How to use a bogus domain to do special searching
This assumes you have a ‘thing’ with an ‘action_date’ and we want a list of this thing from today’s date + a few days, we dont want everything.
<record model=”ir.actions.act_window” id=”open_x_upcomingtasks”>
<field name=”domain”> [('state','=','wacky')] </field>
</record>
Then in the py file:
#otherimports up here…
from datetime import datetime
from datetime import date, timedelta
class x(osv.osv):
_name=”x.x”
def search(self, cr, user, args, offset=0, limit=None, order=None, context=None, count=False, xtra=None):
if (args and len(args)>0 and str(args[0]) == “(‘state’, ‘=’, ‘wacky’)”):
args=[]
newStartPeriod=datetime.today()
newStartPeriod = newStartPeriod.replace(hour=0) #i wanted everything today, not just from this minute
newStartPeriod = newStartPeriod.replace(minute=0) #if you want you can remove these and you
newStartPeriod = newStartPeriod.replace(second=0) #will just get stuff after this second
newEndPeriod=newStartPeriod+timedelta(days=(2)) #add on 2 days…
args = [('action_date', '>=', newStartPeriod.strftime('%Y-%m-%d %H:%M:%S'))]
args += [('action_date', '<=', newEndPeriod.strftime('%Y-%m-%d %H:%M:%S'))]
args +=[('action_type','=','phonecall')] #i have an action type here and i only want phone calls
#you could add state filters or user filters etc
ret = super(x, self).search(cr, user, args, offset, limit, order, context, count)
else:
ret = super(x, self).search(cr, user, args, offset, limit, order, context, count)
return ret
_________________
Developing OpenERP Modules for what seems like an eternity
Smart IT Ltd
http://www.smart-ltd.co.uk