Commit ccf7d473 authored by Sebastien Robin's avatar Sebastien Robin

simulation: fix AdoptSolver when sum of quantities is equal to 0

When AdoptSolver is called for the property 'quantity' on a list of
simulation movements having sum([simulation quantities]) equal to 0,
then the delivery error must be 0.

Before, we were setting as delivery error -quantity of that simulation
movement, then we still had divergence even after the solver was called.
parent 80523287
...@@ -66,9 +66,10 @@ class AdoptSolver(ConfigurablePropertySolverMixin): ...@@ -66,9 +66,10 @@ class AdoptSolver(ConfigurablePropertySolverMixin):
quantity = simulation_movement.getQuantity() quantity = simulation_movement.getQuantity()
if total_quantity == 0: if total_quantity == 0:
delivery_ratio = 1. delivery_ratio = 1.
delivery_error = 0
else: else:
delivery_ratio = quantity / total_quantity delivery_ratio = quantity / total_quantity
delivery_error = total_quantity * delivery_ratio - quantity delivery_error = total_quantity * delivery_ratio - quantity
simulation_movement.edit(delivery_ratio=delivery_ratio, simulation_movement.edit(delivery_ratio=delivery_ratio,
delivery_error=delivery_error, delivery_error=delivery_error,
activate_kw=activate_kw) activate_kw=activate_kw)
......
...@@ -1274,6 +1274,48 @@ class TestPackingList(TestPackingListMixin, ERP5TypeTestCase) : ...@@ -1274,6 +1274,48 @@ class TestPackingList(TestPackingListMixin, ERP5TypeTestCase) :
self.assertEqual('solved', packing_list.getCausalityState()) self.assertEqual('solved', packing_list.getCausalityState())
self.assertEqual(2, len(applied_rule.objectValues())) self.assertEqual(2, len(applied_rule.objectValues()))
def stepModifySimulationMovementWithOppositeQuantities(self,sequence=None, sequence_list=None, **kw):
"""
Make simulation movement having opposite quantities
"""
simulation_movement_list = self._getSPLSimulationMovementList(sequence)
new_quantity_list = [self.default_quantity, -self.default_quantity]
for index, simulation_movement in enumerate(simulation_movement_list):
# we record the property so it doesn't get changed by expand with
# the value from a higher simulation level
simulation_movement.recordProperty('quantity')
simulation_movement.edit(quantity=new_quantity_list[index])
simulation_movement.expand()
def stepCheckPackingListLineHavingQuantityZero(self,sequence=None, sequence_list=None, **kw):
"""
Look if the packing list has new previsions
"""
packing_list_line = sequence.get('packing_list_line')
self.assertEqual(packing_list_line.getQuantity(), 0)
def test_05h_SimulationAdoptPrevisionOnAMergeLineHavingQuantityZero(self):
"""
In some cases, we might have several simulation movements that makes a total
quantity of zero. Make sure Adopt Solver works fine in such case
"""
sequence_list = SequenceList()
sequence_string = self.default_sequence_with_duplicated_lines + """
CheckTwoSimulationLines
ModifySimulationMovementWithOppositeQuantities
Tic
CheckPackingListIsDiverged
AdoptPrevisionQuantity
Tic
CheckPackingListIsNotDivergent
CheckPackingListIsSolved
CheckPackingListLineHavingQuantityZero
"""
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self)
# The 3 following tests currently fail because they are making assertions on # The 3 following tests currently fail because they are making assertions on
# an applied rule which with the new simulation structure is not the same as # an applied rule which with the new simulation structure is not the same as
# in the original test packing list. # in the original test packing list.
......
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