[Erp5-report] r7713 - /erp5/trunk/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_ac...
nobody at svn.erp5.org
nobody at svn.erp5.org
Wed Jun 14 10:17:24 CEST 2006
Author: jerome
Date: Wed Jun 14 10:17:17 2006
New Revision: 7713
URL: http://svn.erp5.org?rev=7713&view=rev
Log:
fix some problems when having lines from the same resource
Modified:
erp5/trunk/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/SaleInvoiceTransaction_getVAT.xml
Modified: erp5/trunk/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/SaleInvoiceTransaction_getVAT.xml
URL: http://svn.erp5.org/erp5/trunk/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/SaleInvoiceTransaction_getVAT.xml?rev=7713&r1=7712&r2=7713&view=diff
==============================================================================
--- erp5/trunk/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/SaleInvoiceTransaction_getVAT.xml (original)
+++ erp5/trunk/bt5/erp5_accounting/SkinTemplateItem/portal_skins/erp5_accounting/SaleInvoiceTransaction_getVAT.xml Wed Jun 14 10:17:17 2006
@@ -70,10 +70,23 @@
<key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
-""" Calculates the VAT for this invoice. \n
-FIXME: it should support :\n
- o multiple VAT lines (with differents ratio)\n
- o other taxes that VAT\n
+"""Calculates the VAT for this invoice, returning a dict with keys:\n
+\n
+ * total: The amount of VAT\n
+ * ratio: The ratio of the VAT\n
+ * title: The title of this VAT, actually this is the title of the\n
+ account used in the invoice transaction rule.\n
+\n
+This scripts first look in the accounting lines related to this invoice, and\n
+uses the sum of all accounts of type collected_vat. If nothing is found, it\n
+will look in the simulation tree to find all movements which uses a\n
+collected_vat account as source.\n
+\n
+TODO: It\'s now clear that this script now needs a complete rewrite, because it\n
+doesn\'t support different VAT rates for different lines and retrieving the VAT\n
+rate associated with an invoice line.\n
+\n
+This API will probably change.\n
"""\n
\n
vat_infos = {\n
@@ -82,27 +95,26 @@
\n
invoice = context\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
+ portal_type=portal.getPortalAccountingMovementTypeList())\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 len(accounting_movement_list):\n
+ for movement in accounting_movement_list:\n
+ account = movement.getSourceValue(portal_type=\'Account\')\n
if account is None : continue\n
if account.getAccountTypeId() == \'collected_vat\' :\n
vat_infos.setdefault(\'title\', account.getTitle())\n
- vat_infos.setdefault(\'ratio\', round(movement.getQuantity() /\n
+ vat_infos.update({\'total\': vat_infos[\'total\'] + movement.getQuantity()})\n
+ vat_infos[\'ratio\'] = vat_infos[\'total\'] /\\\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
+ portal_type=portal.getPortalInvoiceMovementTypeList(),\n
+ fast=0)) or 1)\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(portal_type=portal.getPortalInvoiceMovementTypeList() ) :\n
+ for invoice_movement in invoice.getMovementList(\n
+ portal_type=portal.getPortalInvoiceMovementTypeList() ) :\n
aggregated_simulation_movements = {}\n
for simulation_movement in ( invoice_movement.getDeliveryRelatedValueList(\n
portal_type = \'Simulation Movement\') +\n
@@ -116,15 +128,18 @@
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
+ account = movement.getSourceValue(portal_type=\'Account\')\n
if account is None : continue\n
if account.getAccountTypeId() == \'collected_vat\':\n
vat_infos.setdefault(\'title\', account.getTitle())\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.update( { \'total\':\n
+ vat_infos[\'total\'] + movement.getQuantity() } )\n
+ \n
+ vat_infos[\'ratio\'] = vat_infos[\'total\'] /\\\n
+ (float(invoice.getTotalPrice(\n
+ portal_type=portal.getPortalInvoiceMovementTypeList(),\n
+ fast=0)) or 1)\n
+ \n
vat_infos.setdefault(\'title\', "")\n
vat_infos.setdefault(\'ratio\', 0)\n
return vat_infos\n
@@ -175,20 +190,18 @@
<string>invoice</string>
<string>_getattr_</string>
<string>portal</string>
- <string>accounting_movement_type_list</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>_getitem_</string>
<string>float</string>
- <string>_getitem_</string>
+ <string>_write_</string>
<string>invoice_movement</string>
<string>aggregated_simulation_movements</string>
<string>simulation_movement</string>
- <string>_write_</string>
<string>applied_rule</string>
</tuple>
</value>
More information about the Erp5-report
mailing list