details:   https://code.tryton.org/tryton/commit/f98f28e91b99
branch:    default
user:      Cédric Krier <[email protected]>
date:      Tue Oct 07 17:42:27 2025 +0200
description:
        Do not allow to change template of existing product

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

        Closes #14279
diffstat:

 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(-)

diffs (84 lines):

diff -r 70d57766ec0d -r f98f28e91b99 modules/product/message.xml
--- a/modules/product/message.xml       Thu Oct 02 15:26:34 2025 +0200
+++ b/modules/product/message.xml       Tue Oct 07 17:42:27 2025 +0200
@@ -33,5 +33,8 @@
         <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>
diff -r 70d57766ec0d -r f98f28e91b99 modules/product/product.py
--- a/modules/product/product.py        Thu Oct 02 15:26:34 2025 +0200
+++ b/modules/product/product.py        Tue Oct 07 17:42:27 2025 +0200
@@ -16,6 +16,7 @@
 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
@@ -718,6 +719,17 @@
             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:
             default = {}
diff -r 70d57766ec0d -r f98f28e91b99 modules/web_shop_shopify/message.xml
--- a/modules/web_shop_shopify/message.xml      Thu Oct 02 15:26:34 2025 +0200
+++ b/modules/web_shop_shopify/message.xml      Tue Oct 07 17:42:27 2025 +0200
@@ -36,9 +36,6 @@
         <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>
diff -r 70d57766ec0d -r f98f28e91b99 modules/web_shop_shopify/product.py
--- a/modules/web_shop_shopify/product.py       Thu Oct 02 15:26:34 2025 +0200
+++ b/modules/web_shop_shopify/product.py       Tue Oct 07 17:42:27 2025 +0200
@@ -11,7 +11,6 @@
 
 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 @@
             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'

Reply via email to