Commit e19f3a81 authored by Sebastien Robin's avatar Sebastien Robin

mrp: make item propagation working on transformation simulation rule

The item of produced resources must not be reused on consumed resources
parent c6288537
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
<string>base_application</string> <string>base_application</string>
<string>industrial_phase</string> <string>industrial_phase</string>
<string>quantity_unit</string> <string>quantity_unit</string>
<string>aggregate</string>
</tuple> </tuple>
</value> </value>
</item> </item>
......
...@@ -134,6 +134,8 @@ class TransformationRuleMovementGenerator(MovementGeneratorMixin): ...@@ -134,6 +134,8 @@ class TransformationRuleMovementGenerator(MovementGeneratorMixin):
amount.getCategoryList(), amount.getCategoryList(),
base=True) base=True)
movement.quantity = - movement.quantity movement.quantity = - movement.quantity
# aggregation of items should not be propagated to what comes from transformation
movement.setAggregateList([])
yield movement yield movement
phase_dict = parent_movement.asComposedDocument() \ phase_dict = parent_movement.asComposedDocument() \
.getPreviousTradePhaseDict(phase_set) .getPreviousTradePhaseDict(phase_set)
......
...@@ -39,7 +39,7 @@ class TestBPMMixin(ERP5TypeTestCase): ...@@ -39,7 +39,7 @@ class TestBPMMixin(ERP5TypeTestCase):
"""Skeletons for tests which depend on BPM""" """Skeletons for tests which depend on BPM"""
def getBusinessTemplateList(self): def getBusinessTemplateList(self):
return ('erp5_base', 'erp5_pdm', 'erp5_simulation', 'erp5_trade', return ('erp5_base', 'erp5_pdm', 'erp5_simulation', 'erp5_trade', 'erp5_item',
'erp5_accounting', 'erp5_invoicing', 'erp5_simplified_invoicing', 'erp5_accounting', 'erp5_invoicing', 'erp5_simplified_invoicing',
'erp5_core_proxy_field_legacy', 'erp5_core_proxy_field_legacy',
'erp5_configurator_standard_solver', 'erp5_configurator_standard_solver',
......
...@@ -133,31 +133,40 @@ class TestMRPMixin(TestBPMMixin): ...@@ -133,31 +133,40 @@ class TestMRPMixin(TestBPMMixin):
def createDefaultTransformation(self): def createDefaultTransformation(self):
resource = lambda: self.createProduct(quantity_unit_list=['weight/kg']) resource = lambda: self.createProduct(quantity_unit_list=['weight/kg'])
transformation = self.createTransformation(resource_value=resource()) self.produced_resource = resource()
transformation = self.createTransformation(resource_value=self.produced_resource)
self.consumed_resource_1 = resource()
self.createTransformedResource(transformation=transformation, self.createTransformedResource(transformation=transformation,
resource_value=resource(), resource_value=self.consumed_resource_1,
quantity=3, quantity=3,
quantity_unit_list=['weight/kg'], quantity_unit_list=['weight/kg'],
trade_phase='mrp/p0') trade_phase='mrp/p0')
self.consumed_resource_2 = resource()
self.createTransformedResource(transformation=transformation, self.createTransformedResource(transformation=transformation,
resource_value=resource(), resource_value=self.consumed_resource_2,
quantity=1, quantity=1,
quantity_unit_list=['weight/kg'], quantity_unit_list=['weight/kg'],
trade_phase='mrp/p0') trade_phase='mrp/p0')
self.consumed_resource_3 = resource()
self.createTransformedResource(transformation=transformation, self.createTransformedResource(transformation=transformation,
resource_value=resource(), resource_value=self.consumed_resource_3,
quantity=4, quantity=4,
quantity_unit_list=['weight/kg'], quantity_unit_list=['weight/kg'],
trade_phase='mrp/p1') trade_phase='mrp/p1')
self.consumed_resource_4 = resource()
self.createTransformedResource(transformation=transformation, self.createTransformedResource(transformation=transformation,
resource_value=resource(), resource_value=self.consumed_resource_4,
quantity=1, quantity=1,
quantity_unit_list=['weight/kg'], quantity_unit_list=['weight/kg'],
trade_phase='mrp/p1') trade_phase='mrp/p1')
return transformation return transformation
def createBusinessProcess1(self, node_p0=None): def createBusinessProcess1(self, node_p0=None):
""" order p0 s0 p1 deliver """
PPL : Production Packing List
PR : Production Report
PO : Production Order
order p0 s0 p1 deliver
------- S0 ---- S1 ---- S2 ---- S3 ------- S4 ------- S0 ---- S1 ---- S2 ---- S3 ------- S4
PO PR PPL PR PPL PO PR PPL PR PPL
""" """
...@@ -207,18 +216,23 @@ class TestMRPMixin(TestBPMMixin): ...@@ -207,18 +216,23 @@ class TestMRPMixin(TestBPMMixin):
class TestMRPImplementation(TestMRPMixin): class TestMRPImplementation(TestMRPMixin):
"""the test for implementation""" """the test for implementation"""
def test(self): def createMRPOrder(self, use_item=False):
workshop = self.createNode(title='workshop') self.workshop = self.createNode(title='workshop')
workshop2 = self.createNode(title='workshop2') self.workshop2 = self.createNode(title='workshop2')
destination = self.createNode(title='destination') self.destination = self.createNode(title='destination')
business_process = self.createBusinessProcess1(workshop2) business_process = self.createBusinessProcess1(self.workshop2)
order = self.createDefaultOrder(business_process) self.order = self.createDefaultOrder(business_process)
order_line, = order.objectValues() self.order_line, = self.order.objectValues()
order._edit(source_value=workshop, destination_value=destination) if use_item:
self.item = self.portal.item_module.newContent()
self.order_line.setAggregateValue(self.item)
self.order._edit(source_value=self.workshop, destination_value=self.destination)
self.order.plan()
self.tic() self.tic()
order.plan() def testSimpleOrder(self):
self.tic() self.createMRPOrder()
order = self.order
ar, = order.getCausalityRelatedValueList(portal_type="Applied Rule") ar, = order.getCausalityRelatedValueList(portal_type="Applied Rule")
sm, = ar.objectValues() # order sm, = ar.objectValues() # order
...@@ -227,7 +241,7 @@ class TestMRPImplementation(TestMRPMixin): ...@@ -227,7 +241,7 @@ class TestMRPImplementation(TestMRPMixin):
ar, = sm.objectValues() ar, = sm.objectValues()
movement_list = [] movement_list = []
resource = order_line.getResource() resource = self.order_line.getResource()
for sm in ar.objectValues(): for sm in ar.objectValues():
self.assertEqual(sm.getSource(), None) self.assertEqual(sm.getSource(), None)
self.assertTrue(sm.getDestination()) self.assertTrue(sm.getDestination())
...@@ -266,14 +280,14 @@ class TestMRPImplementation(TestMRPMixin): ...@@ -266,14 +280,14 @@ class TestMRPImplementation(TestMRPMixin):
order.localBuild() order.localBuild()
self.tic() self.tic()
variation = 'industrial_phase/trade_phase/mrp/p0' variation = 'industrial_phase/trade_phase/mrp/p0'
self.checkStock(resource, (workshop2, variation, 10)) self.checkStock(resource, (self.workshop2, variation, 10))
ppl1, = getRelatedDeliveryList("Production Packing List") ppl1, = getRelatedDeliveryList("Production Packing List")
ppl1.start() ppl1.start()
ppl1.deliver() ppl1.deliver()
order.localBuild() order.localBuild()
self.tic() self.tic()
self.checkStock(resource, (workshop, variation, 10)) self.checkStock(resource, (self.workshop, variation, 10))
pr2, = (x for x in getRelatedDeliveryList("Production Report") pr2, = (x for x in getRelatedDeliveryList("Production Report")
if x.aq_base is not pr1.aq_base) if x.aq_base is not pr1.aq_base)
...@@ -281,15 +295,44 @@ class TestMRPImplementation(TestMRPMixin): ...@@ -281,15 +295,44 @@ class TestMRPImplementation(TestMRPMixin):
pr2.deliver() pr2.deliver()
order.localBuild() order.localBuild()
self.tic() self.tic()
self.checkStock(resource, (workshop, '', 10)) self.checkStock(resource, (self.workshop, '', 10))
ppl2, = (x for x in getRelatedDeliveryList("Production Packing List") ppl2, = (x for x in getRelatedDeliveryList("Production Packing List")
if x.aq_base is not ppl1.aq_base) if x.aq_base is not ppl1.aq_base)
ppl2.start() ppl2.start()
ppl2.deliver() ppl2.deliver()
self.tic() self.tic()
self.checkStock(resource, (destination, '', 10)) self.checkStock(resource, (self.destination, '', 10))
def checkExpectedLineList(self, delivery, expected_line_list):
found_line_list = []
for line in delivery.getMovementList():
found_line_list.append((line.getResourceValue(), line.getQuantity(),
line.getAggregateValue()))
found_line_list.sort()
expected_line_list.sort()
self.assertEqual(expected_line_list, found_line_list)
def testOrderWithItem(self):
"""
Check item propagation from Production Order to Production Report
and Production Packing List
"""
self.createMRPOrder(use_item=True)
order = self.order
order.confirm()
order.localBuild()
order_line = self.order_line
resource = order_line.getResourceValue()
self.tic()
production_report, = order.getCausalityRelatedValueList(
portal_type="Production Report")
# resource, quantity, item
expected_line_list = [(self.produced_resource, 10.0, self.item),
(self.consumed_resource_1, -30.0, None),
(self.consumed_resource_2, -10.0, None)]
self.checkExpectedLineList(production_report, expected_line_list)
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment