Add scenario to test kit duplication

issue11854
review418561003
This commit is contained in:
Sergi Almacellas Abellana
2022-11-03 09:18:11 +01:00
parent 24d5b999d2
commit 85b97a94a8
+86
View File
@@ -0,0 +1,86 @@
==============================
Product Kit Duplicate Scenario
==============================
Imports::
>>> from decimal import Decimal
>>> from proteus import Model, Wizard
>>> from trytond.tests.tools import activate_modules
>>> from trytond.modules.company.tests.tools import (
... create_company, get_company)
Activate product_kit::
>>> config = activate_modules('product_kit')
>>> Uom = Model.get('product.uom')
>>> ProductTemplate = Model.get('product.template')
>>> Product = Model.get('product.product')
Create company::
>>> _ = create_company()
>>> company = get_company()
Create products::
>>> unit, = Uom.find([('name', '=', 'Unit')])
>>> template = ProductTemplate()
>>> template.name = "Product 1"
>>> template.default_uom = unit
>>> template.type = 'goods'
>>> template.save()
>>> product1, = template.products
>>> product1.cost_price = Decimal('10.0000')
>>> product1.save()
>>> template = ProductTemplate()
>>> template.name = "Product 2"
>>> template.default_uom = unit
>>> template.type = 'goods'
>>> template.save()
>>> product2, = template.products
>>> product2.cost_price = Decimal('20.0000')
>>> product2.save()
Create composed product::
>>> template = ProductTemplate()
>>> template.name = "Composed Product"
>>> template.default_uom = unit
>>> template.type = 'goods'
>>> template.save()
>>> composed_product, = template.products
>>> composed_product.cost_price = Decimal('10.0000')
>>> component = composed_product.components.new()
>>> component.product = product1
>>> component.quantity = 2
>>> composed_product.save()
Create a kit::
>>> template = ProductTemplate()
>>> template.name = "Kit"
>>> template.default_uom = unit
>>> template.type = 'kit'
>>> template.save()
>>> kit, = template.products
>>> component = template.components.new()
>>> component.product = product1
>>> component.quantity = 1
>>> component = template.components.new()
>>> component.product = product2
>>> component.quantity = 2
>>> template.save()
Test duplicate copies components::
>>> duplicated, = template.duplicate()
>>> len(duplicated.components)
2
>>> duplicated_product, = composed_product.duplicate()
>>> len(duplicated_product.components)
1