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>
17 lines
726 B
Python
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)
|