Commit 877c7bc3 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

Fix Expand of Frozen split and defer simulation

Expanding frozen Simulation resulting from a split and Defer raise a `NotImplementedError`.

It comes from the `_extendMovementCollectionDiff` function in [RuleMixin](product/ERP5/mixin/rule.py) checking the recorded property "Quantity". The Quantity Split Solver set this variable to zero hence leading the function to consider compensation is needed. This merge request remove the setting of the recorded property `quantity` on the the split movement. Re-expanding from the root was also removing that recorded property asking the question if this is needed.

As of now system having used Split and defer Quantity will most likely not be able to re-expand their resulting simulation.

A Test is added to validate the fix.

See merge request !1097
parents 468da0e3 cc4d52b4
......@@ -371,7 +371,7 @@ class RuleMixin(Predicate):
updatable_compensation_movement.setQuantity(
updatable_compensation_movement.getQuantity() + missing_quantity)
updatable_compensation_movement.clearRecordedProperty('quantity')
else:
elif missing_quantity:
# We must create a profit and loss movement
new_movement = self._newProfitAndLossMovement(prevision_movement)
if new_movement is not None:
......
......@@ -26,6 +26,7 @@
#
##############################################################################
from collections import deque
import unittest
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
......@@ -36,6 +37,15 @@ from Products.ERP5Type.tests.Sequence import SequenceList
from Products.ERP5.tests.testOrder import TestOrderMixin
from DateTime import DateTime
def getTree(self):
tree = []
object_list = deque((self,))
while object_list:
self = object_list.popleft()
tree.append(self)
object_list += self.objectValues()
return tree
class TestPackingListMixin(TestOrderMixin):
"""
Test business template erp5_trade
......@@ -1504,6 +1514,88 @@ class TestPackingList(TestPackingListMixin, ERP5TypeTestCase) :
sequence_list.play(self, quiet=quiet)
def stepDeliverPackingList(self, sequence=None, sequence_list=None, **kw):
"""
Deliver Packing List
"""
packing_list = sequence.get('packing_list')
packing_list.stop()
packing_list.deliver()
def stepDeliverNewPackingList(self, sequence=None, sequence_list=None, **kw):
"""
Deliver New Packing List
"""
packing_list = sequence.get('new_packing_list')
packing_list.stop()
packing_list.deliver()
def stepCheckExpandOrderRootAppliedRuleIsStable(self, sequence=None, sequence_list=None, **kw):
"""
Check Order Applied Rule can be expanded without error
"""
order = sequence.get('order')
related_applied_rule_list = order.getCausalityRelatedValueList( \
portal_type=self.applied_rule_portal_type)
applied_rule = related_applied_rule_list[0].getObject()
before = set(getTree(applied_rule))
applied_rule.expand("immediate")
after = getTree(applied_rule)
self.assertTrue(before.issubset(after))
for element in after:
if element in before:
if (element.getPortalType() == 'Simulation Movement' and
element.getDelivery() and
element.getParentValue().getSpecialiseValue().getPortalType()
!= 'Order Root Simulation Rule'):
self.assertFalse(element.getDivergenceList())
else:
if element.getPortalType() == 'Simulation Movement':
element = element.getParentValue()
self.assertNotIn(element, before)
def test_11_02_PackingListDecreaseTwoTimesQuantityAndUpdateDeliveryAndDeliver(self,
quiet=quiet, run=run_all_test):
"""
Change the quantity on an delivery line, then
see if the packing list is divergent and then
split and defer the packing list.
Deliver Packing Lists and make sure the root can be expanded
"""
if not run: return
sequence_list = SequenceList()
sequence_string = self.default_sequence + """
DecreasePackingListLineQuantity
CheckPackingListIsCalculating
Tic
CheckPackingListIsDiverged
SplitAndDeferPackingList
Tic
CheckPackingListIsSolved
CheckPackingListSplitted
DecreasePackingListLineQuantity
CheckPackingListIsCalculating
Tic
CheckPackingListIsDiverged
SplitAndDeferPackingList
Tic
CheckNewPackingListIsDivergent
NewPackingListAdoptPrevisionQuantity
Tic
CheckPackingListIsSolved
CheckNewPackingListIsSolved
CheckPackingListSplittedTwoTimes
DeliverPackingList
DeliverNewPackingList
Tic
CheckExpandOrderRootAppliedRuleIsStable
"""
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self, quiet=quiet)
def stepSplitAndMovePackingList(self, sequence=None, sequence_list=None, **kw):
"""
Do the split and move to another delivery action
......
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