From 4c6a58b69ff571bc861fa139b28e9adf4463ba88 Mon Sep 17 00:00:00 2001
From: Kazuhiko Shiozaki <kazuhiko@nexedi.com>
Date: Fri, 23 Jul 2010 09:49:42 +0000
Subject: [PATCH] add two tests to check if re-expand works fine after
 modifying order lines.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@37253 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/tests/testPackingList.py | 110 +++++++++++++++++++++++++-
 1 file changed, 109 insertions(+), 1 deletion(-)

diff --git a/product/ERP5/tests/testPackingList.py b/product/ERP5/tests/testPackingList.py
index 39b6c2b68b..d06b8281f5 100644
--- a/product/ERP5/tests/testPackingList.py
+++ b/product/ERP5/tests/testPackingList.py
@@ -227,6 +227,17 @@ class TestPackingListMixin(TestOrderMixin):
     packing_list = sequence.get('packing_list')
     self.assertFalse(packing_list.isDivergent())
 
+  def stepChangeOrderLineResource(self, sequence=None,
+                                        sequence_list=None, **kw):
+    """
+    Change the resource of the order.
+    """
+    order = sequence.get('order')
+    resource = sequence.get('resource')
+    for order_line in order.objectValues(
+                             portal_type=self.order_line_portal_type):
+      order_line.edit(resource_value=resource)
+
   def stepChangePackingListLineResource(self, sequence=None,
                                         sequence_list=None, **kw):
     """
@@ -238,6 +249,18 @@ class TestPackingListMixin(TestOrderMixin):
                              portal_type=self.packing_list_line_portal_type):
       packing_list_line.edit(resource_value=resource)
 
+  def stepDecreaseOrderLineQuantity(self, sequence=None, sequence_list=None,
+                                    **kw):
+    """
+    Set a decreased quantity on order lines
+    """
+    order = sequence.get('order')
+    quantity = sequence.get('line_quantity', default=self.default_quantity - 1)
+    sequence.edit(line_quantity=quantity)
+    for order_line in order.objectValues(
+        portal_type=self.order_line_portal_type):
+      order_line.edit(quantity=quantity)
+
   def stepDecreasePackingListLineQuantity(self, sequence=None,
       sequence_list=None, **kw):
     """
@@ -945,7 +968,37 @@ class TestPackingListMixin(TestOrderMixin):
     order = sequence.get('order')
     order.setPriceCurrency(currency.getRelativeUrl())
 
-
+  def _checkRecordedProperty(self, movement_list, property_id, assertion):
+    for movement in movement_list:
+      for simulation_movement in movement.getDeliveryRelatedValueList():
+        if assertion:
+          self.assertTrue(simulation_movement.isPropertyRecorded(property_id))
+        else:
+          self.assertFalse(simulation_movement.isPropertyRecorded(property_id))
+
+  def stepCheckSimulationMovementHasRecordedQuantity(self, sequence=None,
+                                                     sequence_list=None):
+    movement_list = sequence.get('order').objectValues(
+      portal_type=self.order_line_portal_type)
+    self._checkRecordedProperty(movement_list, 'quantity', True)
+
+  def stepCheckSimulationMovementHasNoRecordedQuantity(self, sequence=None,
+                                                       sequence_list=None):
+    movement_list = sequence.get('order').objectValues(
+      portal_type=self.order_line_portal_type)
+    self._checkRecordedProperty(movement_list, 'quantity', False)
+
+  def stepCheckSimulationMovementHasRecordedResource(self, sequence=None,
+                                                     sequence_list=None):
+    movement_list = sequence.get('order').objectValues(
+      portal_type=self.order_line_portal_type)
+    self._checkRecordedProperty(movement_list, 'resource', True)
+
+  def stepCheckSimulationMovementHasNoRecordedResource(self, sequence=None,
+                                                       sequence_list=None):
+    movement_list = sequence.get('order').objectValues(
+      portal_type=self.order_line_portal_type)
+    self._checkRecordedProperty(movement_list, 'resource', False)
 
 class TestPackingList(TestPackingListMixin, ERP5TypeTestCase) :
 
@@ -1573,6 +1626,61 @@ class TestPackingList(TestPackingListMixin, ERP5TypeTestCase) :
 
     sequence_list.play(self, quiet=quiet)
 
+  def test_18_ChangeQuantityOnPackingListAndOrder(self, quiet=quiet):
+    """
+      Change the quantity on a packing list line, and accept the
+      divergence, then change the quantity on an order line to the same
+      value and check if it does not cause divergence on a packing list
+      line and recorded properties are reset after re-expand.
+    """
+    sequence_list = SequenceList()
+
+    # Test with a simply order without cell
+    sequence_string = self.default_sequence + '\
+                      stepDecreasePackingListLineQuantity \
+                      stepTic \
+                      stepCheckPackingListIsDiverged \
+                      stepAcceptDecisionQuantity \
+                      stepTic \
+                      stepCheckPackingListIsSolved \
+                      stepCheckSimulationMovementHasRecordedQuantity \
+                      stepDecreaseOrderLineQuantity \
+                      stepTic \
+                      stepCheckPackingListIsSolved \
+                      stepCheckSimulationMovementHasNoRecordedQuantity \
+                      '
+    sequence_list.addSequenceString(sequence_string)
+
+    sequence_list.play(self, quiet=quiet)
+
+  def test_19_ChangeResourceOnPackingListAndOrder(self, quiet=quiet):
+    """
+      Change the resource on a packing list line, and accept the
+      divergence, then change the resource on an order line to the same
+      value and check if it does not cause divergence on a packing list
+      line and recorded properties are reset after re-expand.
+    """
+    sequence_list = SequenceList()
+
+    # Test with a simply order without cell
+    sequence_string = self.default_sequence + '\
+                      stepCreateNotVariatedResource \
+                      stepChangePackingListLineResource \
+                      stepTic \
+                      stepCheckPackingListIsDiverged \
+                      stepAcceptDecisionResource \
+                      stepTic \
+                      stepCheckPackingListIsSolved \
+                      stepCheckSimulationMovementHasRecordedResource \
+                      stepChangeOrderLineResource \
+                      stepTic \
+                      stepCheckPackingListIsSolved \
+                      stepCheckSimulationMovementHasNoRecordedResource \
+                      '
+    sequence_list.addSequenceString(sequence_string)
+
+    sequence_list.play(self, quiet=quiet)
+
   def test_subcontent_reindexing_packing_list_line_cell(self):
     """Tests, that indexation of Packing List are propagated to subobjects
     during reindxation"""
-- 
2.30.9