From 354139725c1aa12f4b0db9d28e564dab3f82ec2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Tue, 7 Oct 2025 17:42:27 +0200 Subject: [PATCH] Do not allow to change template of existing product Many models rely on the couple product-template to be immutable. Closes #14279 --- modules/product/message.xml | 3 +++ modules/product/product.py | 12 ++++++++++++ modules/web_shop_shopify/message.xml | 3 --- modules/web_shop_shopify/product.py | 13 ------------- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/modules/product/message.xml b/modules/product/message.xml index 06c383774d..8ebae7225d 100644 --- a/modules/product/message.xml +++ b/modules/product/message.xml @@ -33,5 +33,8 @@ this repository contains the full copyright notices and license terms. --> The code on product category must be unique. + + You cannot change the template of the product "%(product)s". + diff --git a/modules/product/product.py b/modules/product/product.py index f76b2b3d76..c1e89e89ee 100644 --- a/modules/product/product.py +++ b/modules/product/product.py @@ -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: diff --git a/modules/web_shop_shopify/message.xml b/modules/web_shop_shopify/message.xml index c07f399053..43003a2779 100644 --- a/modules/web_shop_shopify/message.xml +++ b/modules/web_shop_shopify/message.xml @@ -36,9 +36,6 @@ this repository contains the full copyright notices and license terms. --> To update product "%(product)s" on Shopify, you must use an unit of measure without digits. - - To change the template of product "%(product)s" you must unpublish it from the Shopify web shops. - Failed to save custom collection "%(category)s" with error: %(error)s diff --git a/modules/web_shop_shopify/product.py b/modules/web_shop_shopify/product.py index 1653df4a4a..b500e64532 100644 --- a/modules/web_shop_shopify/product.py +++ b/modules/web_shop_shopify/product.py @@ -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'