[FIX] loyalty : don't raise if user have not access to all reward

Before this commit it is possible to archive a product if the current user have no access to all reward (multi company rules).

closes odoo/odoo#106574

X-original-commit: 5bafee8d0479367fd25b2fa2daefd4374ab38211
Signed-off-by: William Braeckman (wbr) <wbr@odoo.com>
This commit is contained in:
Florent de Labarre
2022-11-25 18:55:49 +01:00
parent e888424db4
commit ebc118ee19
+1 -1
View File
@@ -10,7 +10,7 @@ class ProductProduct(models.Model):
def write(self, vals):
if not vals.get('active', True) and any(product.active for product in self):
# Prevent archiving products used for giving rewards
rewards = self.env['loyalty.reward'].search([('discount_line_product_id', 'in', self.ids)])
rewards = self.env['loyalty.reward'].sudo().search([('discount_line_product_id', 'in', self.ids)], limit=1)
if rewards:
raise ValidationError(_("This product may not be archived. It is being used for an active promotion program."))
return super().write(vals)