first commit

This commit is contained in:
root
2026-03-14 09:42:12 +00:00
commit 0adbd20c2c
10991 changed files with 1646955 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.

View File

@@ -0,0 +1,228 @@
===================
Production Scenario
===================
Imports::
>>> import datetime as dt
>>> from decimal import Decimal
>>> from proteus import Model
>>> from trytond.modules.company.tests.tools import create_company
>>> from trytond.tests.tools import activate_modules, assertEqual, assertNotEqual
>>> today = dt.date.today()
>>> yesterday = today - dt.timedelta(days=1)
>>> before_yesterday = yesterday - dt.timedelta(days=1)
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')
>>> Product = Model.get('product.product')
>>> template = ProductTemplate()
>>> template.name = 'product'
>>> template.default_uom = unit
>>> template.type = 'goods'
>>> template.producible = True
>>> template.list_price = Decimal(30)
>>> product, = template.products
>>> product.cost_price = Decimal(20)
>>> template.save()
>>> product, = template.products
Create Components::
>>> template1 = ProductTemplate()
>>> template1.name = 'component 1'
>>> template1.default_uom = unit
>>> template1.type = 'goods'
>>> template1.list_price = Decimal(5)
>>> component1, = template1.products
>>> component1.cost_price = Decimal(1)
>>> template1.save()
>>> component1, = template1.products
>>> meter, = ProductUom.find([('name', '=', 'Meter')])
>>> centimeter, = ProductUom.find([('name', '=', 'Centimeter')])
>>> template2 = ProductTemplate()
>>> template2.name = 'component 2'
>>> template2.default_uom = meter
>>> template2.type = 'goods'
>>> template2.list_price = Decimal(7)
>>> component2, = template2.products
>>> component2.cost_price = Decimal(5)
>>> template2.save()
>>> component2, = template2.products
Create Bill of Material::
>>> BOM = Model.get('production.bom')
>>> BOMInput = Model.get('production.bom.input')
>>> BOMOutput = Model.get('production.bom.output')
>>> bom = BOM(name='product')
>>> input1 = BOMInput()
>>> bom.inputs.append(input1)
>>> input1.product = component1
>>> input1.quantity = 5
>>> input2 = BOMInput()
>>> bom.inputs.append(input2)
>>> input2.product = component2
>>> input2.quantity = 150
>>> input2.unit = centimeter
>>> output = BOMOutput()
>>> bom.outputs.append(output)
>>> output.product = product
>>> output.quantity = 1
>>> bom.save()
>>> ProductBom = Model.get('product.product-production.bom')
>>> product.boms.append(ProductBom(bom=bom))
>>> product.save()
>>> ProductionLeadTime = Model.get('production.lead_time')
>>> production_lead_time = ProductionLeadTime()
>>> production_lead_time.product = product
>>> production_lead_time.bom = bom
>>> production_lead_time.lead_time = dt.timedelta(1)
>>> production_lead_time.save()
Create an Inventory::
>>> Inventory = Model.get('stock.inventory')
>>> InventoryLine = Model.get('stock.inventory.line')
>>> Location = Model.get('stock.location')
>>> storage, = Location.find([
... ('code', '=', 'STO'),
... ])
>>> inventory = Inventory()
>>> inventory.location = storage
>>> inventory_line1 = InventoryLine()
>>> inventory.lines.append(inventory_line1)
>>> inventory_line1.product = component1
>>> inventory_line1.quantity = 20
>>> inventory_line2 = InventoryLine()
>>> inventory.lines.append(inventory_line2)
>>> inventory_line2.product = component2
>>> inventory_line2.quantity = 6
>>> inventory.click('confirm')
>>> inventory.state
'done'
Make a production::
>>> Production = Model.get('production')
>>> production = Production()
>>> production.planned_date = today
>>> production.product = product
>>> production.bom = bom
>>> production.quantity = 2
>>> assertEqual(production.planned_start_date, yesterday)
>>> sorted([i.quantity for i in production.inputs])
[10.0, 300.0]
>>> output, = production.outputs
>>> output.quantity
2.0
>>> production.save()
>>> production.cost
Decimal('25.0000')
>>> production.number
>>> production.click('wait')
>>> production.state
'waiting'
>>> assertNotEqual(production.number, None)
Test reset bom button::
>>> for input in production.inputs:
... input.quantity += 1
>>> production.click(
... 'reset_bom',
... change=[
... 'bom', 'product', 'unit', 'quantity',
... 'inputs', 'outputs', 'company', 'warehouse', 'location'])
>>> sorted([i.quantity for i in production.inputs])
[10.0, 300.0]
>>> output, = production.outputs
>>> output.quantity
2.0
Do the production::
>>> production.click('assign_try')
>>> production.state
'assigned'
>>> {i.state for i in production.inputs}
{'assigned'}
>>> production.click('run')
>>> {i.state for i in production.inputs}
{'done'}
>>> for input_ in production.inputs:
... assertEqual(input_.effective_date, today)
>>> production.click('do')
>>> output, = production.outputs
>>> output.state
'done'
>>> assertEqual(output.effective_date, production.effective_date)
>>> output.unit_price
Decimal('12.5000')
>>> with config.set_context(locations=[storage.id]):
... Product(product.id).quantity
2.0
Make a production with effective date yesterday and running the day before::
>>> Production = Model.get('production')
>>> production = Production()
>>> production.effective_date = yesterday
>>> production.effective_start_date = before_yesterday
>>> production.product = product
>>> production.bom = bom
>>> production.quantity = 2
>>> production.click('wait')
>>> production.click('assign_try')
>>> production.click('run')
>>> production.reload()
>>> for input_ in production.inputs:
... assertEqual(input_.effective_date, before_yesterday)
>>> production.click('do')
>>> production.reload()
>>> output, = production.outputs
>>> assertEqual(output.effective_date, yesterday)
Make a production with a bom of zero quantity::
>>> zero_bom, = BOM.duplicate([bom])
>>> for input_ in bom.inputs:
... input_.quantity = 0.0
>>> bom_output, = bom.outputs
>>> bom_output.quantity = 0.0
>>> bom.save()
>>> production = Production()
>>> production.product = product
>>> production.bom = bom
>>> production.planned_start_date = yesterday
>>> production.quantity = 2
>>> [i.quantity for i in production.inputs]
[0.0, 0.0]
>>> output, = production.outputs
>>> output.quantity
0.0
Reschedule productions::
>>> production.click('wait')
>>> Cron = Model.get('ir.cron')
>>> cron = Cron(method='production|reschedule')
>>> cron.interval_number = 1
>>> cron.interval_type = 'months'
>>> cron.click('run_once')
>>> production.reload()
>>> assertEqual(production.planned_start_date, today)

View File

@@ -0,0 +1,94 @@
==========================
Production with By-product
==========================
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 main 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 by-products 1 marketable and 1 waste::
>>> template = ProductTemplate()
>>> template.name = 'product'
>>> template.default_uom = unit
>>> template.type = 'goods'
>>> template.list_price = Decimal(10)
>>> template.save()
>>> marketable, = template.products
>>> template = ProductTemplate()
>>> template.name = 'product'
>>> template.default_uom = unit
>>> template.type = 'goods'
>>> template.list_price = Decimal(0)
>>> template.save()
>>> waste, = template.products
Create component::
>>> template = ProductTemplate()
>>> template.name = 'component'
>>> template.default_uom = unit
>>> template.type = 'goods'
>>> template.save()
>>> component, = template.products
>>> component.cost_price = Decimal(5)
>>> component.save()
Create Bill of Material::
>>> 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 = 1
>>> output = bom.outputs.new()
>>> output.product = marketable
>>> output.quantity = 1
>>> output = bom.outputs.new()
>>> output.product = waste
>>> output.quantity = 2
>>> bom.save()
Make a production::
>>> Production = Model.get('production')
>>> production = Production()
>>> production.product = product
>>> production.bom = bom
>>> production.quantity = 4
>>> production.click('wait')
>>> production.click('assign_force')
>>> production.click('run')
>>> production.click('do')
Check output price::
>>> sorted([o.unit_price for o in production.outputs])
[Decimal('0'), Decimal('5.0000'), Decimal('15.0000')]

View File

@@ -0,0 +1,64 @@
====================================
Stock Lot Number Production 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(['stock_lot', 'production'], create_company)
>>> ProductTemplate = Model.get('product.template')
>>> Production = Model.get('production')
>>> Production = Model.get('production')
>>> Sequence = Model.get('ir.sequence')
>>> SequenceType = Model.get('ir.sequence.type')
>>> UoM = Model.get('product.uom')
Create lot sequence::
>>> sequence_type, = SequenceType.find(
... [('name', '=', "Stock Lot")], limit=1)
>>> sequence = Sequence(name="Lot", sequence_type=sequence_type, company=None)
>>> sequence.save()
Create product::
>>> unit, = UoM.find([('name', '=', 'Unit')])
>>> template = ProductTemplate()
>>> template.name = "Product"
>>> template.default_uom = unit
>>> template.type = 'goods'
>>> template.list_price = Decimal('10.0000')
>>> template.lot_required = ['storage']
>>> template.lot_sequence = sequence
>>> template.save()
>>> product, = template.products
Make a production::
>>> production = Production()
>>> output = production.outputs.new()
>>> output.from_location = production.location
>>> output.to_location = production.warehouse.storage_location
>>> output.product = product
>>> output.quantity = 1
>>> output.unit_price = Decimal(0)
>>> output.currency = production.company.currency
>>> production.click('wait')
>>> production.click('assign_force')
>>> production.click('run')
>>> production.click('do')
>>> production.state
'done'
>>> output, = production.outputs
>>> bool(output.lot)
True

View File

@@ -0,0 +1,97 @@
=============================
Production Lot Trace 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(['stock_lot', 'production'], create_company)
>>> Lot = Model.get('stock.lot')
>>> LotTrace = Model.get('stock.lot.trace')
>>> ProductTemplate = Model.get('product.template')
>>> Production = Model.get('production')
>>> UoM = Model.get('product.uom')
Create product::
>>> unit, = UoM.find([('name', '=', 'Unit')])
>>> template = ProductTemplate(name="Product")
>>> template.type = 'goods'
>>> template.default_uom = unit
>>> template.producible = True
>>> template.list_price = Decimal(1)
>>> template.save()
>>> product, = template.products
Create component::
>>> template = ProductTemplate(name="Component")
>>> template.type = 'goods'
>>> template.default_uom = unit
>>> template.save()
>>> component, = template.products
Create Lots::
>>> product_lot = Lot(product=product, number="1")
>>> product_lot.save()
>>> component_lot = Lot(product=component, number="2")
>>> component_lot.save()
Make a production::
>>> production = Production()
>>> input = production.inputs.new()
>>> input.from_location = production.warehouse.storage_location
>>> input.to_location = production.location
>>> input.product = component
>>> input.lot = component_lot
>>> input.quantity = 1
>>> output = production.outputs.new()
>>> output.from_location = production.location
>>> output.to_location = production.warehouse.storage_location
>>> output.product = product
>>> output.lot = product_lot
>>> output.quantity = 1
>>> output.currency = production.company.currency
>>> output.unit_price = Decimal(0)
>>> production.click('wait')
>>> production.click('assign_force')
>>> production.click('run')
>>> production.click('do')
>>> production.state
'done'
Check lot traces::
>>> trace, = LotTrace.find([('lot', '=', product_lot.id)])
>>> trace.document == production
True
>>> trace.upward_traces
[]
>>> trace, = trace.downward_traces
>>> trace.document == production
True
>>> trace.product == component
True
>>> trace, = LotTrace.find([('lot', '=', component_lot.id)])
>>> trace.document == production
True
>>> trace.downward_traces
[]
>>> trace, = trace.upward_traces
>>> trace.document == production
True
>>> trace.product == product
True

View File

@@ -0,0 +1,75 @@
=============================
Production without list price
=============================
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 main 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.save()
>>> product, = template.products
Create component::
>>> template = ProductTemplate()
>>> template.name = 'component'
>>> template.default_uom = unit
>>> template.type = 'goods'
>>> template.save()
>>> component, = template.products
>>> component.cost_price = Decimal(5)
>>> component.save()
Create Bill of Material::
>>> 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 = 2
>>> bom.save()
Make a production::
>>> Production = Model.get('production')
>>> production = Production()
>>> production.product = product
>>> production.bom = bom
>>> production.quantity = 4
>>> production.click('wait')
>>> production.click('assign_force')
>>> production.click('run')
>>> output, = production.outputs
>>> output.quantity = 2
>>> output.save()
>>> _ = output.duplicate()
>>> production.click('do')
Check output price::
>>> production.cost
Decimal('40.0000')
>>> sorted([o.unit_price for o in production.outputs])
[Decimal('10.0000'), Decimal('10.0000')]

View File

@@ -0,0 +1,149 @@
===============================
Production Phantom BOM Scenario
===============================
Imports::
>>> from decimal import Decimal
>>> from proteus import Model
>>> from trytond.modules.company.tests.tools import create_company, get_company
>>> from trytond.tests.tools import activate_modules
Activate modules::
>>> config = activate_modules('production')
>>> ProductUom = Model.get('product.uom')
>>> ProductTemplate = Model.get('product.template')
>>> BOM = Model.get('production.bom')
>>> BOMInput = Model.get('production.bom.input')
>>> BOMOutput = Model.get('production.bom.output')
>>> ProductBom = Model.get('product.product-production.bom')
>>> Production = Model.get('production')
Create company::
>>> _ = create_company()
>>> company = get_company()
Create product::
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
>>> template_table = ProductTemplate()
>>> template_table.name = 'table'
>>> template_table.default_uom = unit
>>> template_table.type = 'goods'
>>> template_table.producible = True
>>> template_table.list_price = Decimal(30)
>>> table, = template_table.products
>>> table.cost_price = Decimal(20)
>>> template_table.save()
>>> table, = template_table.products
Create Components::
>>> template_top = ProductTemplate()
>>> template_top.name = 'top'
>>> template_top.default_uom = unit
>>> template_top.type = 'goods'
>>> template_top.list_price = Decimal(5)
>>> top, = template_top.products
>>> top.cost_price = Decimal(1)
>>> template_top.save()
>>> top, = template_top.products
>>> template_leg = ProductTemplate()
>>> template_leg.name = 'leg'
>>> template_leg.default_uom = unit
>>> template_leg.type = 'goods'
>>> template_leg.producible = True
>>> template_leg.list_price = Decimal(7)
>>> template_leg.producible = True
>>> leg, = template_leg.products
>>> leg.cost_price = Decimal(5)
>>> template_leg.save()
>>> leg, = template_leg.products
>>> template_foot = ProductTemplate()
>>> template_foot.name = 'foot'
>>> template_foot.default_uom = unit
>>> template_foot.type = 'goods'
>>> template_foot.list_price = Decimal(5)
>>> foot, = template_foot.products
>>> foot.cost_price = Decimal(3)
>>> template_foot.save()
>>> foot, = template_foot.products
>>> template_extension = ProductTemplate()
>>> template_extension.name = 'extension'
>>> template_extension.default_uom = unit
>>> template_extension.type = 'goods'
>>> template_extension.list_price = Decimal(5)
>>> extension, = template_extension.products
>>> extension.cost_price = Decimal(4)
>>> template_extension.save()
>>> extension, = template_extension.products
>>> template_hook = ProductTemplate()
>>> template_hook.name = 'hook'
>>> template_hook.default_uom = unit
>>> template_hook.type = 'goods'
>>> template_hook.list_price = Decimal(7)
>>> hook, = template_hook.products
>>> hook.cost_price = Decimal(9)
>>> template_hook.save()
>>> hook, = template_hook.products
Create Phantom Bill of Material with input products::
>>> phantom_bom_input = BOM(name='Leg Foot Input')
>>> phantom_bom_input.phantom = True
>>> phantom_bom_input.phantom_quantity = 1
>>> phantom_bom_input.phantom_unit = unit
>>> phantom_input1 = phantom_bom_input.inputs.new()
>>> phantom_input1.product = leg
>>> phantom_input1.quantity = 1
>>> phantom_input2 = phantom_bom_input.inputs.new()
>>> phantom_input2.product = foot
>>> phantom_input2.quantity = 1
>>> phantom_bom_input.save()
Create Phantom Bill of Material with output products::
>>> phantom_bom_output = BOM(name='Extension Hook Ouput')
>>> phantom_bom_output.phantom = True
>>> phantom_bom_output.phantom_quantity = 1
>>> phantom_bom_output.phantom_unit = unit
>>> phantom_output1 = phantom_bom_output.outputs.new()
>>> phantom_output1.product = extension
>>> phantom_output1.quantity = 1
>>> phantom_output2 = phantom_bom_output.outputs.new()
>>> phantom_output2.product = hook
>>> phantom_output2.quantity = 2
>>> phantom_bom_output.save()
>>> phantom_bom_output.outputs[0].product.name
'extension'
>>> phantom_bom_output.outputs[1].product.name
'hook'
Create Bill of Material using Phantom BoM::
>>> bom = BOM(name='product with Phantom BoM')
>>> input1 = bom.inputs.new()
>>> input1.product = top
>>> input1.quantity = 1
>>> input2 = bom.inputs.new()
>>> input2.phantom_bom = phantom_bom_input
>>> input2.quantity = 4
>>> output = bom.outputs.new()
>>> output.product = table
>>> output.quantity = 1
>>> output2 = bom.outputs.new()
>>> output2.phantom_bom = phantom_bom_output
>>> output2.quantity = 2
>>> bom.save()
>>> table.boms.append(ProductBom(bom=bom))
>>> table.save()

View File

@@ -0,0 +1,91 @@
============================
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

View File

@@ -0,0 +1,106 @@
===================
Production Set Cost
===================
Imports::
>>> from decimal import Decimal
>>> from proteus import Model
>>> from trytond.modules.company.tests.tools import create_company, get_company
>>> from trytond.modules.currency.tests.tools import get_currency
>>> from trytond.tests.tools import activate_modules
Activate modules::
>>> config = activate_modules('production', create_company)
Create main 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(20)
>>> template.save()
>>> product, = template.products
Create component::
>>> template = ProductTemplate()
>>> template.name = 'component'
>>> template.default_uom = unit
>>> template.type = 'goods'
>>> template.save()
>>> component, = template.products
>>> component.cost_price = Decimal(5)
>>> component.save()
Create Bill of Material::
>>> BOM = Model.get('production.bom')
>>> bom = BOM(name='product')
>>> input = bom.inputs.new()
>>> input.product = component
>>> input.quantity = 3
>>> output = bom.outputs.new()
>>> output.product = product
>>> output.quantity = 1
>>> bom.save()
Make a production with 2 unused component::
>>> Production = Model.get('production')
>>> production = Production()
>>> production.product = product
>>> production.bom = bom
>>> production.quantity = 2
>>> production.click('wait')
>>> production.click('assign_force')
>>> production.click('run')
>>> output = production.outputs.new()
>>> output.product = component
>>> output.quantity = 2
>>> output.unit_price = Decimal(0)
>>> output.currency = get_currency()
>>> output.from_location = production.location
>>> output.to_location = production.warehouse.storage_location
>>> production.click('do')
Check output price::
>>> production.cost
Decimal('30.0000')
>>> sorted([o.unit_price for o in production.outputs])
[Decimal('5.0000'), Decimal('10.0000')]
Change cost of input::
>>> Move = Model.get('stock.move')
>>> input, = production.inputs
>>> Move.write([input], {'cost_price': Decimal(6)}, config.context)
>>> input.reload()
>>> bool(input.production_cost_price_updated)
True
Launch cron task::
>>> Cron = Model.get('ir.cron')
>>> cron_set_cost, = Cron.find([
... ('method', '=', 'production|set_cost_from_moves'),
... ])
>>> cron_set_cost.companies.append(get_company())
>>> cron_set_cost.click('run_once')
>>> production.reload()
>>> sorted([o.unit_price for o in production.outputs])
[Decimal('6.0000'), Decimal('12.0000')]
>>> input, = production.inputs
>>> bool(input.production_cost_price_updated)
False

View File

@@ -0,0 +1,88 @@
=========================
Production Waste 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 main 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(20)
>>> template.save()
>>> product, = template.products
Create Component::
>>> template = ProductTemplate()
>>> template.name = 'component 1'
>>> template.default_uom = unit
>>> template.type = 'goods'
>>> template.list_price = Decimal(50)
>>> component, = template.products
>>> component.cost_price = Decimal(1)
>>> template.save()
>>> component, = template.products
Configure locations::
>>> Location = Model.get('stock.location')
>>> lost_found_loc, = Location.find([('type', '=', 'lost_found')])
>>> warehouse_loc, = Location.find([('type', '=', 'warehouse')])
>>> warehouse_loc.waste_locations.append(lost_found_loc)
>>> warehouse_loc.save()
Run the production::
>>> Production = Model.get('production')
>>> production = Production()
>>> input = production.inputs.new()
>>> input.quantity = 20.0
>>> input.product = component
>>> input.from_location = warehouse_loc.storage_location
>>> input.to_location = production.location
>>> production.click('wait')
>>> production.click('assign_force')
>>> production.click('run')
Create outputs including waste products::
>>> output = production.outputs.new()
>>> output.quantity = 1.0
>>> output.product = product
>>> output.from_location = production.location
>>> output.to_location = warehouse_loc.storage_location
>>> output.unit_price = Decimal('0')
>>> output.currency = production.company.currency
>>> waste_output = production.outputs.new()
>>> waste_output.quantity = 1.0
>>> waste_output.product = product
>>> waste_output.from_location = production.location
>>> waste_output.to_location = lost_found_loc
>>> production.click('do')
>>> production.cost
Decimal('20.0000')
>>> output, = [o for o in production.outputs
... if o.to_location.type != 'lost_found']
>>> output.unit_price
Decimal('20.0000')
>>> waste_output, = [o for o in production.outputs
... if o.to_location.type == 'lost_found']
>>> waste_output.unit_price

View File

@@ -0,0 +1,44 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
import datetime
from trytond.modules.company.tests import CompanyTestMixin
from trytond.pool import Pool
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
class ProductionTestCase(CompanyTestMixin, ModuleTestCase):
'Test Production module'
module = 'production'
@with_transaction()
def test_on_change_planned_start_date(self):
"Test on_change_planned_start_date"
pool = Pool()
Production = pool.get('production')
Product = pool.get('product.product')
LeadTime = pool.get('production.lead_time')
date = datetime.date(2016, 11, 26)
product = Product(producible=True)
product.production_lead_times = []
production = Production()
production.planned_date = date
production.product = product
production.state = 'draft'
production.on_change_planned_date()
self.assertEqual(production.planned_start_date, date)
lead_time = LeadTime(bom=None, lead_time=None)
product.production_lead_times = [lead_time]
production.on_change_planned_date()
self.assertEqual(production.planned_start_date, date)
lead_time.lead_time = datetime.timedelta(1)
production.on_change_planned_date()
self.assertEqual(
production.planned_start_date, datetime.date(2016, 11, 25))
del ModuleTestCase

View File

@@ -0,0 +1,8 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.tests.test_tryton import load_doc_tests
def load_tests(*args, **kwargs):
return load_doc_tests(__name__, __file__, *args, **kwargs)