Commit 31dc6d03 authored by Jérome Perrin's avatar Jérome Perrin

Iterrate on all applied rules to find VAT related simulation movements

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@7103 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 783d255b
......@@ -79,45 +79,48 @@ vat_infos = {\n
}\n
\n
invoice = context\n
accounting_movement_type_list = invoice.getPortalAccountingMovementTypeList()\n
accounting_movement_list = [x.getObject() for x in invoice.searchFolder(portal_type = accounting_movement_type_list)]\n
portal = context.getPortalObject()\n
accounting_movement_type_list =\\\n
portal.getPortalAccountingMovementTypeList()\n
accounting_movement_list = invoice.getMovementList(\n
portal_type=accounting_movement_type_list)\n
\n
# 1) the invoice contains accounting lines.\n
if len(accounting_movement_list) :\n
for movement in accounting_movement_list :\n
account = movement.getSourceValue()\n
if account is None : continue\n
if account.getAccountTypeId() == \'collected_vat\' : \n
#if vat_infos[\'title\'] is not None :\n
# assert account.getTitle() == vat_infos[\'title\'] # TODO\n
#if vat_infos[\'ratio\'] != 0 :\n
# assert 1 # TODO\n
if account.getAccountTypeId() == \'collected_vat\' :\n
vat_infos.setdefault(\'title\', account.getTitle())\n
vat_infos.setdefault(\'ratio\', movement.getQuantity() / (float(invoice.getTotalPrice(portal_type = [\'Invoice Line\', \'Sale Invoice Line\'])) or 1)) # XXX this calls catalog => bad & this does not suport multiple VAT lines either\n
vat_infos.setdefault(\'ratio\', round(movement.getQuantity() /\n
(float(invoice.getTotalPrice(\n
portal_type=portal.getPortalInvoiceMovementTypeList())) or 1),\n
2)) # XXX this calls catalog => bad & this does not suport multiple VAT lines either\n
vat_infos.update( { \'total\': vat_infos[\'total\'] + movement.getQuantity() } )\n
\n
# 2) no accounting lines => we must look in the simulation\n
if not vat_infos.has_key(\'title\') :\n
for invoice_movement in invoice.getMovementList() :\n
for invoice_movement in invoice.getMovementList(portal_type=portal.getPortalInvoiceMovementTypeList() ) :\n
aggregated_simulation_movements = {}\n
for simulation_movement in ( invoice_movement.getDeliveryRelatedValueList(portal_type = \'Simulation Movement\') +\n
invoice_movement.getOrderRelatedValueList(portal_type = \'Simulation Movement\') ):\n
if aggregated_simulation_movements.has_key(simulation_movement.getPath()) : \n
continue \n
for simulation_movement in ( invoice_movement.getDeliveryRelatedValueList(\n
portal_type = \'Simulation Movement\') +\n
invoice_movement.getOrderRelatedValueList(\n
portal_type = \'Simulation Movement\') ):\n
if aggregated_simulation_movements.has_key(\n
simulation_movement.getPath()):\n
continue\n
aggregated_simulation_movements[simulation_movement.getPath()] = 1\n
\n
applied_rule_list = simulation_movement.objectValues()\n
if len (applied_rule_list) == 0 : continue\n
applied_rule = applied_rule_list[0]\n
\n
for applied_rule in simulation_movement.objectValues():\n
# inside we got accounting movements\n
for movement in applied_rule.objectValues() :\n
account = movement.getSourceValue()\n
if account is None : continue\n
if account.getAccountTypeId() == \'collected_vat\' : \n
context.log(\'added simulation movement from\', movement.getPath())\n
if account.getAccountTypeId() == \'collected_vat\':\n
vat_infos.setdefault(\'title\', account.getTitle())\n
vat_infos.setdefault(\'ratio\', movement.getQuantity() / (float(invoice_movement.getTotalPrice()) or 1)) # XXX this does not suport multiple VAT lines \n
vat_infos.setdefault(\'ratio\', round(movement.getQuantity() / \n
(float(invoice_movement.getTotalPrice()) or 1),\n
2)) # XXX this does not suport multiple VAT lines\n
vat_infos.update( { \'total\': vat_infos[\'total\'] + movement.getQuantity() } )\n
\n
vat_infos.setdefault(\'title\', "")\n
......@@ -169,23 +172,21 @@ return vat_infos\n
<string>context</string>
<string>invoice</string>
<string>_getattr_</string>
<string>portal</string>
<string>accounting_movement_type_list</string>
<string>append</string>
<string>$append0</string>
<string>_getiter_</string>
<string>x</string>
<string>accounting_movement_list</string>
<string>len</string>
<string>_getiter_</string>
<string>movement</string>
<string>account</string>
<string>None</string>
<string>round</string>
<string>float</string>
<string>_getitem_</string>
<string>invoice_movement</string>
<string>aggregated_simulation_movements</string>
<string>simulation_movement</string>
<string>_write_</string>
<string>applied_rule_list</string>
<string>applied_rule</string>
</tuple>
</value>
......
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