top of page
  • Writer's pictureTek Siong, Hock

Dynamic domain in the Odoo ORM Search method

This Odoo technical development blog is my way to contribute back to the Odoo Community, for all the selfless and great sharing by the community members.

If you have a wizard that allow the user to enter parameters, you may want to use this dynamic domain to do the ORM search, instead of having too many if-else statement.

Example of the following of how to add the search domain parameters, dynamically.

if self.balance:
    domain = [('date_invoice', '>=', self.date_from),
              ('date_invoice', '<=', self.date_to),
              ('state', 'in', ['open'])]
if self.filter_debit == 'invoice':
    domain.append(('type', '=', 'out_invoice'))
if self.filter_debit == 'credit':

invoices = self.env['account.invoice'].search(domain, order="date_invoice         asc"):

106 views0 comments

Recent Posts

See All
bottom of page