Community mailing list archives

community@mail.odoo.com

Re: easy way to filter weekdays

by André P. <app@thinkopen.solutions> - 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):

@api.one
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')
    self.env.cr.execute(query)
    ids = [t[0] for t in self.env.cr.fetchall()]
    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 <mohamedhagag1981@gmail.com> escreveu:

Dears,


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


what function can I use in the filter ?


Regards,

_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-59
Post to: mailto:community@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe