I'm writing a module to expand on the sales report. I need to add filters for specific time periods relative to the current date. I can use either python or postgres to calculate the needed date range, but I'm having a problem using those dates in the xml for the view. Primarily I'm trying to use a field or a python function as the value for a domain in the search filter. Is this possible?
When trying to use a field, I generally get an evaluation error like:
NameError: name 'end_last_week' is not defined
This happens both when the field is defined by a compute function and when it's defined by the database query and I can confirm that the field is populated in the model table. The relevant search filter element I'm trying to use looks like this:
<filter name="Last Week" string="Last Week" domain="[('state','not in',('draft', 'cancel', 'sent')), ('date','<=',end_last_week),('date', '>=',start_last_week)]"/>
How can I use a computed variable as the value for a domain? Any insight is appreciated.
EDIT:
For reference, here is an example definition for a field I want to use as a domain value:
def _compute_end_last(self):
last_week_end = str((datetime.now().date()) - timedelta(days=(datetime.now().date()).weekday() + 3))
return last_week_end
end_last_week = fields.Char('End Last', compute='_compute_end_last', store=True)