[Erp5-report] r11638 - in /erp5/trunk/bt5/erp5_accounting: SkinTemplateItem/portal_skins/er...

nobody at svn.erp5.org nobody at svn.erp5.org
Thu Dec 7 16:15:29 CET 2006


Author: jerome
Date: Thu Dec  7 16:15:27 2006
New Revision: 11638

URL: http://svn.erp5.org?rev=11638&view=rev
Log:
Creating a related payment for an invoice will also take into account lines in transactions related to this invoice by the causality relation.


Modified:
    erp5/trunk/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/Invoice_createRelatedPaymentTransaction.xml
    erp5/trunk/bt5/erp5_accounting/bt/revision

Modified: erp5/trunk/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/Invoice_createRelatedPaymentTransaction.xml
URL: http://svn.erp5.org/erp5/trunk/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/Invoice_createRelatedPaymentTransaction.xml?rev=11638&r1=11637&r2=11638&view=diff
==============================================================================
--- erp5/trunk/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/Invoice_createRelatedPaymentTransaction.xml (original)
+++ erp5/trunk/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/Invoice_createRelatedPaymentTransaction.xml Thu Dec  7 16:15:27 2006
@@ -73,8 +73,8 @@
 be provided, but by default the transaction is created at the system date.\n
 """\n
 from DateTime import DateTime\n
-# translate with Base_translateString which is a bit more robust during activities\n
-# because it doesn\'t rely on REQUEST[\'PARENTS\']\n
+# translate with Base_translateString which is a bit more robust during\n
+# activities, because it doesn\'t rely on REQUEST[\'PARENTS\']\n
 N_ = context.Base_translateString\n
 \n
 date = DateTime()\n
@@ -118,25 +118,82 @@
    id=\'bank\',\n
 )\n
 \n
+# Calculate the payable/receivable quantity, for this we sum all lines\n
+# using a payable or receivable type account in this invoice ( unless this\n
+# line have a "grouping reference") minus the sum of payable/receivable line on\n
+# all causality related accounting transactions\n
 bank_quantity = 0\n
-for line in context.objectValues(\n
+receivable_or_payable_quantity_per_account = {}\n
+for line in context.getMovementList(\n
             portal_type=portal.getPortalAccountingMovementTypeList()):\n
   if is_source:\n
     account = line.getSourceValue(portal_type=\'Account\')\n
+    mirror_account = line.getDestinationValue(portal_type=\'Account\')\n
   else:\n
     account = line.getDestinationValue(portal_type=\'Account\')\n
+    mirror_account = line.getSourceValue(portal_type=\'Account\')\n
   \n
+  key = (account, mirror_account)\n
   if account is not None and \\\n
       account.getAccountTypeId() in (\'payable\', \'receivable\') and \\\n
       line.getSourceSection() == context.getSourceSection() and \\\n
       line.getDestinationSection() == context.getDestinationSection() and \\\n
-      not line.getGroupingReference() :\n
-     related_payment.newContent(\n
-       portal_type=line_portal_type,\n
-       source=line.getSource(),\n
-       destination=line.getDestination(),\n
-       quantity= - line.getQuantity())\n
-     bank_quantity += line.getQuantity()\n
+      not line.getGroupingReference():\n
+    receivable_or_payable_quantity_per_account[key] = \\\n
+            receivable_or_payable_quantity_per_account.get(key, 0) \\\n
+                            - line.getQuantity()\n
+    bank_quantity += line.getQuantity()\n
+\n
+for related_transaction in context.getCausalityRelatedValueList(\n
+      portal_type=context.getPortalAccountingTransactionTypeList()):\n
+  if related_transaction.getSimulationState() in (\n
+              \'draft\', \'cancelled\', \'deleted\'):\n
+    continue\n
+  related_transaction_is_source = related_transaction.\\\n
+                                        AccountingTransaction_isSourceView()\n
+  for line in related_transaction.getMovementList(\n
+            portal_type=portal.getPortalAccountingMovementTypeList()):\n
+    if related_transaction_is_source:\n
+      account = line.getSourceValue(portal_type=\'Account\')\n
+      mirror_account = line.getDestinationValue(portal_type=\'Account\')\n
+    else:\n
+      account = line.getDestinationValue(portal_type=\'Account\')\n
+      mirror_account = line.getSourceValue(portal_type=\'Account\')\n
+  \n
+    key = (account, mirror_account)\n
+    if account is not None and \\\n
+        account.getAccountTypeId() in (\'payable\', \'receivable\'):\n
+      if line.getSourceSection() == context.getSourceSection() and \\\n
+         line.getDestinationSection() == context.getDestinationSection() and \\\n
+         not line.getGroupingReference():\n
+        receivable_or_payable_quantity_per_account[key] = \\\n
+            receivable_or_payable_quantity_per_account.get(key, 0) \\\n
+                       - line.getQuantity()\n
+        bank_quantity += line.getQuantity()\n
+      elif line.getSourceSection() == context.getDestinationSection() and \\\n
+           line.getDestinationSection() == context.getSourceSection() and \\\n
+           not line.getGroupingReference():\n
+        receivable_or_payable_quantity_per_account[key] = \\\n
+            receivable_or_payable_quantity_per_account.get(key, 0) \\\n
+                       + line.getQuantity()\n
+        bank_quantity -= line.getQuantity()\n
+\n
+# now create lines using the dictionnary\n
+for (account, mirror_account), quantity in\\\n
+        receivable_or_payable_quantity_per_account.items():\n
+  if is_source:\n
+    related_payment.newContent(\n
+      portal_type=line_portal_type,\n
+      source_value=account,\n
+      destination_value=mirror_account,\n
+      quantity=quantity)\n
+  else:\n
+    related_payment.newContent(\n
+      portal_type=line_portal_type,\n
+      source_value=mirror_account,\n
+      destination_value=account,\n
+      quantity=-quantity)\n
+\n
 \n
 if is_source:\n
   bank.edit( source=node,\n
@@ -212,10 +269,17 @@
                             <string>related_payment</string>
                             <string>bank</string>
                             <string>bank_quantity</string>
+                            <string>receivable_or_payable_quantity_per_account</string>
                             <string>_getiter_</string>
                             <string>line</string>
                             <string>account</string>
+                            <string>mirror_account</string>
+                            <string>key</string>
                             <string>None</string>
+                            <string>_write_</string>
+                            <string>related_transaction</string>
+                            <string>related_transaction_is_source</string>
+                            <string>quantity</string>
                           </tuple>
                         </value>
                     </item>

Modified: erp5/trunk/bt5/erp5_accounting/bt/revision
URL: http://svn.erp5.org/erp5/trunk/bt5/erp5_accounting/bt/revision?rev=11638&r1=11637&r2=11638&view=diff
==============================================================================
--- erp5/trunk/bt5/erp5_accounting/bt/revision (original)
+++ erp5/trunk/bt5/erp5_accounting/bt/revision Thu Dec  7 16:15:27 2006
@@ -1,1 +1,1 @@
-140
+142




More information about the Erp5-report mailing list