[Erp5-report] r20955 - in /erp5/trunk/products/ERP5: Document/ tests/

nobody at svn.erp5.org nobody at svn.erp5.org
Wed May 14 12:14:52 CEST 2008


Author: jerome
Date: Wed May 14 12:14:50 2008
New Revision: 20955

URL: http://svn.erp5.org?rev=20955&view=rev
Log:
Changing properties on a planned order line should update the corresponding simulation, for invoice and accouting.

Rule: propagate values from prevision in _getCompensatedMovementList
InvoiceTransactionRule & InvoicingRule: add properties in _generatePrevision (project, function, payment)
testInvoice: tests that changes on the order line are reflected in invoice and accounting simulation


Modified:
    erp5/trunk/products/ERP5/Document/InvoiceTransactionRule.py
    erp5/trunk/products/ERP5/Document/InvoicingRule.py
    erp5/trunk/products/ERP5/Document/Rule.py
    erp5/trunk/products/ERP5/tests/testInvoice.py

Modified: erp5/trunk/products/ERP5/Document/InvoiceTransactionRule.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/InvoiceTransactionRule.py?rev=20955&r1=20954&r2=20955&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/InvoiceTransactionRule.py (original)
+++ erp5/trunk/products/ERP5/Document/InvoiceTransactionRule.py Wed May 14 12:14:50 2008
@@ -124,8 +124,19 @@
             'id': transaction_line.getId(),
             'source': transaction_line.getSource(),
             'source_section': context_movement.getSourceSection(),
+            'source_decision': context_movement.getSourceDecision(),
+            'source_administration': context_movement.getSourceAdministration(),
+            'source_project': context_movement.getSourceProject(),
+            'source_function': context_movement.getSourceFunction(),
+            'source_payment': context_movement.getSourcePayment(),
             'destination': transaction_line.getDestination(),
             'destination_section': context_movement.getDestinationSection(),
+            'destination_section': context_movement.getDestinationSection(),
+            'destination_decision': context_movement.getDestinationDecision(),
+            'destination_administration': context_movement.getDestinationAdministration(),
+            'destination_project': context_movement.getDestinationProject(),
+            'destination_function': context_movement.getDestinationFunction(),
+            'destination_payment': context_movement.getDestinationPayment(),
             'start_date': context_movement.getStartDate(),
             'stop_date': context_movement.getStopDate(),
             'resource': resource,

Modified: erp5/trunk/products/ERP5/Document/InvoicingRule.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/InvoicingRule.py?rev=20955&r1=20954&r2=20955&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/InvoicingRule.py (original)
+++ erp5/trunk/products/ERP5/Document/InvoicingRule.py Wed May 14 12:14:50 2008
@@ -92,10 +92,16 @@
         'source_section': context_movement.getSourceSection(),
         'source_decision': context_movement.getSourceDecision(),
         'source_administration': context_movement.getSourceAdministration(),
+        'source_project': context_movement.getSourceProject(),
+        'source_function': context_movement.getSourceFunction(),
+        'source_payment': context_movement.getSourcePayment(),
         'destination': context_movement.getDestination(),
         'destination_section': context_movement.getDestinationSection(),
         'destination_decision': context_movement.getDestinationDecision(),
         'destination_administration': context_movement.getDestinationAdministration(),
+        'destination_project': context_movement.getDestinationProject(),
+        'destination_function': context_movement.getDestinationFunction(),
+        'destination_payment': context_movement.getDestinationPayment(),
         'start_date': context_movement.getStartDate(),
         'stop_date': context_movement.getStopDate(),
         'resource': context_movement.getResource(),

Modified: erp5/trunk/products/ERP5/Document/Rule.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/Rule.py?rev=20955&r1=20954&r2=20955&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/Rule.py (original)
+++ erp5/trunk/products/ERP5/Document/Rule.py Wed May 14 12:14:50 2008
@@ -315,19 +315,26 @@
           else:
             prevision['quantity'] = q_diff
             add_list.append(prevision)
+
         # Check the date
         for movement in p_matched_list:
           if movement in (mutable_movement_list \
               + deletable_movement_list):
+            prop_dict = modify_dict.setdefault(movement.getId(), {})
             for prop in ('start_date', 'stop_date'):
               #XXX should be >= 15
               if prevision.get(prop) != movement.getProperty(prop):
-                prop_dict = modify_dict.setdefault(movement.getId(), {})
                 prop_dict[prop] = prevision.get(prop)
                 break
+
+            for k, v in prevision.items():
+              if v != movement.getProperty(k):
+                prop_dict.setdefault(k, v)
+
         # update movement lists
         for movement in p_matched_list:
           non_matched_list.remove(movement)
+
       # No movement matched, we need to create one
       else:
         add_list.append(prevision)

Modified: erp5/trunk/products/ERP5/tests/testInvoice.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/tests/testInvoice.py?rev=20955&r1=20954&r2=20955&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/tests/testInvoice.py (original)
+++ erp5/trunk/products/ERP5/tests/testInvoice.py Wed May 14 12:14:50 2008
@@ -1998,6 +1998,352 @@
     self.assertEquals(order_price_currency,
           delivery_movement.getPriceCurrency())
 
+  def test_modify_planned_order_invoicing_rule(self):
+    # tests that modifying a planned order affects movements from invoicing
+    # rule
+    sequence_list = SequenceList()
+    sequence = sequence_list.addSequenceString('''
+      stepCreateEntities
+      stepCreateCurrency
+      stepCreateSaleInvoiceTransactionRule
+      stepCreateOrder
+      stepSetOrderProfile
+      stepSetOrderPriceCurrency
+      stepCreateNotVariatedResource
+      stepTic
+      stepCreateOrderLine
+      stepSetOrderLineResource
+      stepSetOrderLineDefaultValues
+      stepOrderOrder
+      stepTic
+    ''')
+    sequence_list.play(self, quiet=1)
+    order = sequence.get('order')
+    order_line = sequence.get('order_line')
+    
+    other_entity = self.portal.organisation_module.newContent(
+                                      portal_type='Organisation',
+                                      title='Other Entity')
+    
+
+    related_applied_rule = order.getCausalityRelatedValue(
+                             portal_type='Applied Rule')
+    delivery_movement = related_applied_rule.contentValues()[0]
+    invoice_applied_rule = delivery_movement.contentValues()[0]
+    invoice_movement = invoice_applied_rule.contentValues()[0]
+    
+    order_line.setSourceValue(other_entity)
+    get_transaction().commit()
+    self.tic()
+    invoice_movement = invoice_applied_rule.contentValues()[0]
+    self.assertEquals(other_entity,
+                      invoice_movement.getSourceValue())
+
+    order_line.setDestinationValue(other_entity)
+    get_transaction().commit()
+    self.tic()
+    invoice_movement = invoice_applied_rule.contentValues()[0]
+    self.assertEquals(other_entity,
+                      invoice_movement.getDestinationValue())
+
+    order_line.setSourceSectionValue(other_entity)
+    get_transaction().commit()
+    self.tic()
+    invoice_movement = invoice_applied_rule.contentValues()[0]
+    self.assertEquals(other_entity,
+                      invoice_movement.getSourceSectionValue())
+
+    # make sure destination_section != source_section, this might be needed by
+    # some rules
+    order_line.setSourceSectionValue(order_line.getDestinationSectionValue())
+
+    order_line.setDestinationSectionValue(other_entity)
+    get_transaction().commit()
+    self.tic()
+    invoice_movement = invoice_applied_rule.contentValues()[0]
+    self.assertEquals(other_entity,
+                 invoice_movement.getDestinationSectionValue())
+
+    order_line.setSourceAdministrationValue(other_entity)
+    get_transaction().commit()
+    self.tic()
+    invoice_movement = invoice_applied_rule.contentValues()[0]
+    self.assertEquals(other_entity,
+                 invoice_movement.getSourceAdministrationValue())
+
+    order_line.setDestinationAdministrationValue(other_entity)
+    get_transaction().commit()
+    self.tic()
+    invoice_movement = invoice_applied_rule.contentValues()[0]
+    self.assertEquals(other_entity,
+            invoice_movement.getDestinationAdministrationValue())
+
+    order_line.setSourceDecisionValue(other_entity)
+    get_transaction().commit()
+    self.tic()
+    invoice_movement = invoice_applied_rule.contentValues()[0]
+    self.assertEquals(other_entity,
+                 invoice_movement.getSourceDecisionValue())
+
+    order_line.setDestinationDecisionValue(other_entity)
+    get_transaction().commit()
+    self.tic()
+    invoice_movement = invoice_applied_rule.contentValues()[0]
+    self.assertEquals(other_entity,
+            invoice_movement.getDestinationDecisionValue())
+
+    order_line.setSourceProjectValue(other_entity)
+    get_transaction().commit()
+    self.tic()
+    invoice_movement = invoice_applied_rule.contentValues()[0]
+    self.assertEquals(other_entity,
+                 invoice_movement.getSourceProjectValue())
+
+    order_line.setDestinationProjectValue(other_entity)
+    get_transaction().commit()
+    self.tic()
+    invoice_movement = invoice_applied_rule.contentValues()[0]
+    self.assertEquals(other_entity,
+            invoice_movement.getDestinationProjectValue())
+
+    order_line.setSourcePaymentValue(other_entity)
+    get_transaction().commit()
+    self.tic()
+    invoice_movement = invoice_applied_rule.contentValues()[0]
+    self.assertEquals(other_entity,
+                 invoice_movement.getSourcePaymentValue())
+
+    order_line.setDestinationPaymentValue(other_entity)
+    get_transaction().commit()
+    self.tic()
+    invoice_movement = invoice_applied_rule.contentValues()[0]
+    self.assertEquals(other_entity,
+            invoice_movement.getDestinationPaymentValue())
+
+    order_line.setSourceFunctionValue(other_entity)
+    get_transaction().commit()
+    self.tic()
+    invoice_movement = invoice_applied_rule.contentValues()[0]
+    self.assertEquals(other_entity,
+                 invoice_movement.getSourceFunctionValue())
+
+    order_line.setDestinationFunctionValue(other_entity)
+    get_transaction().commit()
+    self.tic()
+    invoice_movement = invoice_applied_rule.contentValues()[0]
+    self.assertEquals(other_entity,
+            invoice_movement.getDestinationFunctionValue())
+
+    self.assertNotEquals(123, order_line.getPrice())
+    order_line.setPrice(123)
+    get_transaction().commit()
+    self.tic()
+    invoice_movement = invoice_applied_rule.contentValues()[0]
+    self.assertEquals(123,
+            invoice_movement.getPrice())
+
+    self.assertNotEquals(456, order_line.getQuantity())
+    order_line.setQuantity(456)
+    get_transaction().commit()
+    self.tic()
+    invoice_movement = invoice_applied_rule.contentValues()[0]
+    self.assertEquals(456,
+            invoice_movement.getQuantity())
+
+    other_resource = self.portal.product_module.newContent(
+                                        portal_type='Product',
+                                        title='Other Resource')
+    order_line.setResourceValue(other_resource)
+    get_transaction().commit()
+    self.tic()
+    invoice_movement = invoice_applied_rule.contentValues()[0]
+    self.assertEquals(other_resource,
+            invoice_movement.getResourceValue())
+
+    order_line.setStartDate(DateTime(2001, 02, 03))
+    get_transaction().commit()
+    self.tic()
+    invoice_movement = invoice_applied_rule.contentValues()[0]
+    self.assertEquals(DateTime(2001, 02, 03),
+                 invoice_movement.getStartDate())
+
+    order_line.setStopDate(DateTime(2002, 03, 04))
+    get_transaction().commit()
+    self.tic()
+    invoice_movement = invoice_applied_rule.contentValues()[0]
+    self.assertEquals(DateTime(2002, 03, 04),
+                 invoice_movement.getStopDate())
+
+  def test_modify_planned_order_invoice_transaction_rule(self):
+    # tests that modifying a planned order affects movements from invoice
+    # transaction rule
+    sequence_list = SequenceList()
+    sequence = sequence_list.addSequenceString('''
+      stepCreateEntities
+      stepCreateCurrency
+      stepCreateSaleInvoiceTransactionRule
+      stepCreateOrder
+      stepSetOrderProfile
+      stepSetOrderPriceCurrency
+      stepCreateNotVariatedResource
+      stepTic
+      stepCreateOrderLine
+      stepSetOrderLineResource
+      stepSetOrderLineDefaultValues
+      stepOrderOrder
+      stepTic
+    ''')
+    sequence_list.play(self, quiet=1)
+    order = sequence.get('order')
+    order_line = sequence.get('order_line')
+    
+    other_entity = self.portal.organisation_module.newContent(
+                                      portal_type='Organisation',
+                                      title='Other Entity')
+
+    related_applied_rule = order.getCausalityRelatedValue(
+                             portal_type='Applied Rule')
+    delivery_movement = related_applied_rule.contentValues()[0]
+    invoice_applied_rule = delivery_movement.contentValues()[0]
+    invoice_movement = invoice_applied_rule.contentValues()[0]
+    invoice_transaction_applied_rule = invoice_movement.contentValues()[0]
+    invoice_transaction_movement =\
+         invoice_transaction_applied_rule._getOb('income')
+    
+    order_line.setSourceSectionValue(other_entity)
+    get_transaction().commit()
+    self.tic()
+    self.assertEquals(other_entity,
+                      invoice_transaction_movement.getSourceSectionValue())
+
+    # make sure destination_section != source_section, this might be needed by
+    # some rules
+    order_line.setSourceSectionValue(order_line.getDestinationSectionValue())
+
+    order_line.setDestinationSectionValue(other_entity)
+    get_transaction().commit()
+    self.tic()
+    invoice_transaction_movement =\
+         invoice_transaction_applied_rule._getOb('income')
+    self.assertEquals(other_entity,
+                 invoice_transaction_movement.getDestinationSectionValue())
+
+    order_line.setSourceAdministrationValue(other_entity)
+    get_transaction().commit()
+    self.tic()
+    invoice_transaction_movement =\
+         invoice_transaction_applied_rule._getOb('income')
+    self.assertEquals(other_entity,
+                 invoice_transaction_movement.getSourceAdministrationValue())
+
+    order_line.setDestinationAdministrationValue(other_entity)
+    get_transaction().commit()
+    self.tic()
+    invoice_transaction_movement =\
+         invoice_transaction_applied_rule._getOb('income')
+    self.assertEquals(other_entity,
+            invoice_transaction_movement.getDestinationAdministrationValue())
+
+    order_line.setSourceDecisionValue(other_entity)
+    get_transaction().commit()
+    self.tic()
+    invoice_transaction_movement =\
+         invoice_transaction_applied_rule._getOb('income')
+    self.assertEquals(other_entity,
+                 invoice_transaction_movement.getSourceDecisionValue())
+
+    order_line.setDestinationDecisionValue(other_entity)
+    get_transaction().commit()
+    self.tic()
+    invoice_transaction_movement =\
+         invoice_transaction_applied_rule._getOb('income')
+    self.assertEquals(other_entity,
+            invoice_transaction_movement.getDestinationDecisionValue())
+
+    order_line.setSourceProjectValue(other_entity)
+    get_transaction().commit()
+    self.tic()
+    invoice_transaction_movement =\
+         invoice_transaction_applied_rule._getOb('income')
+    self.assertEquals(other_entity,
+                 invoice_transaction_movement.getSourceProjectValue())
+
+    order_line.setDestinationProjectValue(other_entity)
+    get_transaction().commit()
+    self.tic()
+    invoice_transaction_movement =\
+         invoice_transaction_applied_rule._getOb('income')
+    self.assertEquals(other_entity,
+            invoice_transaction_movement.getDestinationProjectValue())
+
+    order_line.setSourceFunctionValue(other_entity)
+    get_transaction().commit()
+    self.tic()
+    invoice_transaction_movement =\
+         invoice_transaction_applied_rule._getOb('income')
+    self.assertEquals(other_entity,
+                 invoice_transaction_movement.getSourceFunctionValue())
+
+    order_line.setDestinationFunctionValue(other_entity)
+    get_transaction().commit()
+    self.tic()
+    invoice_transaction_movement =\
+         invoice_transaction_applied_rule._getOb('income')
+    self.assertEquals(other_entity,
+            invoice_transaction_movement.getDestinationFunctionValue())
+
+    order_line.setSourcePaymentValue(other_entity)
+    get_transaction().commit()
+    self.tic()
+    invoice_transaction_movement =\
+         invoice_transaction_applied_rule._getOb('income')
+    self.assertEquals(other_entity,
+                 invoice_transaction_movement.getSourcePaymentValue())
+
+    order_line.setDestinationPaymentValue(other_entity)
+    get_transaction().commit()
+    self.tic()
+    invoice_transaction_movement =\
+         invoice_transaction_applied_rule._getOb('income')
+    self.assertEquals(other_entity,
+            invoice_transaction_movement.getDestinationPaymentValue())
+
+    order_line.setQuantity(1)
+    order_line.setPrice(123)
+    get_transaction().commit()
+    self.tic()
+    invoice_transaction_movement =\
+         invoice_transaction_applied_rule._getOb('income')
+    self.assertEquals(123,
+            invoice_transaction_movement.getQuantity())
+
+    order_line.setQuantity(456)
+    order_line.setPrice(1)
+    get_transaction().commit()
+    self.tic()
+    invoice_transaction_movement =\
+         invoice_transaction_applied_rule._getOb('income')
+    self.assertEquals(456,
+            invoice_transaction_movement.getQuantity())
+
+    order_line.setStartDate(DateTime(2001, 02, 03))
+    get_transaction().commit()
+    self.tic()
+    invoice_transaction_movement =\
+         invoice_transaction_applied_rule._getOb('income')
+    self.assertEquals(DateTime(2001, 02, 03),
+                 invoice_transaction_movement.getStartDate())
+
+    order_line.setStopDate(DateTime(2002, 03, 04))
+    get_transaction().commit()
+    self.tic()
+    invoice_transaction_movement =\
+         invoice_transaction_applied_rule._getOb('income')
+    self.assertEquals(DateTime(2002, 03, 04),
+                 invoice_transaction_movement.getStopDate())
+
+
+
 #class TestPurchaseInvoice(TestInvoice):
 #  order_portal_type = 'Purchase Order'
 #  order_line_portal_type = 'Purchase Order Line'




More information about the Erp5-report mailing list