If applied, this commit will solve the issue of missing product issue while installing the following modules: loyalty_delivery, pos_loyalty, sale_loyalty, website_sale_loyalty Steps to produce: - Install loyalty module. - Go to 'Products' or 'Product Variants'. - Delete the product 'Gift Card'. - Now install the 'sale_loyalty' module. This commit will raise an userError while deleting the loyalty products. sentry - 4112536971 closes odoo/odoo#121484 X-original-commit: 3488d292b514bbf4190f19bd8271b3e68b3eb055 Signed-off-by: Parth Solanki (paso) <paso@odoo.com>
23 lines
788 B
Python
23 lines
788 B
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import _, api, models
|
|
from odoo.exceptions import UserError
|
|
|
|
|
|
class ProductTemplate(models.Model):
|
|
_inherit = 'product.template'
|
|
|
|
@api.ondelete(at_uninstall=False)
|
|
def _unlink_except_loyalty_products(self):
|
|
product_data = [
|
|
self.env.ref('loyalty.gift_card_product_50', False),
|
|
self.env.ref('loyalty.ewallet_product_50', False),
|
|
]
|
|
for product in self.filtered(lambda p: p.product_variant_id in product_data):
|
|
raise UserError(_(
|
|
"You cannot delete %(name)s as it is used in 'Coupons & Loyalty'."
|
|
" Please archive it instead.",
|
|
name=product.name
|
|
))
|