[FIX] loyalty: fix missing loyalty product update issue
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>
This commit is contained in:
@@ -1770,6 +1770,16 @@ msgstr ""
|
||||
msgid "You can not delete a program in an active state"
|
||||
msgstr ""
|
||||
|
||||
#. module: loyalty
|
||||
#. odoo-python
|
||||
#: code:addons/loyalty/models/product_product.py:0
|
||||
#: code:addons/loyalty/models/product_template.py:0
|
||||
#, python-format
|
||||
msgid ""
|
||||
"You cannot delete %(name)s as it is used in 'Coupons & Loyalty'. Please "
|
||||
"archive it instead."
|
||||
msgstr ""
|
||||
|
||||
#. module: loyalty
|
||||
#: model:mail.template,subject:loyalty.mail_template_gift_card
|
||||
msgid "Your Gift Card at {{ object.company_id.name }}"
|
||||
|
||||
@@ -7,4 +7,5 @@ from . import loyalty_reward
|
||||
from . import loyalty_rule
|
||||
from . import loyalty_program
|
||||
from . import product_product
|
||||
from . import product_template
|
||||
from . import res_partner
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import _, models
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo import _, api, models
|
||||
from odoo.exceptions import UserError, ValidationError
|
||||
|
||||
|
||||
class ProductProduct(models.Model):
|
||||
_inherit = 'product.product'
|
||||
@@ -14,3 +15,16 @@ class ProductProduct(models.Model):
|
||||
if rewards:
|
||||
raise ValidationError(_("This product may not be archived. It is being used for an active promotion program."))
|
||||
return super().write(vals)
|
||||
|
||||
@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 in product_data):
|
||||
raise UserError(_(
|
||||
"You cannot delete %(name)s as it is used in 'Coupons & Loyalty'."
|
||||
" Please archive it instead.",
|
||||
name=product.name
|
||||
))
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
# -*- 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
|
||||
))
|
||||
Reference in New Issue
Block a user