Commit 4bc7ebe5 authored by Jérome Perrin's avatar Jérome Perrin

Some problems with Invoice_createRelatedPaymentTransaction where detected in...

Some problems with Invoice_createRelatedPaymentTransaction where detected in tests for a client project.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@11670 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 854de185
...@@ -92,7 +92,7 @@ portal.portal_selections.setSelectionParamsFor(\n ...@@ -92,7 +92,7 @@ portal.portal_selections.setSelectionParamsFor(\n
\n \n
related_payment = portal.accounting_module.newContent(\n related_payment = portal.accounting_module.newContent(\n
portal_type="Payment Transaction",\n portal_type="Payment Transaction",\n
title = str(N_("Payment of ${invoice_title}",\n title=str(N_("Payment of ${invoice_title}",\n
mapping=dict(invoice_title=unicode((context.getReference() or\n mapping=dict(invoice_title=unicode((context.getReference() or\n
context.getTitle() or \'\'),\n context.getTitle() or \'\'),\n
\'utf8\', \'repr\')))),\n \'utf8\', \'repr\')))),\n
...@@ -108,10 +108,13 @@ related_payment = portal.accounting_module.newContent(\n ...@@ -108,10 +108,13 @@ related_payment = portal.accounting_module.newContent(\n
if is_source:\n if is_source:\n
related_payment.edit(destination_payment=context.getDestinationPayment(),\n related_payment.edit(destination_payment=context.getDestinationPayment(),\n
source_payment=payment)\n source_payment=payment)\n
section = context.getSourceSection()\n
mirror_section = context.getDestinationSection()\n
else:\n else:\n
related_payment.edit(destination_payment=payment,\n related_payment.edit(destination_payment=payment,\n
source_payment=context.getSourcePayment())\n source_payment=context.getSourcePayment())\n
\n section = context.getDestinationSection()\n
mirror_section = context.getSourceSection()\n
\n \n
bank = related_payment.newContent(\n bank = related_payment.newContent(\n
portal_type=line_portal_type,\n portal_type=line_portal_type,\n
...@@ -123,29 +126,40 @@ bank = related_payment.newContent(\n ...@@ -123,29 +126,40 @@ bank = related_payment.newContent(\n
# line have a "grouping reference") minus the sum of payable/receivable line on\n # line have a "grouping reference") minus the sum of payable/receivable line on\n
# all causality related accounting transactions\n # all causality related accounting transactions\n
bank_quantity = 0\n bank_quantity = 0\n
receivable_or_payable_quantity_per_account = {}\n quantity_per_account = {}\n
for line in context.getMovementList(\n for line in context.getMovementList(\n
portal_type=portal.getPortalAccountingMovementTypeList()):\n portal_type=portal.getPortalAccountingMovementTypeList()):\n
\n
if line.getGroupingReference():\n
# we ignore line that have a \'letter\'\n
continue\n
\n
if is_source:\n if is_source:\n
account = line.getSourceValue(portal_type=\'Account\')\n account = line.getSourceValue(portal_type=\'Account\')\n
mirror_account = line.getDestinationValue(portal_type=\'Account\')\n mirror_account = line.getDestinationValue(portal_type=\'Account\')\n
line_section = line.getSourceSection()\n
line_mirror_section = line.getDestinationSection()\n
qty = -line.getQuantity()\n
else:\n else:\n
account = line.getDestinationValue(portal_type=\'Account\')\n account = line.getDestinationValue(portal_type=\'Account\')\n
mirror_account = line.getSourceValue(portal_type=\'Account\')\n mirror_account = line.getSourceValue(portal_type=\'Account\')\n
line_section = line.getDestinationSection()\n
line_mirror_section = line.getSourceSection()\n
qty = line.getQuantity()\n
\n \n
key = (account, mirror_account)\n key = (account, mirror_account)\n
if account is not None and \\\n if account is not None and \\\n
account.getAccountTypeId() in (\'payable\', \'receivable\') and \\\n account.getAccountTypeId() in (\'payable\', \'receivable\'):\n
line.getSourceSection() == context.getSourceSection() and \\\n if line_section == section and line_mirror_section == mirror_section:\n
line.getDestinationSection() == context.getDestinationSection() and \\\n quantity_per_account[key] = quantity_per_account.get(key, 0) - qty\n
not line.getGroupingReference():\n bank_quantity += qty\n
receivable_or_payable_quantity_per_account[key] = \\\n elif line_section == mirror_section and line_mirror_section == section:\n
receivable_or_payable_quantity_per_account.get(key, 0) \\\n quantity_per_account[key] = quantity_per_account.get(key, 0) + qty\n
- line.getQuantity()\n bank_quantity -= qty\n
bank_quantity += line.getQuantity()\n
\n \n
for related_transaction in context.getCausalityRelatedValueList(\n for related_transaction in context.getCausalityRelatedValueList(\n
portal_type=context.getPortalAccountingTransactionTypeList()):\n portal_type=context.getPortalAccountingTransactionTypeList()):\n
# XXX copy n paste :(\n
if related_transaction.getSimulationState() in (\n if related_transaction.getSimulationState() in (\n
\'draft\', \'cancelled\', \'deleted\'):\n \'draft\', \'cancelled\', \'deleted\'):\n
continue\n continue\n
...@@ -153,51 +167,56 @@ for related_transaction in context.getCausalityRelatedValueList(\n ...@@ -153,51 +167,56 @@ for related_transaction in context.getCausalityRelatedValueList(\n
AccountingTransaction_isSourceView()\n AccountingTransaction_isSourceView()\n
for line in related_transaction.getMovementList(\n for line in related_transaction.getMovementList(\n
portal_type=portal.getPortalAccountingMovementTypeList()):\n portal_type=portal.getPortalAccountingMovementTypeList()):\n
\n
if line.getGroupingReference():\n
# we ignore line that have a \'letter\'\n
continue\n
\n
if related_transaction_is_source:\n if related_transaction_is_source:\n
account = line.getSourceValue(portal_type=\'Account\')\n account = line.getSourceValue(portal_type=\'Account\')\n
mirror_account = line.getDestinationValue(portal_type=\'Account\')\n mirror_account = line.getDestinationValue(portal_type=\'Account\')\n
line_section = line.getSourceSection()\n
line_mirror_section = line.getDestinationSection()\n
else:\n else:\n
account = line.getDestinationValue(portal_type=\'Account\')\n account = line.getDestinationValue(portal_type=\'Account\')\n
mirror_account = line.getSourceValue(portal_type=\'Account\')\n mirror_account = line.getSourceValue(portal_type=\'Account\')\n
line_section = line.getDestinationSection()\n
line_mirror_section = line.getSourceSection()\n
\n
if is_source:\n
qty = -line.getQuantity()\n
else:\n
qty = line.getQuantity()\n
\n \n
key = (account, mirror_account)\n key = (account, mirror_account)\n
if account is not None and \\\n if account is not None and \\\n
account.getAccountTypeId() in (\'payable\', \'receivable\'):\n account.getAccountTypeId() in (\'payable\', \'receivable\'):\n
if line.getSourceSection() == context.getSourceSection() and \\\n if line_section == section and line_mirror_section == mirror_section:\n
line.getDestinationSection() == context.getDestinationSection() and \\\n quantity_per_account[key] = quantity_per_account.get(key, 0) - qty\n
not line.getGroupingReference():\n bank_quantity += qty\n
receivable_or_payable_quantity_per_account[key] = \\\n \n
receivable_or_payable_quantity_per_account.get(key, 0) \\\n elif line_section == mirror_section and line_mirror_section == section:\n
- line.getQuantity()\n quantity_per_account[key] = quantity_per_account.get(key, 0) + qty\n
bank_quantity += line.getQuantity()\n bank_quantity -= qty\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 \n
# now create lines using the dictionnary\n # now create lines using the dictionnary\n
for (account, mirror_account), quantity in\\\n for (account, mirror_account), quantity in quantity_per_account.items():\n
receivable_or_payable_quantity_per_account.items():\n
if is_source:\n if is_source:\n
related_payment.newContent(\n related_payment.newContent(\n
portal_type=line_portal_type,\n portal_type=line_portal_type,\n
source_value=account,\n source_value=account,\n
destination_value=mirror_account,\n destination_value=mirror_account,\n
quantity=quantity)\n quantity=-quantity)\n
else:\n else:\n
related_payment.newContent(\n related_payment.newContent(\n
portal_type=line_portal_type,\n portal_type=line_portal_type,\n
source_value=mirror_account,\n source_value=mirror_account,\n
destination_value=account,\n destination_value=account,\n
quantity=-quantity)\n quantity=quantity)\n
\n
\n \n
if is_source:\n if is_source:\n
bank.edit( source=node,\n bank.edit( source=node,\n
quantity=bank_quantity )\n quantity=-bank_quantity )\n
else:\n else:\n
bank.edit( destination=node,\n bank.edit( destination=node,\n
quantity=bank_quantity )\n quantity=bank_quantity )\n
...@@ -267,13 +286,18 @@ else:\n ...@@ -267,13 +286,18 @@ else:\n
<string>str</string> <string>str</string>
<string>unicode</string> <string>unicode</string>
<string>related_payment</string> <string>related_payment</string>
<string>section</string>
<string>mirror_section</string>
<string>bank</string> <string>bank</string>
<string>bank_quantity</string> <string>bank_quantity</string>
<string>receivable_or_payable_quantity_per_account</string> <string>quantity_per_account</string>
<string>_getiter_</string> <string>_getiter_</string>
<string>line</string> <string>line</string>
<string>account</string> <string>account</string>
<string>mirror_account</string> <string>mirror_account</string>
<string>line_section</string>
<string>line_mirror_section</string>
<string>qty</string>
<string>key</string> <string>key</string>
<string>None</string> <string>None</string>
<string>_write_</string> <string>_write_</string>
......
145 148
\ No newline at end of file \ No newline at end of file
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