Files
odoo_source/addons/loyalty/models/product_product.py
T
Florent de Labarre ebc118ee19 [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>
2022-11-25 18:55:49 +01:00

17 lines
726 B
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import _, models
from odoo.exceptions import ValidationError
class ProductProduct(models.Model):
_inherit = 'product.product'
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'].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)