diff --git a/addons/account/account.py b/addons/account/account.py index 1b618d24cc4..1b7727e9737 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -1232,6 +1232,7 @@ class account_tax(osv.osv): '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"), 'company_id': fields.many2one('res.company', 'Company', required=True), 'description': fields.char('Internal Name',size=32), + 'price_include': fields.boolean('Tax Included in Price', help="Check this is the price you use on the product and invoices is including this tax.") } def name_get(self, cr, uid, ids, context={}): @@ -1254,6 +1255,7 @@ class account_tax(osv.osv): 'applicable_type': lambda *a: 'true', 'type': lambda *a: 'percent', 'amount': lambda *a: 0, + 'price_include': lambda *a: 0, 'active': lambda *a: 1, 'sequence': lambda *a: 1, 'tax_group': lambda *a: 'vat', @@ -1286,11 +1288,8 @@ class account_tax(osv.osv): for tax in taxes: # we compute the amount for the current tax object and append it to the result - if tax.type=='percent': - amount = cur_price_unit * tax.amount - res.append({'id':tax.id, + data = {'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, @@ -1303,47 +1302,21 @@ class account_tax(osv.osv): 'price_unit': cur_price_unit, 'tax_code_id': tax.tax_code_id.id, 'ref_tax_code_id': tax.ref_tax_code_id.id, - }) + } + res.append(data) + if tax.type=='percent': + amount = cur_price_unit * tax.amount + data['amount'] = amount 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, - '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, - 'tax_sign': tax.tax_sign, - 'ref_base_sign': tax.ref_base_sign, - 'ref_tax_sign': tax.ref_tax_sign, - 'price_unit': 1, - 'tax_code_id': tax.tax_code_id.id, - 'ref_tax_code_id': tax.ref_tax_code_id.id,}) + data['amount'] = tax.amount elif tax.type=='code': address = address_id and self.pool.get('res.partner.address').browse(cr, uid, address_id) or None localdict = {'price_unit':cur_price_unit, 'address':address, 'product':product, 'partner':partner} exec tax.python_compute in localdict amount = localdict['result'] - 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, - 'tax_sign': tax.tax_sign, - 'ref_base_sign': tax.ref_base_sign, - 'ref_tax_sign': tax.ref_tax_sign, - 'price_unit': cur_price_unit, - 'tax_code_id': tax.tax_code_id.id, - 'ref_tax_code_id': tax.ref_tax_code_id.id, - }) - amount2 = res[-1]['amount'] + data['amount'] = amount + amount2 = data['amount'] if len(tax.child_ids): if tax.child_depend: del res[-1] @@ -1369,86 +1342,72 @@ class account_tax(osv.osv): r['amount'] *= quantity return res - def _unit_compute_inv(self, cr, uid, taxes, price_unit, address_id=None, product=None, partner=None,tax_parent_tot=0.0): + def _unit_compute_inv(self, cr, uid, taxes, price_unit, address_id=None, product=None, partner=None): taxes = self._applicable(cr, uid, taxes, price_unit, address_id, product, partner) res = [] taxes.reverse() cur_price_unit=price_unit - for tax in taxes: - # we compute the amount for the current tax object and append it to the result + tax_parent_tot = 0.0 + for tax in taxes: + if (tax.type=='percent') and not tax.include_base_amount: + tax_parent_tot+=tax.amount + + for tax in taxes: if tax.type=='percent': - amount = cur_price_unit - (cur_price_unit / (1 + 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, - 'tax_sign': tax.tax_sign, - 'ref_base_sign': tax.ref_base_sign, - 'ref_tax_sign': tax.ref_tax_sign, - 'price_unit': cur_price_unit - amount, - 'tax_code_id': tax.tax_code_id.id, - 'ref_tax_code_id': tax.ref_tax_code_id.id,}) + if tax.include_base_amount: + amount = cur_price_unit - (cur_price_unit / (1 + tax.amount)) + else: + amount = (cur_price_unit / (1 + tax_parent_tot)) * tax.amount 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, - '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, - 'tax_sign': tax.tax_sign, - 'ref_base_sign': tax.ref_base_sign, - 'ref_tax_sign': tax.ref_tax_sign, - 'price_unit': 1, - 'tax_code_id': tax.tax_code_id.id, - 'ref_tax_code_id': tax.ref_tax_code_id.id,}) + amount = tax.amount elif tax.type=='code': address = address_id and self.pool.get('res.partner.address').browse(cr, uid, address_id) or None localdict = {'price_unit':cur_price_unit, 'address':address, 'product':product, 'partner':partner} exec tax.python_compute_inv in localdict amount = localdict['result'] - 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, - 'tax_sign': tax.tax_sign, - 'ref_base_sign': tax.ref_base_sign, - 'ref_tax_sign': tax.ref_tax_sign, - 'price_unit': cur_price_unit - amount, - 'tax_code_id': tax.tax_code_id.id, - 'ref_tax_code_id': tax.ref_tax_code_id.id, - }) - amount2 = res[-1]['amount'] + if tax.include_base_amount: + cur_price_unit -= amount + todo = 0 + else: + todo = 1 + res.append({ + 'id': tax.id, + 'todo': todo, + '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, + 'tax_sign': tax.tax_sign, + 'ref_base_sign': tax.ref_base_sign, + 'ref_tax_sign': tax.ref_tax_sign, + 'price_unit': cur_price_unit, + 'tax_code_id': tax.tax_code_id.id, + 'ref_tax_code_id': tax.ref_tax_code_id.id, + }) if len(tax.child_ids): if tax.child_depend: del res[-1] amount = price_unit - else: - amount = amount2 - for t in tax.child_ids: - parent_tax = self._unit_compute_inv(cr, uid, [t], amount, address_id, product, partner) - res.extend(parent_tax) - if tax.include_base_amount: - cur_price_unit-=amount - taxes.reverse() + + parent_tax = self._unit_compute_inv(cr, uid, tax.child_ids, amount, address_id, product, partner) + res.extend(parent_tax) + + total = 0.0 + for r in res: + if r['todo']: + total += r['amount'] + for r in res: + r['price_unit'] -= total + r['todo'] = 0 return res def compute_inv(self, cr, uid, taxes, price_unit, quantity, address_id=None, product=None, partner=None): diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml index c3053513fde..c73b829f14b 100644 --- a/addons/account/account_view.xml +++ b/addons/account/account_view.xml @@ -557,6 +557,7 @@ + @@ -588,6 +589,7 @@