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:
@@ -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>
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user