Merge lp:~openbig/bigconsulting/changes_in_mileston into lp:bigconsulting
- changes_in_mileston
- Merge into addons
Proposed by
gpa(OpenERP)
Status: | Superseded |
---|---|
Proposed branch: | lp:~openbig/bigconsulting/changes_in_mileston |
Merge into: | lp:bigconsulting |
Diff against target: |
464 lines (+143/-97) 4 files modified
account_invoice_cash_discount/account_invoice_cash_discount.py (+41/-28) account_invoice_cash_discount/wizard/account_pay_invoice.py (+64/-41) account_invoice_cash_discount/wizard/account_pay_invoice_view.xml (+1/-1) account_invoice_cash_discount/wizard/invoice_statement_payment.py (+37/-27) |
To merge this branch: | bzr merge lp:~openbig/bigconsulting/changes_in_mileston |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
openbig | Pending | ||
Review via email: mp+31269@code.launchpad.net |
This proposal has been superseded by a proposal from 2010-07-29.
Commit message
Description of the change
changes in milestone1 and milestone2 functionality to calculate tax and discount
To post a comment you must log in.
- 61. By gpa(OpenERP)
-
added changes in milestone1
- 62. By gpa(OpenERP)
-
changes in the tax fied bas amount
- 63. By gpa(OpenERP)
-
changes in calculation of ratio
Unmerged revisions
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'account_invoice_cash_discount/account_invoice_cash_discount.py' |
2 | --- account_invoice_cash_discount/account_invoice_cash_discount.py 2010-07-27 14:33:57 +0000 |
3 | +++ account_invoice_cash_discount/account_invoice_cash_discount.py 2010-07-29 11:49:41 +0000 |
4 | @@ -317,24 +317,30 @@ |
5 | if amount_discount>0.0: |
6 | for line in invoice.invoice_line: |
7 | if line.invoice_line_tax_id: |
8 | - for tax in tax_obj.compute(cr, uid, line.invoice_line_tax_id, amount_discount, line.quantity, invoice.address_invoice_id.id, line.product_id, invoice.partner_id): |
9 | - tax_amount = tax['amount'] |
10 | - tax_total_amount += tax['amount'] |
11 | - tax_invoice_id = invoice_tax_obj.search(cr,uid,[('invoice_id','=',invoice.id),('name','=',tax['name'])]) |
12 | + total_tax_amount = 0.0 |
13 | + for tax_id in line.invoice_line_tax_id: |
14 | + tax_data = tax_obj.browse(cr, uid, tax_id.id, context=context) |
15 | + tax_amt = amount_discount * tax_data.amount |
16 | + tax_real_amt = tax_amt / (1 + tax_data.amount) |
17 | + total_tax_amount += tax_real_amt |
18 | + tax_invoice_id = invoice_tax_obj.search(cr,uid,[('invoice_id','=',invoice.id),('name','=',tax_data.name)]) |
19 | + |
20 | for tax_id in tax_invoice_id: |
21 | tax_value = invoice_tax_obj.browse(cr, uid, tax_id) |
22 | tax_account_id = tax_value.account_id.id |
23 | + tax_code_id = tax_value.tax_code_id.id |
24 | + |
25 | l3 = { |
26 | - 'debit': direction * tax_amount<0 and - direction * tax_amount, |
27 | - 'credit': direction * tax_amount>0 and direction * tax_amount, |
28 | + 'debit': direction * tax_real_amt<0 and - direction * tax_real_amt, |
29 | + 'credit': direction * tax_real_amt>0 and direction * tax_real_amt, |
30 | 'account_id': tax_account_id, |
31 | 'partner_id': invoice.partner_id.id, |
32 | 'ref':ref, |
33 | 'date': date, |
34 | 'currency_id':currency_id, |
35 | 'amount_currency':amount_currency and direction * amount_currency or 0.0, |
36 | - 'tax_code_id':tax_value.tax_code_id.id, |
37 | - 'tax_amount':tax_amount, |
38 | + 'tax_code_id':tax_code_id, |
39 | + 'tax_amount':tax_real_amt, |
40 | } |
41 | l3['name'] = name |
42 | lines.append((0, 0, l3)) |
43 | @@ -358,16 +364,12 @@ |
44 | 'tax_amount':move_line_data.tax_amount, |
45 | } |
46 | lines.append((0, 0, l4)) |
47 | - |
48 | else: |
49 | if amount_discount>0: |
50 | account_id = False |
51 | if 'account_id' in context and context['account_id']: |
52 | account_id = context['account_id'] |
53 | -# if tax_total_amount>0: |
54 | -# amount_discount = (amount_discount - tax_total_amount) |
55 | -# else: |
56 | -# amount_discount = amount_discount |
57 | + |
58 | for line in invoice.invoice_line: |
59 | line_tax_amount = 0.0 |
60 | tax_amount = 0.0 |
61 | @@ -379,20 +381,32 @@ |
62 | invoice_res_amount = invoice.amount_total |
63 | line_ratio = line_total / invoice_res_amount |
64 | |
65 | - discount = amount_discount * line_ratio |
66 | - |
67 | - for tax in tax_obj.compute(cr, uid, line.invoice_line_tax_id, amount_discount, line.quantity, invoice.address_invoice_id.id, line.product_id, invoice.partner_id): |
68 | - tax_amount = tax['amount'] |
69 | - |
70 | + discount_ratio = amount_discount * line_ratio |
71 | + total_tax_amount = 0.0 |
72 | + |
73 | + for tax_id in line.invoice_line_tax_id: |
74 | + tax_data = tax_obj.browse(cr, uid, tax_id.id, context=context) |
75 | + tax_amt = discount_ratio * tax_data.amount |
76 | + tax_real_amt = tax_amt / (1 + tax_data.amount) |
77 | + total_tax_amount += tax_real_amt |
78 | + |
79 | + tax_invoice_id = invoice_tax_obj.search(cr,uid,[('invoice_id','=',invoice.id),('name','=',tax_data.name)]) |
80 | + for tax_id in tax_invoice_id: |
81 | + tax_value = invoice_tax_obj.browse(cr, uid, tax_id) |
82 | + tax_account_id = tax_value.account_id.id |
83 | + base_code_id = tax_value.base_code_id.id |
84 | + |
85 | l4 = { |
86 | - 'debit': direction * (discount - tax_amount)<0 and - direction * (discount - tax_amount), |
87 | - 'credit': direction * (discount - tax_amount)>0 and direction * (discount - tax_amount), |
88 | + 'debit': direction * (discount - total_tax_amount)<0 and - direction * (discount - total_tax_amount), |
89 | + 'credit': direction * (discount - total_tax_amount)>0 and direction * (discount - total_tax_amount), |
90 | 'account_id': account_id, |
91 | 'partner_id': invoice.partner_id.id, |
92 | 'ref':ref, |
93 | 'date': date, |
94 | 'currency_id':currency_id, |
95 | 'amount_currency':amount_currency and direction * amount_currency or 0.0, |
96 | + 'tax_code_id':base_code_id, |
97 | + 'tax_amount':line.price_unit, |
98 | } |
99 | l4['name'] = name |
100 | lines.append((0, 0, l4)) |
101 | @@ -530,9 +544,9 @@ |
102 | amount = res_currency_obj.compute(cr, uid, st.currency.id, |
103 | company_currency_id, move.amount, context=context, |
104 | account=acc_cur) |
105 | - if move.reconcile_id and move.reconcile_id.line_new_ids: |
106 | - for newline in move.reconcile_id.line_new_ids: |
107 | - amount += newline.amount |
108 | +# if move.reconcile_id and move.reconcile_id.line_new_ids: |
109 | +# for newline in move.reconcile_id.line_new_ids: |
110 | +# amount += newline.amount |
111 | |
112 | val = { |
113 | 'name': move.name, |
114 | @@ -569,9 +583,10 @@ |
115 | val['amount_currency'] = amount_cur |
116 | |
117 | torec.append(account_move_line_obj.create(cr, uid, val , context=context)) |
118 | - |
119 | + newline_sum = 0.0 |
120 | if move.reconcile_id and move.reconcile_id.line_new_ids: |
121 | for newline in move.reconcile_id.line_new_ids: |
122 | + newline_sum += newline.amount |
123 | account_move_line_obj.create(cr, uid, { |
124 | 'name': newline.name or move.name, |
125 | 'date': move.date, |
126 | @@ -673,8 +688,6 @@ |
127 | 'amount_currency': amount_currency, |
128 | 'currency_id': currency_id, |
129 | }, context=context) |
130 | - else: |
131 | - continue |
132 | |
133 | account_move_line_obj.create(cr, uid, { |
134 | 'name': move.name, |
135 | @@ -683,8 +696,8 @@ |
136 | 'move_id': move_id, |
137 | 'partner_id': ((move.partner_id) and move.partner_id.id) or False, |
138 | 'account_id': account_id, |
139 | - 'credit': ((amount < 0) and -amount) or 0.0, |
140 | - 'debit': ((amount > 0) and amount) or 0.0, |
141 | + 'credit': (((amount-newline_sum) < 0) and -(amount-newline_sum)) or 0.0, |
142 | + 'debit': (((amount-newline_sum) > 0) and (amount-newline_sum)) or 0.0, |
143 | 'statement_id': st.id, |
144 | 'journal_id': st.journal_id.id, |
145 | 'period_id': st.period_id.id, |
146 | |
147 | === modified file 'account_invoice_cash_discount/wizard/account_pay_invoice.py' |
148 | --- account_invoice_cash_discount/wizard/account_pay_invoice.py 2010-07-27 14:33:57 +0000 |
149 | +++ account_invoice_cash_discount/wizard/account_pay_invoice.py 2010-07-29 11:49:41 +0000 |
150 | @@ -142,41 +142,45 @@ |
151 | for line in invoice.invoice_line: |
152 | tax_amount = 0.0 |
153 | line_tax_amount = 0.0 |
154 | - |
155 | + ######## |
156 | + line_tax_amount = 0.0 |
157 | for tax in tax_obj.compute(cr, uid, line.invoice_line_tax_id, line.price_subtotal, line.quantity, invoice.address_invoice_id.id, line.product_id, invoice.partner_id): |
158 | - line_tax_amount = tax['amount'] |
159 | - |
160 | + line_tax_amount += tax['amount'] |
161 | line_total = line.price_subtotal + line_tax_amount |
162 | invoice_res_amount = invoice.amount_total |
163 | line_ratio = line_total / invoice_res_amount |
164 | + ##################################################### |
165 | + discount_pay = discount * line_ratio |
166 | |
167 | if line.invoice_line_tax_id: |
168 | - for tax in tax_obj.compute(cr, uid, line.invoice_line_tax_id, discount, line.quantity, invoice.address_invoice_id.id, line.product_id, invoice.partner_id): |
169 | - tax_amount = tax['amount'] |
170 | - tax_invoice_id = invoice_tax_obj.search(cr,uid,[('invoice_id','=',invoice.id),('name','=',tax['name'])]) |
171 | + total_tax_amount = 0.0 |
172 | + for tax_id in line.invoice_line_tax_id: |
173 | + tax_data = tax_obj.browse(cr, uid, tax_id.id, context=context) |
174 | + |
175 | + tax_amt = discount_pay * tax_data.amount |
176 | + tax_real_amt = tax_amt / (1 + tax_data.amount) |
177 | + total_tax_amount += tax_real_amt |
178 | + tax_invoice_id = invoice_tax_obj.search(cr,uid,[('invoice_id','=',invoice.id),('name','=',tax_data.name)]) |
179 | + |
180 | for tax_id in tax_invoice_id: |
181 | tax_value = invoice_tax_obj.browse(cr, uid, tax_id) |
182 | - tax_account_id = tax_value.account_id.id |
183 | base_code_id = tax_value.base_code_id.id |
184 | - |
185 | - if invoice.company_id.currency_id.id<>invoice.currency_id.id: |
186 | - amount = cur_obj.compute(cr, uid, invoice.currency_id.id, invoice.company_id.currency_id.id, tax_amount, context=context) |
187 | - |
188 | - discount_pay = discount * line_ratio |
189 | + |
190 | + |
191 | if invoice.company_id.currency_id.id<>invoice.currency_id.id: |
192 | - discount_amount = discount - tax_amount |
193 | + discount_amount = discount - tax_real_amt |
194 | amount = cur_obj.compute(cr, uid, invoice.currency_id.id, invoice.company_id.currency_id.id, discount_amount, context=context) |
195 | |
196 | l4 = { |
197 | - 'debit': direction * (discount_pay - tax_amount)<0 and - direction * (discount_pay - tax_amount), |
198 | - 'credit': direction * (discount_pay - tax_amount)>0 and direction * (discount_pay - tax_amount), |
199 | + 'debit': direction * (discount_pay - total_tax_amount)<0 and - direction * (discount_pay - total_tax_amount), |
200 | + 'credit': direction * (discount_pay - total_tax_amount)>0 and direction * (discount_pay - total_tax_amount), |
201 | 'account_id': discount_account_id, |
202 | 'date': date, |
203 | 'name':name, |
204 | 'currency_id':invoice.currency_id.id or False, |
205 | 'journal_id':invoice.journal_id.id, |
206 | 'tax_code_id':base_code_id, |
207 | - 'tax_amount':tax_amount, |
208 | + 'tax_amount':line.price_unit, |
209 | 'amount_currency':amount and direction * amount or 0.0, |
210 | 'analytic_account_id':line.account_analytic_id.id or False, |
211 | } |
212 | @@ -206,33 +210,48 @@ |
213 | line_ids = [] |
214 | |
215 | tax_code_id = False |
216 | + tax_account_id = False |
217 | discount = self._get_discount(cr, uid, context=context) |
218 | if discount>0.0: |
219 | for line in invoice.invoice_line: |
220 | - tax_amount = 0.0 |
221 | line_tax_amount = 0.0 |
222 | + total_tax_amount = 0.0 |
223 | + ############# Ratio##### |
224 | + for tax in tax_obj.compute(cr, uid, line.invoice_line_tax_id, line.price_subtotal, line.quantity, invoice.address_invoice_id.id, line.product_id, invoice.partner_id): |
225 | + line_tax_amount += tax['amount'] |
226 | + line_total = line.price_subtotal + line_tax_amount |
227 | + invoice_res_amount = invoice.amount_total |
228 | + line_ratio = line_total / invoice_res_amount |
229 | + ############# |
230 | + |
231 | + ### discount for the invoice line |
232 | + discount_pay = discount * line_ratio |
233 | + |
234 | if line.invoice_line_tax_id: |
235 | - for tax in tax_obj.compute(cr, uid, line.invoice_line_tax_id, discount, line.quantity, invoice.address_invoice_id.id, line.product_id, invoice.partner_id): |
236 | - tax_amount = tax['amount'] |
237 | - tax_invoice_id = invoice_tax_obj.search(cr,uid,[('invoice_id','=',invoice.id),('name','=',tax['name'])]) |
238 | + for tax_id in line.invoice_line_tax_id: |
239 | + tax_data = tax_obj.browse(cr, uid, tax_id.id, context=context) |
240 | + tax_amt = discount_pay * tax_data.amount |
241 | + tax_real_amt = tax_amt / (1 + tax_data.amount) |
242 | + total_tax_amount += tax_real_amt |
243 | + tax_invoice_id = invoice_tax_obj.search(cr,uid,[('invoice_id','=',invoice.id),('name','=',tax_data.name)]) |
244 | for tax_id in tax_invoice_id: |
245 | tax_value = invoice_tax_obj.browse(cr, uid, tax_id) |
246 | tax_account_id = tax_value.account_id.id |
247 | tax_code_id = tax_value.tax_code_id.id |
248 | - |
249 | + |
250 | if invoice.company_id.currency_id.id<>invoice.currency_id.id: |
251 | amount = cur_obj.compute(cr, uid, invoice.currency_id.id, invoice.company_id.currency_id.id, tax_amount, context=context) |
252 | - |
253 | + |
254 | l3 = { |
255 | - 'debit': direction * tax_amount<0 and - direction * tax_amount, |
256 | - 'credit': direction * tax_amount>0 and direction * tax_amount, |
257 | + 'debit': direction * tax_real_amt<0 and - direction * tax_real_amt, |
258 | + 'credit': direction * tax_real_amt>0 and direction * tax_real_amt, |
259 | 'account_id': tax_account_id, |
260 | 'date': date, |
261 | 'journal_id':invoice.journal_id.id or False, |
262 | 'name':name, |
263 | 'currency_id':invoice.currency_id.id or False, |
264 | - 'tax_code_id':tax_value.tax_code_id.id, |
265 | - 'tax_amount':-tax_amount, |
266 | + 'tax_code_id':tax_code_id, |
267 | + 'tax_amount':discount_pay, |
268 | 'amount_currency':amount and direction * amount or 0.0, |
269 | 'analytic_account_id':line.account_analytic_id.id or False, |
270 | } |
271 | @@ -315,18 +334,23 @@ |
272 | for line in invoice.invoice_line: |
273 | tax_amount = 0.0 |
274 | line_tax_amount = 0.0 |
275 | - |
276 | + total_tax_amount = 0.0 |
277 | #####get the ratio of the line in the total invoice amount |
278 | for tax in tax_obj.compute(cr, uid, line.invoice_line_tax_id, line.price_subtotal, line.quantity, invoice.address_invoice_id.id, line.product_id, invoice.partner_id): |
279 | - line_tax_amount = tax['amount'] |
280 | + line_tax_amount += tax['amount'] |
281 | line_total = line.price_subtotal + line_tax_amount |
282 | invoice_res_amount = invoice.amount_total |
283 | line_ratio = line_total / invoice_res_amount |
284 | ########################### |
285 | + discount_pay = data['cash_amount'] * line_ratio |
286 | if line.invoice_line_tax_id: |
287 | - for tax in tax_obj.compute(cr, uid, line.invoice_line_tax_id, data['cash_amount'], line.quantity, invoice.address_invoice_id.id, line.product_id, invoice.partner_id): |
288 | - tax_amount = tax['amount'] |
289 | - tax_invoice_id = invoice_tax_obj.search(cr,uid,[('invoice_id','=',invoice.id),('name','=',tax['name'])]) |
290 | + for tax_id in line.invoice_line_tax_id: |
291 | + tax_data = tax_obj.browse(cr, uid, tax_id.id, context=context) |
292 | + tax_amt = discount_pay * tax_data.amount |
293 | + tax_real_amt = tax_amt / (1 + tax_data.amount) |
294 | + total_tax_amount += tax_real_amt |
295 | + |
296 | + tax_invoice_id = invoice_tax_obj.search(cr,uid,[('invoice_id','=',invoice.id),('name','=',tax_data.name)]) |
297 | for tax_id in tax_invoice_id: |
298 | tax_value = invoice_tax_obj.browse(cr, uid, tax_id) |
299 | tax_account_id = tax_value.account_id.id |
300 | @@ -337,15 +361,15 @@ |
301 | amount = cur_obj.compute(cr, uid, invoice.currency_id.id, invoice.company_id.currency_id.id, tax_amount, context=context) |
302 | |
303 | l3 = { |
304 | - 'debit': direction * tax_amount<0 and - direction * tax_amount, |
305 | - 'credit': direction * tax_amount>0 and direction * tax_amount, |
306 | + 'debit': direction * tax_real_amt<0 and - direction * tax_real_amt, |
307 | + 'credit': direction * tax_real_amt>0 and direction * tax_real_amt, |
308 | 'account_id': tax_account_id, |
309 | 'date': date, |
310 | 'journal_id':data.get('journal_id',False) , |
311 | 'name':name, |
312 | 'currency_id':invoice.currency_id.id or False, |
313 | 'tax_code_id':tax_value.tax_code_id.id, |
314 | - 'tax_amount':-tax_amount, |
315 | + 'tax_amount':discount_pay, |
316 | 'amount_currency':amount and direction * amount or 0.0, |
317 | 'analytic_account_id':line.account_analytic_id.id or False, |
318 | } |
319 | @@ -368,21 +392,20 @@ |
320 | else: |
321 | discount_account_id = data['account_id'] |
322 | |
323 | - discount = data['cash_amount'] * line_ratio |
324 | if invoice.company_id.currency_id.id<>invoice.currency_id.id: |
325 | - discount_amount = discount - tax_amount |
326 | + discount_amount = discount_pay - tax_amount |
327 | amount = cur_obj.compute(cr, uid, invoice.currency_id.id, invoice.company_id.currency_id.id, discount_amount, context=context) |
328 | - |
329 | + |
330 | l4 = { |
331 | - 'debit': direction * (discount - tax_amount)<0 and - direction * (discount - tax_amount), |
332 | - 'credit': direction * (discount - tax_amount)>0 and direction * (discount - tax_amount), |
333 | + 'debit': direction * (discount_pay - total_tax_amount)<0 and - direction * (discount_pay - total_tax_amount), |
334 | + 'credit': direction * (discount_pay - total_tax_amount)>0 and direction * (discount_pay - total_tax_amount), |
335 | 'account_id': discount_account_id, |
336 | 'date': date, |
337 | 'name':name, |
338 | 'currency_id':invoice.currency_id.id or False, |
339 | 'journal_id':data.get('journal_id',False), |
340 | 'tax_code_id':base_code_id, |
341 | - 'tax_amount':tax_amount, |
342 | + 'tax_amount':line.price_unit, |
343 | 'amount_currency':amount and direction * amount or 0.0, |
344 | 'analytic_account_id':line.account_analytic_id.id or False, |
345 | } |
346 | @@ -516,7 +539,7 @@ |
347 | debit+=payment.debit |
348 | credit+=payment.credit |
349 | amount_paid+=abs(debit-credit) |
350 | - |
351 | + |
352 | if data['cash_residual_amount'] == 0.0 or self.pool.get('res.currency').is_zero(cr, uid, invoice.company_id.currency_id, |
353 | (amount_paid - inv_amount_company_currency)): |
354 | return self.pay_and_reconcile(cr, uid, ids, context=context) |
355 | |
356 | === modified file 'account_invoice_cash_discount/wizard/account_pay_invoice_view.xml' |
357 | --- account_invoice_cash_discount/wizard/account_pay_invoice_view.xml 2010-07-26 12:24:39 +0000 |
358 | +++ account_invoice_cash_discount/wizard/account_pay_invoice_view.xml 2010-07-29 11:49:41 +0000 |
359 | @@ -76,7 +76,7 @@ |
360 | <field name="model">account.move.line.memory</field> |
361 | <field name="type">tree</field> |
362 | <field name="arch" type="xml"> |
363 | - <tree string="Account Move Line"> |
364 | + <tree string="Account Move Line" editable="bottom"> |
365 | <field name="date"/> |
366 | <field name="name"/> |
367 | <field name="account_id"/> |
368 | |
369 | === modified file 'account_invoice_cash_discount/wizard/invoice_statement_payment.py' |
370 | --- account_invoice_cash_discount/wizard/invoice_statement_payment.py 2010-07-23 11:30:07 +0000 |
371 | +++ account_invoice_cash_discount/wizard/invoice_statement_payment.py 2010-07-29 11:49:41 +0000 |
372 | @@ -138,47 +138,57 @@ |
373 | 'line_ids': [(6, 0, [line.id])] |
374 | }, context=context) |
375 | |
376 | - ######################################### Calculation for discount and taxes###### |
377 | + ######################################### Calculation for discount and taxes###### |
378 | if line.invoice.id: |
379 | |
380 | discount = 0.0 |
381 | account = False |
382 | - tax_total_amount = 0.0 |
383 | - total_discount = 0.0 |
384 | invoice = obj_inv.browse(cursor, user, line.invoice.id, context=context) |
385 | - |
386 | for invoice_line in invoice.invoice_line: |
387 | + line_tax_amount = 0.0 |
388 | + total_tax_amount = 0.0 |
389 | + #####get the ratio of the line in the total invoice amount |
390 | + for tax in tax_obj.compute(cursor, user, invoice_line.invoice_line_tax_id, invoice_line.price_subtotal, invoice_line.quantity, invoice.address_invoice_id.id, invoice_line.product_id, invoice.partner_id): |
391 | + line_tax_amount += tax['amount'] |
392 | + line_total = invoice_line.price_subtotal + line_tax_amount |
393 | + invoice_res_amount = invoice.amount_total |
394 | + line_ratio = line_total / invoice_res_amount |
395 | + ########################### |
396 | + amount = obj_inv._get_amount(cursor, user, [invoice.id] ,invoice.residual, invoice.payment_term.id, context=context) |
397 | + invoice_amount = amount['amount'] |
398 | + discount = obj_inv._get_payment(cursor, user, [invoice.id] , invoice_amount, invoice.payment_term.id, context=context) |
399 | + account = obj_inv._get_account(cursor, user, [invoice.id] , invoice.residual, invoice.payment_term.id, context=context) |
400 | + |
401 | + ### discount for the invoice line |
402 | + discount_pay = discount * line_ratio |
403 | if invoice_line.invoice_line_tax_id: |
404 | - amount_invoice_line = obj_inv._get_amount(cursor, user, [invoice.id] , invoice_line.price_subtotal, invoice.payment_term.id, context=context) |
405 | - line_amount = amount_invoice_line['amount'] |
406 | - discount = obj_inv._get_payment(cursor, user, [invoice.id] , line_amount, invoice.payment_term.id, context=context) |
407 | - account = obj_inv._get_account(cursor, user, [invoice.id] , invoice.residual, invoice.payment_term.id, context=context) |
408 | - |
409 | - tax_amount = 0.0 |
410 | - for tax in tax_obj.compute(cursor, user, invoice_line.invoice_line_tax_id, discount, invoice_line.quantity, invoice.address_invoice_id.id, invoice_line.product_id, invoice.partner_id): |
411 | - tax_amount = tax['amount'] |
412 | - tax_total_amount += tax['amount'] |
413 | - tax_invoice_id = invoice_tax_obj.search(cursor,user,[('invoice_id','=',invoice.id),('name','=',tax['name'])]) |
414 | + tax_real_amt = 0.0 |
415 | + for tax_id in invoice_line.invoice_line_tax_id: |
416 | + tax_data = tax_obj.browse(cursor, user, tax_id.id, context=context) |
417 | + tax_amt = discount_pay * tax_data.amount |
418 | + tax_real_amt = tax_amt / (1 + tax_data.amount) |
419 | + total_tax_amount += tax_real_amt |
420 | + |
421 | + tax_invoice_id = invoice_tax_obj.search(cursor, user,[('invoice_id','=',invoice.id),('name','=',tax_data.name)]) |
422 | for tax_id in tax_invoice_id: |
423 | tax_value = invoice_tax_obj.browse(cursor, user, tax_id) |
424 | tax_account_id = tax_value.account_id.id |
425 | - |
426 | - if tax_amount>0: |
427 | + |
428 | + if tax_real_amt>0: |
429 | statement_reconcile_line_obj.create(cursor, user, { |
430 | 'name': line.name, |
431 | - 'amount': tax_amount, |
432 | + 'amount': tax_real_amt, |
433 | 'account_id': tax_account_id, |
434 | 'line_id': reconcile_id, |
435 | }, context=context) |
436 | - |
437 | - if discount>0: |
438 | - total_discount += discount |
439 | - statement_reconcile_line_obj.create(cursor, user, { |
440 | - 'name': line.name, |
441 | - 'amount': discount - tax_amount, |
442 | - 'account_id': account, |
443 | - 'line_id': reconcile_id, |
444 | - }, context=context) |
445 | + if discount>0: |
446 | + discount = discount * line_ratio |
447 | + statement_reconcile_line_obj.create(cursor, user, { |
448 | + 'name': line.name, |
449 | + 'amount': discount - total_tax_amount, |
450 | + 'account_id': account, |
451 | + 'line_id': reconcile_id, |
452 | + }, context=context) |
453 | ########################################################################## |
454 | |
455 | if line.journal_id.type == 'sale': |
456 | @@ -190,7 +200,7 @@ |
457 | |
458 | statement_line_obj.create(cursor, user, { |
459 | 'name': line.name or '?', |
460 | - 'amount': amount, |
461 | + 'amount': invoice_amount, |
462 | 'type': type, |
463 | 'partner_id': line.partner_id.id, |
464 | 'account_id': line.account_id.id, |