top of page

Dynamic domain in the Odoo ORM Search method

  • Writer: Tek Siong, Hock
    Tek Siong, Hock
  • Nov 27, 2021
  • 1 min read

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"):

 
 
 

Recent Posts

See All

Comments


Subscribe Form

  • facebook
  • linkedin

©2019 by Excelroot Technology Sdn Bhd.

bottom of page