Community mailing list archives

Re: easy way to filter weekdays

by André P. <> - 05/29/2015 10:24:45
I don't think you can do it with just a domain, but you can add a function field to allow you to search/filter those invoices.

Example (not tested):
def _weekend_invoice(self):
    weekday = fields.Datetime.from_string(self.create_date).weekday()
    self.weekend_invoice = weekday in (5, 6)

def _search_weekend_invoice(self, operator, value):
    if operator not in ('=', '!='):
        return []
    if operator == '!=':
        value = not value
    query = 'SELECT id FROM account_invoice WHERE EXTRACT(DOW FROM create_date) %s IN (5, 6)'
    query = query % ('' if value else 'NOT')
    ids = [t[0] for t in]
    return [('id', 'in', ids)]

weekend_invoice = fields.Boolean(compute='_weekend_invoice', search='_search_weekend_invoice')

Then you can use the weekend_invoice field, as in [('weekend_invoice', '=', True)].

Em sex, 29 de mai de 2015 às 00:50, Mohamed M. Hagag <> escreveu:


I want to create a domain filter that lists all invoices created on Saturdays or Sundays .

what function can I use in the filter ?


Post to: