This question has been flagged
1 Reply
2154 Views

Hello, 


With Odoo Studio I added a smart button where it counts the number of times the record appears with the calendar.

Odoo Studio automatically does this:


results = self.env['calendar.event'].read_group([('x_studio_physician', 'in', self.ids)], 'x_studio_physician', 'x_studio_physician')dic = {}for x in results: dic[x['x_studio_physician'][0]] = x['x_studio_physician_count']for record in self: record['x_x_studio_physician__calendar_event_count'] = dic.get(record.id, 0)


I add a pipeline status bar to calendar so I would like to count only one specific state or to count all that are different from a specific one.



Thanks in advance for your help.

Avatar
Discard
Author Best Answer

If for someone the answer that I got reading in books is useful, here it goes:

The first part of read_group is the domain, so you just need to include the additional conditions you wanted.

results = self.env ['calendar.event']. read_group (['&',('x_studio_physician', 'in', self.ids),('x_studio_status','=','specific status')], 'x_studio_physician', 'x_studio_physician') dic = {} for x in results: dic [ x ['x_studio_physician'] [0]] = x ['x_studio_physician_count'] for record in self: record ['x_x_studio_physician__calendar_event_count'] = dic.get (record.id, 0)
Avatar
Discard