Merge lp:~openerp-dev/openobject-addons/5.0-opw-18126-ado into lp:openobject-addons/5.0

Proposed by Amit Dodiya (OpenERP)
Status: Needs review
Proposed branch: lp:~openerp-dev/openobject-addons/5.0-opw-18126-ado
Merge into: lp:openobject-addons/5.0
Diff against target: 141 lines (+51/-12)
4 files modified
account/account.py (+34/-1)
account/invoice.py (+6/-4)
purchase/purchase.py (+5/-3)
sale/sale.py (+6/-4)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/5.0-opw-18126-ado
Reviewer Review Type Date Requested Status
Raphael Collet (OpenERP) Pending
Review via email: mp+79252@code.launchpad.net

Description of the change

Hello,

[FIX] Tax included in price is not working : case(18126)

In Sales order / Account Invoice / Purchase Order when making tax calculations, the amount calculation is wrong. It adds the Tax even if we have checked the "taxes included in the price" in Taxes card.

Thanks,
Amit

To post a comment you must log in.
2927. By Raphael Collet (OpenERP)

[MERGE] opw 17578

2928. By nel

[FIX] when invoic

2929. By nel

[Revert]

2930. By Amit Dodiya (OpenERP)

[FIX] Tax included in price is not working

Unmerged revisions

2930. By Amit Dodiya (OpenERP)

[FIX] Tax included in price is not working

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account/account.py'
2--- account/account.py 2011-09-22 12:00:02 +0000
3+++ account/account.py 2011-11-15 09:32:34 +0000
4@@ -1585,6 +1585,39 @@
5 cur_price_unit+=amount2
6 return res
7
8+ def compute_all(self, cr, uid, taxes, price_unit, quantity, address_id=None, product=None, partner=None):
9+ """
10+ RETURN: {
11+ 'total': 0.0, # Total without taxes
12+ 'total_included: 0.0, # Total with taxes
13+ 'taxes': [] # List of taxes, see compute for the format
14+ }
15+ """
16+ totalin = totalex = round(price_unit * quantity, int(config['price_accuracy']))
17+ tin = []
18+ tex = []
19+ for tax in taxes:
20+ if tax.price_include:
21+ tin.append(tax)
22+ else:
23+ tex.append(tax)
24+ tin = self.compute_inv(cr, uid, tin, price_unit, quantity, address_id=address_id, product=product, partner=partner)
25+ for r in tin:
26+ totalex -= r.get('amount', 0.0)
27+ totlex_qty = 0.0
28+ try:
29+ totlex_qty=totalex/quantity
30+ except:
31+ pass
32+ tex = self.compute(cr, uid, tex, totlex_qty, quantity, address_id=address_id, product=product, partner=partner)
33+ for r in tex:
34+ totalin += r.get('amount', 0.0)
35+ return {
36+ 'total': totalex,
37+ 'total_included': totalin,
38+ 'taxes': tin + tex
39+ }
40+
41 def compute(self, cr, uid, taxes, price_unit, quantity, address_id=None, product=None, partner=None):
42
43 """
44@@ -1635,7 +1668,7 @@
45 elif tax.type=='code':
46 address = address_id and self.pool.get('res.partner.address').browse(cr, uid, address_id) or None
47 localdict = {'price_unit':cur_price_unit, 'address':address, 'product':product, 'partner':partner}
48- exec tax.python_compute_inv in localdict
49+ exec tax.python_compute in localdict
50 amount = localdict['result']
51 elif tax.type=='balance':
52 amount = cur_price_unit - reduce(lambda x,y: y.get('amount',0.0)+x, res, 0.0)
53
54=== modified file 'account/invoice.py'
55--- account/invoice.py 2011-09-08 08:35:21 +0000
56+++ account/invoice.py 2011-11-15 09:32:34 +0000
57@@ -53,8 +53,8 @@
58 }
59 for line in invoice.invoice_line:
60 res[invoice.id]['amount_untaxed'] += line.price_subtotal
61- for line in invoice.tax_line:
62- res[invoice.id]['amount_tax'] += line.amount
63+ for c in self.pool.get('account.tax').compute_all(cr, uid, line.invoice_line_tax_id, line.price_unit, line.quantity, line.product_id)['taxes']:
64+ res[invoice.id]['amount_tax']+= c.get('amount', 0.0)
65 res[invoice.id]['amount_total'] = res[invoice.id]['amount_tax'] + res[invoice.id]['amount_untaxed']
66 return res
67
68@@ -999,11 +999,13 @@
69 def _amount_line(self, cr, uid, ids, prop, unknow_none,unknow_dict):
70 res = {}
71 cur_obj=self.pool.get('res.currency')
72+ tax_obj = self.pool.get('account.tax')
73 for line in self.browse(cr, uid, ids):
74 if line.invoice_id:
75- res[line.id] = line.price_unit * line.quantity * (1-(line.discount or 0.0)/100.0)
76+ price = line.price_unit * line.quantity * (1-(line.discount or 0.0)/100.0)
77 cur = line.invoice_id.currency_id
78- res[line.id] = cur_obj.round(cr, uid, cur, res[line.id])
79+ taxes = tax_obj.compute_all(cr, uid, line.invoice_line_tax_id, price, line.quantity, line.product_id)
80+ res[line.id] = cur_obj.round(cr, uid, cur, taxes['total'])
81 else:
82 res[line.id] = round(line.price_unit * line.quantity * (1-(line.discount or 0.0)/100.0),int(config['price_accuracy']))
83 return res
84
85=== modified file 'purchase/purchase.py'
86--- purchase/purchase.py 2011-09-15 09:04:43 +0000
87+++ purchase/purchase.py 2011-11-15 09:32:34 +0000
88@@ -55,8 +55,8 @@
89 val = val1 = 0.0
90 cur=order.pricelist_id.currency_id
91 for line in order.order_line:
92- for c in self.pool.get('account.tax').compute(cr, uid, line.taxes_id, line.price_unit, line.product_qty, order.partner_address_id.id, line.product_id, order.partner_id):
93- val+= c['amount']
94+ for c in self.pool.get('account.tax').compute_all(cr, uid, line.taxes_id, line.price_unit, line.product_qty, order.partner_address_id.id, line.product_id, order.partner_id)['taxes']:
95+ val+= c.get('amount', 0.0)
96 val1 += line.price_subtotal
97 res[order.id]['amount_tax']=cur_obj.round(cr, uid, cur, val)
98 res[order.id]['amount_untaxed']=cur_obj.round(cr, uid, cur, val1)
99@@ -464,9 +464,11 @@
100 def _amount_line(self, cr, uid, ids, prop, unknow_none,unknow_dict):
101 res = {}
102 cur_obj=self.pool.get('res.currency')
103+ tax_obj = self.pool.get('account.tax')
104 for line in self.browse(cr, uid, ids):
105 cur = line.order_id.pricelist_id.currency_id
106- res[line.id] = cur_obj.round(cr, uid, cur, line.price_unit * line.product_qty)
107+ taxes = tax_obj.compute_all(cr, uid, line.taxes_id, line.price_unit, line.product_qty, line.order_id.partner_address_id.id, line.product_id, line.order_id.partner_id)
108+ res[line.id] = cur_obj.round(cr, uid, cur, taxes['total'])
109 return res
110
111 _columns = {
112
113=== modified file 'sale/sale.py'
114--- sale/sale.py 2011-11-10 16:42:32 +0000
115+++ sale/sale.py 2011-11-15 09:32:34 +0000
116@@ -64,8 +64,8 @@
117
118 def _amount_line_tax(self, cr, uid, line, context={}):
119 val = 0.0
120- for c in self.pool.get('account.tax').compute(cr, uid, line.tax_id, line.price_unit * (1-(line.discount or 0.0)/100.0), line.product_uom_qty, line.order_id.partner_invoice_id.id, line.product_id, line.order_id.partner_id):
121- val += c['amount']
122+ for c in self.pool.get('account.tax').compute_all(cr, uid, line.tax_id, line.price_unit * (1-(line.discount or 0.0)/100.0), line.product_uom_qty, line.order_id.partner_invoice_id.id, line.product_id, line.order_id.partner_id)['taxes']:
123+ val += c.get('amount', 0.0)
124 return val
125
126 def _amount_all(self, cr, uid, ids, field_name, arg, context):
127@@ -767,10 +767,12 @@
128 def _amount_line(self, cr, uid, ids, field_name, arg, context):
129 res = {}
130 cur_obj = self.pool.get('res.currency')
131+ tax_obj = self.pool.get('account.tax')
132 for line in self.browse(cr, uid, ids):
133- res[line.id] = line.price_unit * line.product_uom_qty * (1 - (line.discount or 0.0) / 100.0)
134+ price = line.price_unit * (1 - (line.discount or 0.0) / 100.0)
135+ taxes = tax_obj.compute_all(cr, uid, line.tax_id, price, line.product_uom_qty, line.order_id.partner_invoice_id.id, line.product_id, line.order_id.partner_id)
136 cur = line.order_id.pricelist_id.currency_id
137- res[line.id] = cur_obj.round(cr, uid, cur, res[line.id])
138+ res[line.id] = cur_obj.round(cr, uid, cur, taxes['total'])
139 return res
140
141 def _number_packages(self, cr, uid, ids, field_name, arg, context):