From 2dea59f722a76e6813696af1b0d2c1644184e135 Mon Sep 17 00:00:00 2001 From: ced <> Date: Thu, 4 Jan 2007 14:43:49 +0000 Subject: [PATCH] ACCOUNT: Add possibilitty to include tax amount in base amount for the computation of the next taxes bzr revid: ced-2131b8cd119da193d24cc3f7fbd82bebb667e858 --- addons/account/account.py | 36 +++++++---- addons/account/account_move_line.py | 18 +++--- addons/account/account_view.xml | 2 + addons/account/invoice.py | 59 ++++++++--------- addons/account/report/invoice.rml | 19 +++--- addons/account_tax_include/account.py | 33 ++++++---- .../account_tax_include/invoice_tax_incl.py | 64 ++++++++++--------- addons/purchase/purchase.py | 5 +- .../purchase_tax_include/purchase_tax_incl.py | 17 ++--- addons/sale/sale.py | 5 +- addons/sale_rebate/sale.py | 9 +-- addons/sale_tax_include/sale_tax_incl.py | 17 ++--- 12 files changed, 155 insertions(+), 129 deletions(-) diff --git a/addons/account/account.py b/addons/account/account.py index 45fc3eb5376..85817d358db 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -826,6 +826,7 @@ class account_tax(osv.osv): 'ref_tax_code_id': fields.many2one('account.tax.code', 'Tax Code', help="Use this code for the VAT declaration."), 'ref_base_sign': fields.float('Base Code Sign', help="Usualy 1 or -1."), 'ref_tax_sign': fields.float('Tax Code Sign', help="Usualy 1 or -1."), + 'include_base_amount': fields.boolean('Include in base amount', help="Indicate if the amount of tax must be included in the base amount for the computation of the next taxes"), } _defaults = { 'python_compute': lambda *a: '''# price_unit\n# address : res.partner.address object or False\n\nresult = price_unit * 0.10''', @@ -839,6 +840,7 @@ class account_tax(osv.osv): 'ref_base_sign': lambda *a: -1, 'tax_sign': lambda *a: 1, 'base_sign': lambda *a: 1, + 'include_base_amount': lambda *a: False, } _order = 'sequence' @@ -854,24 +856,21 @@ class account_tax(osv.osv): res.append(tax) return res - def _unit_compute(self, cr, uid, ids, price_unit, address_id=None): - taxes = self.browse(cr, uid, ids) - return self._unit_compute_br(cr, uid, taxes, price_unit, address_id) - - def _unit_compute_br(self, cr, uid, taxes, price_unit, address_id=None): + def _unit_compute(self, cr, uid, taxes, price_unit, address_id=None): taxes = self._applicable(cr, uid, taxes, price_unit, address_id) res = [] + cur_price_unit=price_unit for tax in taxes: # we compute the amount for the current tax object and append it to the result if tax.type=='percent': - amount = price_unit * tax.amount - res.append({'id':tax.id, 'name':tax.name, 'amount':amount, 'account_collected_id':tax.account_collected_id.id, 'account_paid_id':tax.account_paid_id.id}) + amount = cur_price_unit * tax.amount + res.append({'id':tax.id, 'name':tax.name, 'amount':amount, 'account_collected_id':tax.account_collected_id.id, 'account_paid_id':tax.account_paid_id.id, 'base_code_id': tax.base_code_id.id, 'ref_base_code_id': tax.ref_base_code_id.id, 'sequence': tax.sequence, 'base_sign': tax.base_sign, 'ref_base_sign': tax.ref_base_sign, 'price_unit': cur_price_unit, 'tax_code_id': tax.tax_code_id.id,}) elif tax.type=='fixed': - res.append({'id':tax.id, 'name':tax.name, 'amount':tax.amount, 'account_collected_id':tax.account_collected_id.id, 'account_paid_id':tax.account_paid_id.id}) + res.append({'id':tax.id, 'name':tax.name, 'amount':tax.amount, 'account_collected_id':tax.account_collected_id.id, 'account_paid_id':tax.account_paid_id.id, 'base_code_id': tax.base_code_id.id, 'ref_base_code_id': tax.ref_base_code_id.id, 'sequence': tax.sequence, 'base_sign': tax.base_sign, 'ref_base_sign': tax.ref_base_sign, 'price_unit': 1, 'tax_code_id': tax.tax_code_id.id,}) elif tax.type=='code': address = address_id and self.pool.get('res.partner.address').browse(cr, uid, address_id) or None - localdict = {'price_unit':price_unit, 'address':address} + localdict = {'price_unit':cur_price_unit, 'address':address} exec tax.python_compute in localdict amount = localdict['result'] res.append({ @@ -879,7 +878,14 @@ class account_tax(osv.osv): 'name': tax.name, 'amount': amount, 'account_collected_id': tax.account_collected_id.id, - 'account_paid_id': tax.account_paid_id.id + 'account_paid_id': tax.account_paid_id.id, + 'base_code_id': tax.base_code_id.id, + 'ref_base_code_id': tax.ref_base_code_id.id, + 'sequence': tax.sequence, + 'base_sign': tax.base_sign, + 'ref_base_sign': tax.ref_base_sign, + 'price_unit': cur_price_unit, + 'tax_code_id': tax.tax_code_id.id, }) amount2 = res[-1]['amount'] if len(tax.child_ids): @@ -889,11 +895,13 @@ class account_tax(osv.osv): else: amount = amount2 for t in tax.child_ids: - parent_tax = self._unit_compute_br(cr, uid, [t], amount, address_id) + parent_tax = self._unit_compute(cr, uid, [t], amount, address_id) res.extend(parent_tax) + if tax.include_base_amount: + cur_price_unit+=amount2 return res - def compute(self, cr, uid, ids, price_unit, quantity, address_id=None): + def compute(self, cr, uid, taxes, price_unit, quantity, address_id=None): """ Compute tax values for given PRICE_UNIT, QUANTITY and a buyer/seller ADDRESS_ID. @@ -902,9 +910,9 @@ class account_tax(osv.osv): tax = {'name':'', 'amount':0.0, 'account_collected_id':1, 'account_paid_id':2} one tax for each tax id in IDS and their childs """ - res = self._unit_compute(cr, uid, ids, price_unit, address_id) + res = self._unit_compute(cr, uid, taxes, price_unit, address_id) for r in res: - r['amount'] = round(quantity * r['amount'],2) + r['amount'] *= quantity return res account_tax() diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index 3e053d7b1fe..e02e6680162 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -95,20 +95,18 @@ class account_move_line(osv.osv): data['partner_id'] = partner_id - print taxes for t in taxes: if not taxes[t] and t[0]: s=0 for l in move.line_id: - for tax in l.account_id.tax_ids: - taxes = self.pool.get('account.tax').compute(cr, uid, [tax.id], l.debit or l.credit, 1, False) - key = (l.debit and 'account_paid_id') or 'account_collected_id' - for t2 in taxes: - if (t2[key] == t[0]) and (tax.tax_code_id.id==t[1]): - if l.debit: - s += t2['amount'] - else: - s -= t2['amount'] + taxes = self.pool.get('account.tax').compute(cr, uid, l.account_id.tax_ids, l.debit or l.credit, 1, False) + key = (l.debit and 'account_paid_id') or 'account_collected_id' + for t2 in taxes: + if (t2[key] == t[0]) and (t2['tax_code_id']==t[1]): + if l.debit: + s += t2['amount'] + else: + s -= t2['amount'] data['debit'] = s>0 and s or 0.0 data['credit'] = s<0 and -s or 0.0 diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml index c21e1df901f..4679ebf913a 100644 --- a/addons/account/account_view.xml +++ b/addons/account/account_view.xml @@ -589,7 +589,9 @@ + +