How to search for a record in the database?

  • type
      technical
  • info created for version
      14.0
  • mvc
      Python (models/controllers)
Add to Cart

Suppose self is a project.task record and you want to fetch it's project ...

project_id = self.env['project.project'].browse(self.project_id.id)

If you don't know the id of a record to search for, you use the search method with a domain. For example ...

won_stage_ids = self.env['crm.stage'].search([('is_won', '=', True)])