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':
    domain.append(('type','=','out_invoice'))

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

119 views0 comments

Recent Posts

See All

Odoo Element Cannot be Located in Parent View

Sometimes, after you've added a new field to the existing view, by inheriting the view, you may encountered the following error, when upgrading the module. Element 'XXXXX' cannot be located in parent

Comments


bottom of page