Strip generated code of product

The template code or product suffix code allow to have trailing and leading
spaces but not the code of the product. So we must compare the code with a
stripped version of the generated code to avoid infinite loop.

Closes #12801
This commit is contained in:
Cédric Krier
2023-12-05 10:28:35 +01:00
parent f5076fb5e7
commit e030cd2470
2 changed files with 30 additions and 0 deletions
+7
View File
@@ -649,6 +649,13 @@ class Product(
for product in products:
code = ''.join(filter(None, [
product.prefix_code, product.suffix_code]))
if cls.code.strip:
if cls.code.strip == 'leading':
code = code.lstrip()
elif cls.code.strip == 'trailing':
code = code.rstrip()
else:
code = code.strip()
if not code:
code = None
if code != product.code:
@@ -60,3 +60,26 @@ Change template code::
>>> template.save()
>>> sorted([p.code for p in template.products])
['PRD001', 'PRD002']
Create template with trailing space in code::
>>> template = ProductTemplate()
>>> template.name = "Product"
>>> template.code = "TRAILING "
>>> template.default_uom = unit
>>> template.save()
>>> product, = template.products
>>> product.code
'TRAILING'
Create product with leading space in code::
>>> template = ProductTemplate()
>>> template.name = "Product"
>>> template.default_uom = unit
>>> product, = template.products
>>> product.suffix_code = " LEADING"
>>> template.save()
>>> product, = template.products
>>> product.code
'LEADING'