I have a button called job_count which links jobs to equipment. It is only showing active records of job, But, I want to show the count of all the active as well as an archived record of jobs associated with equipment. Please help.
def _get_job_count(self):
for record in self:
j_count = self.env['job_module'].sudo().search_count([('equipment_id', 'in', self.ids)]])
record.job_count= j_count
active
toggles the global visibility of the record, if active is set to False
the record is invisible in most searches and listing.
You can manually tell the search method to find also archived records by adding the following criteria to the search domain:
'|', ('active','=',True), ('active','=',False)
Example:
search_count([('equipment_id', 'in', self.ids), '|', ('active','=',True), ('active','=',False)])
Odoo provide a shortcut to set the active
flag, you just need to specify active_test
in the context.
whether the default filtering of records with
active
field set toFalse
should be applied.
In old API, the active_test
is passed through the context
parameter:
.search_count(cr, uid, domain, context=dict(context, active_test=False))
In new API, you can use with_context
method to update the search context:
self.with_context(active_test=False).search_count(domain)