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
(grafted from 79e4677f878eaedbaa882af75f450cfc9958624b)

--HG--
branch : 7.0
This commit is contained in:
Cédric Krier committed 2023-12-05 10:28:35 +01:00
1 parent d30092792a
commit fb11301663
2 files changed
+30

No files matched your search

+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'