Files
tradon/modules/production/tests/scenario_production_rounding.rst
2026-03-14 09:42:12 +00:00

92 lines
2.3 KiB
ReStructuredText

============================
Production Rounding Scenario
============================
Imports::
>>> from decimal import Decimal
>>> from proteus import Model
>>> from trytond.modules.company.tests.tools import create_company
>>> from trytond.tests.tools import activate_modules
Activate modules::
>>> config = activate_modules('production', create_company)
Create product::
>>> 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.type = 'goods'
>>> template.producible = True
>>> template.list_price = Decimal(30)
>>> template.save()
>>> product, = template.products
Create component::
>>> template = ProductTemplate()
>>> template.name = 'component'
>>> template.default_uom = unit
>>> template.type = 'goods'
>>> template.list_price = Decimal(5)
>>> template.save()
>>> component, = template.products
Create residual::
>>> template = ProductTemplate()
>>> template.name = 'residual'
>>> template.default_uom = unit
>>> template.type = 'goods'
>>> template.list_price = Decimal(0)
>>> template.save()
>>> residual, = template.products
Create Bill of Material with rational ratio::
>>> BOM = Model.get('production.bom')
>>> bom = BOM(name='product')
>>> input = bom.inputs.new()
>>> input.product = component
>>> input.quantity = 4
>>> output = bom.outputs.new()
>>> output.product = product
>>> output.quantity = 9
>>> output = bom.outputs.new()
>>> output.product = residual
>>> output.quantity = 8
>>> bom.save()
Make a production with rounding::
>>> Production = Model.get('production')
>>> production = Production()
>>> production.product = product
>>> production.bom = bom
>>> production.quantity = 3
Check component is ceiled::
>>> input, = production.inputs
>>> input.quantity
2.0
Check product quantity::
>>> output, = [o for o in production.outputs if o.product == product]
>>> output.quantity
3.0
Check residual is floored::
>>> output, = [o for o in production.outputs if o.product == residual]
>>> output.quantity
2.0