Do not allow to change template of existing product

Many models rely on the couple product-template to be immutable.

Closes #14279
This commit is contained in:
Cédric Krier
2025-10-07 17:42:27 +02:00
parent c059af6bed
commit 354139725c
4 changed files with 15 additions and 16 deletions
+3
View File
@@ -33,5 +33,8 @@ this repository contains the full copyright notices and license terms. -->
<record model="ir.message" id="msg_category_code_unique">
<field name="text">The code on product category must be unique.</field>
</record>
<record model="ir.message" id="msg_product_change_template">
<field name="text">You cannot change the template of the product "%(product)s".</field>
</record>
</data>
</tryton>
+12
View File
@@ -16,6 +16,7 @@ from trytond.i18n import gettext
from trytond.model import (
DeactivableMixin, Exclude, Index, Model, ModelSQL, ModelView, UnionMixin,
fields, sequence_ordered, tree)
from trytond.model.exceptions import AccessError
from trytond.modules.company.model import (
CompanyMultiValueMixin, CompanyValueMixin)
from trytond.pool import Pool
@@ -717,6 +718,17 @@ class Product(
if mode in {'create', 'write'}:
cls.sync_code(products)
@classmethod
def check_modification(cls, mode, products, values=None, external=False):
super().check_modification(
mode, products, values=values, external=external)
if mode == 'write' and 'template' in values:
for product in products:
if product.template.id != values.get('template'):
raise AccessError(gettext(
'product.msg_product_change_template',
product=product.rec_name))
@classmethod
def copy(cls, products, default=None):
if default is None:
-3
View File
@@ -36,9 +36,6 @@ this repository contains the full copyright notices and license terms. -->
<record model="ir.message" id="msg_product_shopify_uom_digits">
<field name="text">To update product "%(product)s" on Shopify, you must use an unit of measure without digits.</field>
</record>
<record model="ir.message" id="msg_product_change_template">
<field name="text">To change the template of product "%(product)s" you must unpublish it from the Shopify web shops.</field>
</record>
<record model="ir.message" id="msg_custom_collection_fail">
<field name="text">Failed to save custom collection "%(category)s" with error:
%(error)s</field>
-13
View File
@@ -11,7 +11,6 @@ from sql.operators import Equal
from trytond.i18n import gettext
from trytond.model import Exclude, ModelSQL, ModelView, fields
from trytond.model.exceptions import AccessError
from trytond.modules.product.exceptions import TemplateValidationError
from trytond.pool import Pool, PoolMeta
from trytond.pyson import Bool, Eval, If
@@ -310,18 +309,6 @@ class Product(IdentifiersMixin, metaclass=PoolMeta):
self.default_uom, quantity, self.shopify_uom, round=True,
factor=self.shopify_uom_factor, rate=self.shopify_uom_rate)
@classmethod
def check_modification(cls, mode, products, values=None, external=False):
super().check_modification(
mode, products, values=values, external=external)
if mode == 'write' and 'template' in values:
for product in products:
if (product.template.id != values.get('template')
and product.shopify_identifiers):
raise AccessError(gettext(
'web_shop_shopify.msg_product_change_template',
product=product.rec_name))
class ProductURL(metaclass=PoolMeta):
__name__ = 'product.web_shop_url'