Commit 357a70ac authored by Jérome Perrin's avatar Jérome Perrin

Repair AccountingTransaction_roundDebitCredit: this script should round debit /

credit on created line (and adjust cents on the last line if needed, and if the 
difference is not too big, not to hide error in the configuration).
Enable AccountingTransaction_roundDebitCredit to be called on generated invoices.

This should fix testAccountingRules



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@13897 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 25a3ba5c
...@@ -70,42 +70,31 @@ ...@@ -70,42 +70,31 @@
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[ <value> <string encoding="cdata"><![CDATA[
""" Rounds debit and credit lines on generated transactions, according to \n
precision of this transaction\'s resource.\n
"""\n """\n
This script no longer round debit & credit but only check consistency in a generated\n precision = context.getQuantityPrecisionFromResource(context.getResource())\n
accounting transaction, because now we want rouding problems fixed.\n resource = context.getResourceValue()\n
"""\n
\n
precision = context.Base_getPreferredPrecision()\n
r_ = lambda x: context.Base_getRoundValue(x, precision)\n
\n \n
line = None\n line = None\n
net_balance = 0.0\n total_quantity = 0.0\n
debit_balance = 0.0\n
credit_balance = 0.0\n
\n \n
line_list = context.getMovementList(portal_type=context.getPortalAccountingMovementTypeList())\n line_list = context.getMovementList(\n
portal_type=context.getPortalAccountingMovementTypeList())\n
\n \n
for line in line_list:\n for line in line_list:\n
line_quantity = r_(line.getQuantity())\n line_quantity = round(line.getQuantity(), precision)\n
# Auto remove empty lines\n line.setQuantity(line_quantity)\n
if line_quantity == 0.0: \n total_quantity += line_quantity\n
context.deleteContent(line.getId())\n \n
# Proceed to next line\n # total_quantity should be 0, or we created a transaction where debit != credit\n
continue\n if abs(round(total_quantity, precision)) > 2 * resource.getBaseUnitQuantity():\n
line.setQuantity(line_quantity) \n raise ValueError, \'debit != credit for %s => %s\' % (\n
if line.getSourceDebit() > 0:\n context.getPath(), total_quantity)\n
line.setSourceDebit(r_(line.getSourceDebit()))\n
debit_balance = r_(debit_balance + r_(line_quantity))\n
else:\n
line.setSourceCredit(r_(line.getSourceCredit()))\n
credit_balance = r_(credit_balance + r_(line_quantity))\n
net_balance = r_(net_balance + r_(line_quantity))\n
\n \n
# Check if the debit is equal to the credit\n # if the difference is <= the base quantity unit, we round the last line\n
if abs(net_balance) > 0 or \\\n if line is not None:\n
abs(credit_balance + debit_balance) > 0:\n line.setQuantity(round(line.getQuantity() - total_quantity, precision))\n
# raise ValueError, "Debit differ to Credit (%s != %s => diff: %s) for %s " % (debit_balance, credit_balance, net_balance, context.getPath())\n
context.log(\'ValueError\', "Debit differ to Credit (%s != %s => diff: %s) for %s " % (debit_balance, credit_balance, net_balance, context.getPath()))\n
]]></string> </value> ]]></string> </value>
...@@ -159,16 +148,16 @@ if abs(net_balance) > 0 or \\\n ...@@ -159,16 +148,16 @@ if abs(net_balance) > 0 or \\\n
<string>_getattr_</string> <string>_getattr_</string>
<string>context</string> <string>context</string>
<string>precision</string> <string>precision</string>
<string>r_</string> <string>resource</string>
<string>None</string> <string>None</string>
<string>line</string> <string>line</string>
<string>net_balance</string> <string>total_quantity</string>
<string>debit_balance</string>
<string>credit_balance</string>
<string>line_list</string> <string>line_list</string>
<string>_getiter_</string> <string>_getiter_</string>
<string>round</string>
<string>line_quantity</string> <string>line_quantity</string>
<string>abs</string> <string>abs</string>
<string>ValueError</string>
</tuple> </tuple>
</value> </value>
</item> </item>
......
...@@ -95,7 +95,7 @@ for line in sale_invoice.objectValues() :\n ...@@ -95,7 +95,7 @@ for line in sale_invoice.objectValues() :\n
continue\n continue\n
else : \n else : \n
resources_keys[line.getResource()] = 1\n resources_keys[line.getResource()] = 1\n
context.log(\'resources_keys\',resources_keys)\n \n
if len(resources_keys.keys()) == 1 :\n if len(resources_keys.keys()) == 1 :\n
# set the resource on the transaction\n # set the resource on the transaction\n
sale_invoice.setResource(resources_keys.keys()[0])\n sale_invoice.setResource(resources_keys.keys()[0])\n
...@@ -110,8 +110,8 @@ else :\n ...@@ -110,8 +110,8 @@ else :\n
raise ValueError, "%s doesn(t have only one resource %s" % (\n raise ValueError, "%s doesn(t have only one resource %s" % (\n
sale_invoice.getPath(), resources_keys.keys())\n sale_invoice.getPath(), resources_keys.keys())\n
\n \n
\n # round debit / credit on created transaction.\n
# vim: syntax=python\n context.AccountingTransaction_roundDebitCredit()\n
</string> </value> </string> </value>
</item> </item>
<item> <item>
......
240 242
\ 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