Files
tryton/modules/product/tests/scenario_product_variant.rst
T
Cédric Krier fb11301663 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
2023-12-05 10:28:35 +01:00

86 lines
2.1 KiB
ReStructuredText

========================
Product Variant Scenario
========================
Imports::
>>> from decimal import Decimal
>>> from proteus import Model
>>> from trytond.tests.tools import activate_modules
>>> from trytond.modules.company.tests.tools import create_company
Activate modules::
>>> config = activate_modules('product')
Create company::
>>> _ = create_company()
Create a template::
>>> ProductUom = Model.get('product.uom')
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
>>> ProductTemplate = Model.get('product.template')
>>> template = ProductTemplate()
>>> template.name = "Product"
>>> template.default_uom = unit
>>> template.list_price = Decimal('42.0000')
>>> template.code = "PROD"
>>> template.save()
>>> len(template.products)
1
>>> product, = template.products
>>> product.code
'PROD'
>>> product.suffix_code = "001"
>>> product.save()
>>> product.code
'PROD001'
Create a variant::
>>> Product = Model.get('product.product')
>>> product = Product()
>>> product.template = template
>>> product.name
'Product'
>>> product.list_price
Decimal('42.0000')
>>> product.suffix_code = "002"
>>> product.save()
>>> product.list_price
Decimal('42.0000')
>>> product.code
'PROD002'
Change template code::
>>> template.code = "PRD"
>>> 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'