[FIX] loyalty: unable to open partner view

Step to Reproduce at Runbot:
-> Install Coupons & Loyalty and Contacts Apps
-> Open Contacts form view
-> AccessError telling you that you cannot read loyalty program & cards

See this video url:
https://watch.screencastify.com/v/ygI1wjVyP5xo5tWTzeST

closes odoo/odoo#130092

Part-of: #107375
X-original-commit: 4c31ef775579b6c7163c91fa2069fcc64819f940
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
This commit is contained in:
higo-odoo
2023-07-28 21:54:53 +02:00
committed by Victor Feyens
parent c1445d5cbf
commit 76eb8fe870
+4 -1
View File
@@ -7,11 +7,14 @@ class ResPartner(models.Model):
loyalty_card_count = fields.Integer(
string="Active loyalty cards",
compute='_compute_count_active_cards')
compute='_compute_count_active_cards',
compute_sudo=True,
groups='base.group_user')
def _compute_count_active_cards(self):
loyalty_groups = self.env['loyalty.card']._read_group(
domain=[
'|', ('company_id', '=', False), ('company_id', 'in', self.env.companies.ids),
('partner_id', 'in', self.with_context(active_test=False)._search([('id', 'child_of', self.ids)])),
('points', '>', '0'),
('program_id.active', '=', 'True'),