changeset 56d0e5a4d621 in modules/production:default
details:
https://hg.tryton.org/modules/production?cmd=changeset;node=56d0e5a4d621
description:
Allow lost_found as output of production
issue6335
review323431002
diffstat:
CHANGELOG | 1 +
production.py | 7 ++-
tests/scenario_production_waste.rst | 92 +++++++++++++++++++++++++++++++++++++
tests/test_production.py | 4 +
4 files changed, 103 insertions(+), 1 deletions(-)
diffs (140 lines):
diff -r 36999d34ea12 -r 56d0e5a4d621 CHANGELOG
--- a/CHANGELOG Sun Oct 11 16:12:36 2020 +0200
+++ b/CHANGELOG Sun Oct 11 23:46:52 2020 +0200
@@ -1,3 +1,4 @@
+* Allow lost_found as output of production
* Keep cost of unused input products
* Use the shipment assign wizard for production
* Rename production state from cancel to cancelled
diff -r 36999d34ea12 -r 56d0e5a4d621 production.py
--- a/production.py Sun Oct 11 16:12:36 2020 +0200
+++ b/production.py Sun Oct 11 23:46:52 2020 +0200
@@ -131,7 +131,10 @@
domain=[
('shipment', '=', None),
('from_location', '=', Eval('location')),
- ('to_location', 'child_of', [Eval('warehouse')], 'parent'),
+ ['OR',
+ ('to_location', 'child_of', [Eval('warehouse')], 'parent'),
+ ('to_location.waste_warehouses', '=', Eval('warehouse')),
+ ],
('company', '=', Eval('company', -1)),
],
states={
@@ -545,6 +548,8 @@
Decimal(str(input_.internal_quantity)) * cost_price)
outputs = []
for output in production.outputs:
+ if output.to_location.type == 'lost_found':
+ continue
product = output.product
if input_quantities.get(output.product):
cost_price = (
diff -r 36999d34ea12 -r 56d0e5a4d621 tests/scenario_production_waste.rst
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/scenario_production_waste.rst Sun Oct 11 23:46:52 2020 +0200
@@ -0,0 +1,92 @@
+=========================
+Production Waste 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 modules::
+
+ >>> config = activate_modules('production')
+
+Create company::
+
+ >>> _ = create_company()
+ >>> company = get_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')
+ >>> 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('done')
+ >>> 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
diff -r 36999d34ea12 -r 56d0e5a4d621 tests/test_production.py
--- a/tests/test_production.py Sun Oct 11 16:12:36 2020 +0200
+++ b/tests/test_production.py Sun Oct 11 23:46:52 2020 +0200
@@ -67,4 +67,8 @@
tearDown=doctest_teardown, encoding='utf-8',
checker=doctest_checker,
optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
+ suite.addTests(doctest.DocFileSuite('scenario_production_waste.rst',
+ tearDown=doctest_teardown, encoding='utf-8',
+ checker=doctest_checker,
+ optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
return suite