Commit b999b62f authored by Kevin Deldycke's avatar Kevin Deldycke

Don't round debit and credit freely. Just check inconsistencies.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@6697 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent eca39694
...@@ -68,34 +68,35 @@ ...@@ -68,34 +68,35 @@
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[ <value> <string encoding="cdata"><![CDATA[
""" Round debit & credit in a generated accounting transaction """\n """\n
This script no longer round debit & credit but only check consistency in a generated\n
accounting transaction, because now we want rouding problems fixed.\n
"""\n
\n \n
precision = int(context.Section_getCurrencyPrecision(mapping_id=\'source_section\'))\n precision = context.Base_getPreferredPrecision()\n
r_ = lambda x: context.Base_getRoundValue(x, precision)\n
\n \n
debit_list = []\n line = None\n
credit_list = []\n net_balance = 0.0\n
line = None\n debit_balance = 0.0\n
total_quantity = 0\n credit_balance = 0.0\n
\n \n
for line in context.getMovementList(portal_type =\n for line in context.getMovementList(portal_type=context.getPortalAccountingMovementTypeList()):\n
context.getPortalAccountingMovementTypeList()) :\n line_quantity = r_(line.getQuantity())\n
if line.getSourceDebit() > 0 :\n line.setQuantity(line_quantity) \n
# line.setSourceDebit((line.getSourceDebit() * precision) / int(precision))\n if line.getSourceDebit() > 0:\n
line.setSourceDebit( float((\'%.\'+str(precision)+\'f\') % (line.getSourceDebit())) )\n line.setSourceDebit(r_(line.getSourceDebit()))\n
total_quantity += line.getQuantity()\n debit_balance = r_(debit_balance + r_(line_quantity))\n
else :\n else:\n
# line.setSourceCredit((line.getSourceCredit() * precision) / int(precision))\n line.setSourceCredit(r_(line.getSourceCredit()))\n
line.setSourceCredit( float((\'%.\'+str(precision)+\'f\') % (line.getSourceCredit())) )\n credit_balance = r_(credit_balance + r_(line_quantity))\n
total_quantity += line.getQuantity()\n net_balance = r_(net_balance + r_(line_quantity))\n
\n \n
if abs(total_quantity) > 2:\n # Check if the debit is equal to the credit\n
# if the difference is important, then it\'s probably a misconfiguration in the rule\n if abs(net_balance) > 0 or \\\n
# so we have to raise an errror.\n abs(credit_balance + debit_balance) > 0:\n
raise ValueError, \'debit != credit for %s => %s\' % (\n # raise ValueError, "Debit differ to Credit (%s != %s => diff: %s) for %s " % (debit_balance, credit_balance, net_balance, context.getPath())\n
context.getPath(), total_quantity)\n context.log(\'ValueError\', "Debit differ to Credit (%s != %s => diff: %s) for %s " % (debit_balance, credit_balance, net_balance, context.getPath()))\n
\n
if line is not None :\n
line.setQuantity(line.getQuantity() - total_quantity)\n
]]></string> </value> ]]></string> </value>
...@@ -144,20 +145,18 @@ if line is not None :\n ...@@ -144,20 +145,18 @@ if line is not None :\n
<key> <string>co_varnames</string> </key> <key> <string>co_varnames</string> </key>
<value> <value>
<tuple> <tuple>
<string>int</string>
<string>_getattr_</string> <string>_getattr_</string>
<string>context</string> <string>context</string>
<string>precision</string> <string>precision</string>
<string>debit_list</string> <string>r_</string>
<string>credit_list</string>
<string>None</string> <string>None</string>
<string>line</string> <string>line</string>
<string>total_quantity</string> <string>net_balance</string>
<string>debit_balance</string>
<string>credit_balance</string>
<string>_getiter_</string> <string>_getiter_</string>
<string>float</string> <string>line_quantity</string>
<string>str</string>
<string>abs</string> <string>abs</string>
<string>ValueError</string>
</tuple> </tuple>
</value> </value>
</item> </item>
......
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