← Back to team overview

openobject-italia-core-devs team mailing list archive

lp:~openobject-italia-core-devs/openobject-italia/l10n_it_invoice_tax_compute into lp:openobject-italia

 

Lorenzo Battistini - agilebg.com has proposed merging lp:~openobject-italia-core-devs/openobject-italia/l10n_it_invoice_tax_compute into lp:openobject-italia.

Requested reviews:
  OpenERP Italia core devs (openobject-italia-core-devs)

For more details, see:
https://code.launchpad.net/~openobject-italia-core-devs/openobject-italia/l10n_it_invoice_tax_compute/+merge/60069
-- 
https://code.launchpad.net/~openobject-italia-core-devs/openobject-italia/l10n_it_invoice_tax_compute/+merge/60069
Your team OpenERP Italia core devs is requested to review the proposed merge of lp:~openobject-italia-core-devs/openobject-italia/l10n_it_invoice_tax_compute into lp:openobject-italia.
=== added directory 'l10n_it_invoice_tax'
=== added file 'l10n_it_invoice_tax/AUTHORS.txt'
--- l10n_it_invoice_tax/AUTHORS.txt	1970-01-01 00:00:00 +0000
+++ l10n_it_invoice_tax/AUTHORS.txt	2011-05-05 14:33:41 +0000
@@ -0,0 +1,2 @@
+Matteo Grolla <magrolla@xxxxxxxx>
+Marco Marchiori <marcomarkiori@xxxxxxxxx>
\ No newline at end of file

=== added file 'l10n_it_invoice_tax/__init__.py'
--- l10n_it_invoice_tax/__init__.py	1970-01-01 00:00:00 +0000
+++ l10n_it_invoice_tax/__init__.py	2011-05-05 14:33:41 +0000
@@ -0,0 +1,22 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    Copyright (C) 2011 Italian OpenERP Community (<http://www.openerp-italia.com>)                            
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU Affero General Public License for more details.
+#
+#    You should have received a copy of the GNU Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+import invoice

=== added file 'l10n_it_invoice_tax/__openerp__.py'
--- l10n_it_invoice_tax/__openerp__.py	1970-01-01 00:00:00 +0000
+++ l10n_it_invoice_tax/__openerp__.py	2011-05-05 14:33:41 +0000
@@ -0,0 +1,58 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    Copyright (C) 2011 Italian OpenERP Community (<http://www.openerp-italia.com>)                            
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU Affero General Public License for more details.
+#
+#    You should have received a copy of the GNU Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+{
+    'name': 'Italian Localisation - Invoice Tax',
+    'version': '0.1',
+    'category': 'Localisation/Italy',
+    'description': """Italian localization module that covers
+    
+    -Invoice taxes: 
+        legend:
+            TA(l)    TaxAmount for line l
+            TBA(l)   TaxBaseAmount for line l
+            TA(t)    TaxAmount for tax t
+            TBA(t)   TaxBaseAmount for tax t
+            
+        default behaviour: 
+            openerp by default calculates taxes line by line as a function of line tax base amount 
+            and then groups these amounts by tax.
+            TA(l) = f(TBA(l)
+            TA(t) = sum( round( TA(l) ) )    /sum on lines l to which tax t is applied
+        this module behaviour: 
+            In Italy the correct way to compute taxes is to first compute the tax base amount TBA(t) 
+            and the compute TA as a function of TBA(t)
+            TBA(t) = sum( TBA(t) )    /sum on lines l to which tax t is applied
+            TA(t) = f( TBA(t) )
+        the result difference is small but important
+
+    """,
+    'author': 'OpenERP Italian Community',
+    'website': 'http://www.openerp-italia.org',
+    'license': 'AGPL-3',
+    "depends" : ['account', 'account_voucher'],
+    "init_xml" : [],
+    "update_xml" : [],
+    "demo_xml" : [],
+    "active": False,
+    "installable": True
+}
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+

=== added file 'l10n_it_invoice_tax/invoice.py'
--- l10n_it_invoice_tax/invoice.py	1970-01-01 00:00:00 +0000
+++ l10n_it_invoice_tax/invoice.py	2011-05-05 14:33:41 +0000
@@ -0,0 +1,86 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    Copyright (C) 2011 Italian OpenERP Community (<http://www.openerp-italia.com>)                            
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU Affero General Public License for more details.
+#
+#    You should have received a copy of the GNU Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+import time
+from osv import fields, osv
+
+
+class account_invoice_tax(osv.osv):
+    _inherit = "account.invoice.tax"
+    
+    
+    # FIXME calcolare correttamente con tax inlcuded in price
+    # TODO analizzare con tasse complesse che includono child taxes
+    #
+    def compute(self, cr, uid, invoice_id, context=None):
+        tax_grouped = {}
+        tax_obj = self.pool.get('account.tax')
+        cur_obj = self.pool.get('res.currency')
+        inv = self.pool.get('account.invoice').browse(cr, uid, invoice_id, context=context)
+        cur = inv.currency_id
+        company_currency = inv.company_id.currency_id.id
+
+        for line in inv.invoice_line:
+            for tax in tax_obj.compute_all(cr, uid, line.invoice_line_tax_id, (line.price_unit* (1-(line.discount or 0.0)/100.0)), line.quantity, inv.address_invoice_id.id, line.product_id, inv.partner_id)['taxes']:
+                val={}
+                val['invoice_id'] = inv.id
+                val['name'] = tax['name']
+                val['amount'] = tax['amount']
+                val['price'] = (line.price_unit* (1-(line.discount or 0.0)/100.0)) * line.quantity
+                val['manual'] = False
+                val['sequence'] = tax['sequence']
+                val['base'] = tax['price_unit'] * line['quantity']
+                for line_tax in line.invoice_line_tax_id:
+                    if tax["id"] == line_tax.id:
+                        val['tax'] = [line_tax]
+
+                if inv.type in ('out_invoice','in_invoice'):
+                    val['base_code_id'] = tax['base_code_id']
+                    val['tax_code_id'] = tax['tax_code_id']
+                    val['base_amount'] = cur_obj.compute(cr, uid, inv.currency_id.id, company_currency, val['base'] * tax['base_sign'], context={'date': inv.date_invoice or time.strftime('%Y-%m-%d')}, round=False)
+                    val['tax_amount'] = cur_obj.compute(cr, uid, inv.currency_id.id, company_currency, val['amount'] * tax['tax_sign'], context={'date': inv.date_invoice or time.strftime('%Y-%m-%d')}, round=False)
+                    val['account_id'] = tax['account_collected_id'] or line.account_id.id
+                else:
+                    val['base_code_id'] = tax['ref_base_code_id']
+                    val['tax_code_id'] = tax['ref_tax_code_id']
+                    val['base_amount'] = cur_obj.compute(cr, uid, inv.currency_id.id, company_currency, val['base'] * tax['ref_base_sign'], context={'date': inv.date_invoice or time.strftime('%Y-%m-%d')}, round=False)
+                    val['tax_amount'] = cur_obj.compute(cr, uid, inv.currency_id.id, company_currency, val['amount'] * tax['ref_tax_sign'], context={'date': inv.date_invoice or time.strftime('%Y-%m-%d')}, round=False)
+                    val['account_id'] = tax['account_paid_id'] or line.account_id.id
+
+                key = (val['tax_code_id'], val['base_code_id'], val['account_id'])
+                if not key in tax_grouped:
+                    tax_grouped[key] = val
+                else:
+                    tax_grouped[key]['amount'] += val['amount']
+                    tax_grouped[key]['price'] += val['price']
+                    tax_grouped[key]['base'] += val['base']
+                    tax_grouped[key]['base_amount'] += val['base_amount']
+                    tax_grouped[key]['tax_amount'] += val['tax_amount']
+
+        for t in tax_grouped.values():
+            t['price'] = cur_obj.round(cr, uid, cur, t['price'])
+            amount = tax_obj.compute_all(cr, uid, t['tax'], t['price'], 1)["taxes"][0]["amount"] #MG
+            t['amount'] = cur_obj.round(cr, uid, cur, amount)
+            t['base_amount'] = cur_obj.round(cr, uid, cur, t['base_amount'])            
+            t['tax_amount'] = cur_obj.round(cr, uid, cur, t['tax_amount'])      #TODO    anche il tax amount deve essere calcolato correttamente, dove viene usato?
+        return tax_grouped
+    
+account_invoice_tax()    
+

=== added directory 'l10n_it_invoice_tax/tests'
=== added file 'l10n_it_invoice_tax/tests/tests.txt'
--- l10n_it_invoice_tax/tests/tests.txt	1970-01-01 00:00:00 +0000
+++ l10n_it_invoice_tax/tests/tests.txt	2011-05-05 14:33:41 +0000
@@ -0,0 +1,107 @@
+Manual tests on tax calculation (should write automated tests)
+
+1) arrotondamento IVA ordinaria 20%
+fattura   VENDJ/2011/016  
+IVA20   12,29   2,46
+IVA20   12,29   2,46
+IVA20   12,29   2,46
+IVA10   
+  
+IVA10   
+  
+IVA10   
+  
+IVA10   
+  
+IVA10   
+  
+IVA10   
+  
+IVA10   
+  
+IVA10   
+  
+IVA10   
+  
+somma   36,87   7,38
+
+  
+  
+IVA10   0   0
+IVA20   36,87   7,37
+
+  
+  
+
+  36,87   7,37
+L'IVA corretta è 7,37, e cioè il 20% del totale imponibile al 20%
+
+2) arrotondamento IVA ordinaria e agevolata 4%
+fattura   VENDJ/2011/018  
+IVA4  12,33   0,49
+IVA20   12,29   2,46
+IVA20   12,29   2,46
+IVA20   12,29   2,46
+IVA4  12,33   0,49
+IVA4  12,33   0,49
+IVA20   12,29   2,46
+IVA20   12,29   2,46
+IVA20   12,29   2,46
+IVA20   
+  
+IVA20   
+  
+IVA20   
+  
+
+  
+  
+somma   110,73  16,23
+
+  
+  
+IVA4  36,99   1,48
+IVA20   73,74   14,75
+
+  
+  
+TOTALE IVA  110,73  16,23
+
+l'IVA viene correttamente ripartita fra IVA 4 ed IVA 20
+
+arrotondamento IVA ordinaria 20% ed agevolata 10%
+
+fattura   VENDJ/2011/019  
+IVA20   12,29   2,46
+IVA20   12,29   2,46
+IVA20   12,29   2,46
+IVA10   10,56   1,06
+IVA10   10,56   1,06
+IVA10   10,56   1,06
+IVA10   
+  
+IVA10   
+  
+IVA10   
+  
+IVA10   
+  
+IVA10   
+  
+IVA10   
+  
+
+  
+  
+somma   68,55   10,56
+
+  
+  
+IVA10   31,68   3,17
+IVA20   36,87   7,37
+
+  
+  
+TOTALE IVA  68,55   10,54
+
+L'IVA viene correttamente calcolata ed indicata secondo le aliquote


Follow ups