How to search for a record in the database?
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)])