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: |
469 lines (+142/-100) 4 files modified
account_invoice_cash_discount/account_invoice_cash_discount.py (+41/-28) account_invoice_cash_discount/wizard/account_pay_invoice.py (+62/-44) account_invoice_cash_discount/wizard/account_pay_invoice_view.xml (+1/-1) account_invoice_cash_discount/wizard/invoice_statement_payment.py (+38/-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+31276@code.launchpad.net |
This proposal supersedes a proposal from 2010-07-29.
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.
- 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 13:16:48 +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 13:16:48 +0000 |
150 | @@ -140,43 +140,42 @@ |
151 | discount_account_id = self._get_account(cr, uid, context=context) |
152 | if discount>0.0: |
153 | for line in invoice.invoice_line: |
154 | - tax_amount = 0.0 |
155 | + total_tax_amount = 0.0 |
156 | + ######## |
157 | line_tax_amount = 0.0 |
158 | - |
159 | 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): |
160 | - line_tax_amount = tax['amount'] |
161 | - |
162 | + line_tax_amount += tax['amount'] |
163 | line_total = line.price_subtotal + line_tax_amount |
164 | invoice_res_amount = invoice.amount_total |
165 | line_ratio = line_total / invoice_res_amount |
166 | + ##################################################### |
167 | + discount_pay = discount * line_ratio |
168 | |
169 | if line.invoice_line_tax_id: |
170 | - 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): |
171 | - tax_amount = tax['amount'] |
172 | - tax_invoice_id = invoice_tax_obj.search(cr,uid,[('invoice_id','=',invoice.id),('name','=',tax['name'])]) |
173 | + for tax_id in line.invoice_line_tax_id: |
174 | + tax_data = tax_obj.browse(cr, uid, tax_id.id, context=context) |
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 | for tax_id in tax_invoice_id: |
180 | tax_value = invoice_tax_obj.browse(cr, uid, tax_id) |
181 | - tax_account_id = tax_value.account_id.id |
182 | base_code_id = tax_value.base_code_id.id |
183 | - |
184 | - if invoice.company_id.currency_id.id<>invoice.currency_id.id: |
185 | - amount = cur_obj.compute(cr, uid, invoice.currency_id.id, invoice.company_id.currency_id.id, tax_amount, context=context) |
186 | - |
187 | - discount_pay = discount * line_ratio |
188 | + |
189 | if invoice.company_id.currency_id.id<>invoice.currency_id.id: |
190 | - discount_amount = discount - tax_amount |
191 | + discount_amount = discount - tax_real_amt |
192 | amount = cur_obj.compute(cr, uid, invoice.currency_id.id, invoice.company_id.currency_id.id, discount_amount, context=context) |
193 | - |
194 | + |
195 | l4 = { |
196 | - 'debit': direction * (discount_pay - tax_amount)<0 and - direction * (discount_pay - tax_amount), |
197 | - 'credit': direction * (discount_pay - tax_amount)>0 and direction * (discount_pay - tax_amount), |
198 | + 'debit': direction * (discount_pay - total_tax_amount)<0 and - direction * (discount_pay - total_tax_amount), |
199 | + 'credit': direction * (discount_pay - total_tax_amount)>0 and direction * (discount_pay - total_tax_amount), |
200 | 'account_id': discount_account_id, |
201 | 'date': date, |
202 | 'name':name, |
203 | 'currency_id':invoice.currency_id.id or False, |
204 | 'journal_id':invoice.journal_id.id, |
205 | 'tax_code_id':base_code_id, |
206 | - 'tax_amount':tax_amount, |
207 | + 'tax_amount':line.price_unit, |
208 | 'amount_currency':amount and direction * amount or 0.0, |
209 | 'analytic_account_id':line.account_analytic_id.id or False, |
210 | } |
211 | @@ -206,33 +205,47 @@ |
212 | line_ids = [] |
213 | |
214 | tax_code_id = False |
215 | + tax_account_id = False |
216 | discount = self._get_discount(cr, uid, context=context) |
217 | if discount>0.0: |
218 | for line in invoice.invoice_line: |
219 | - tax_amount = 0.0 |
220 | line_tax_amount = 0.0 |
221 | + total_tax_amount = 0.0 |
222 | + ############# Ratio##### |
223 | + 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): |
224 | + line_tax_amount += tax['amount'] |
225 | + line_total = line.price_subtotal + line_tax_amount |
226 | + invoice_res_amount = invoice.amount_total |
227 | + line_ratio = line_total / invoice_res_amount |
228 | + ############# |
229 | + ### discount for the invoice line |
230 | + discount_pay = discount * line_ratio |
231 | + |
232 | if line.invoice_line_tax_id: |
233 | - 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): |
234 | - tax_amount = tax['amount'] |
235 | - tax_invoice_id = invoice_tax_obj.search(cr,uid,[('invoice_id','=',invoice.id),('name','=',tax['name'])]) |
236 | + for tax_id in line.invoice_line_tax_id: |
237 | + tax_data = tax_obj.browse(cr, uid, tax_id.id, context=context) |
238 | + tax_amt = discount_pay * tax_data.amount |
239 | + tax_real_amt = tax_amt / (1 + tax_data.amount) |
240 | + total_tax_amount += tax_real_amt |
241 | + tax_invoice_id = invoice_tax_obj.search(cr,uid,[('invoice_id','=',invoice.id),('name','=',tax_data.name)]) |
242 | for tax_id in tax_invoice_id: |
243 | tax_value = invoice_tax_obj.browse(cr, uid, tax_id) |
244 | tax_account_id = tax_value.account_id.id |
245 | tax_code_id = tax_value.tax_code_id.id |
246 | - |
247 | + |
248 | if invoice.company_id.currency_id.id<>invoice.currency_id.id: |
249 | amount = cur_obj.compute(cr, uid, invoice.currency_id.id, invoice.company_id.currency_id.id, tax_amount, context=context) |
250 | - |
251 | + |
252 | l3 = { |
253 | - 'debit': direction * tax_amount<0 and - direction * tax_amount, |
254 | - 'credit': direction * tax_amount>0 and direction * tax_amount, |
255 | + 'debit': direction * tax_real_amt<0 and - direction * tax_real_amt, |
256 | + 'credit': direction * tax_real_amt>0 and direction * tax_real_amt, |
257 | 'account_id': tax_account_id, |
258 | 'date': date, |
259 | 'journal_id':invoice.journal_id.id or False, |
260 | 'name':name, |
261 | 'currency_id':invoice.currency_id.id or False, |
262 | - 'tax_code_id':tax_value.tax_code_id.id, |
263 | - 'tax_amount':-tax_amount, |
264 | + 'tax_code_id':tax_code_id, |
265 | + 'tax_amount':(discount_pay-tax_real_amt), |
266 | 'amount_currency':amount and direction * amount or 0.0, |
267 | 'analytic_account_id':line.account_analytic_id.id or False, |
268 | } |
269 | @@ -311,22 +324,28 @@ |
270 | discount_account_id = False |
271 | tax_code_id = False |
272 | base_code_id = False |
273 | + tax_account_id = False |
274 | |
275 | for line in invoice.invoice_line: |
276 | tax_amount = 0.0 |
277 | line_tax_amount = 0.0 |
278 | - |
279 | + total_tax_amount = 0.0 |
280 | #####get the ratio of the line in the total invoice amount |
281 | 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): |
282 | - line_tax_amount = tax['amount'] |
283 | + line_tax_amount += tax['amount'] |
284 | line_total = line.price_subtotal + line_tax_amount |
285 | invoice_res_amount = invoice.amount_total |
286 | line_ratio = line_total / invoice_res_amount |
287 | ########################### |
288 | + discount_pay = data['cash_amount'] * line_ratio |
289 | if line.invoice_line_tax_id: |
290 | - 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): |
291 | - tax_amount = tax['amount'] |
292 | - tax_invoice_id = invoice_tax_obj.search(cr,uid,[('invoice_id','=',invoice.id),('name','=',tax['name'])]) |
293 | + for tax_id in line.invoice_line_tax_id: |
294 | + tax_data = tax_obj.browse(cr, uid, tax_id.id, context=context) |
295 | + tax_amt = discount_pay * tax_data.amount |
296 | + tax_real_amt = tax_amt / (1 + tax_data.amount) |
297 | + total_tax_amount += tax_real_amt |
298 | + |
299 | + tax_invoice_id = invoice_tax_obj.search(cr,uid,[('invoice_id','=',invoice.id),('name','=',tax_data.name)]) |
300 | for tax_id in tax_invoice_id: |
301 | tax_value = invoice_tax_obj.browse(cr, uid, tax_id) |
302 | tax_account_id = tax_value.account_id.id |
303 | @@ -337,15 +356,15 @@ |
304 | amount = cur_obj.compute(cr, uid, invoice.currency_id.id, invoice.company_id.currency_id.id, tax_amount, context=context) |
305 | |
306 | l3 = { |
307 | - 'debit': direction * tax_amount<0 and - direction * tax_amount, |
308 | - 'credit': direction * tax_amount>0 and direction * tax_amount, |
309 | + 'debit': direction * tax_real_amt<0 and - direction * tax_real_amt, |
310 | + 'credit': direction * tax_real_amt>0 and direction * tax_real_amt, |
311 | 'account_id': tax_account_id, |
312 | 'date': date, |
313 | 'journal_id':data.get('journal_id',False) , |
314 | 'name':name, |
315 | 'currency_id':invoice.currency_id.id or False, |
316 | - 'tax_code_id':tax_value.tax_code_id.id, |
317 | - 'tax_amount':-tax_amount, |
318 | + 'tax_code_id':tax_code_id, |
319 | + 'tax_amount':(discount_pay-tax_real_amt), |
320 | 'amount_currency':amount and direction * amount or 0.0, |
321 | 'analytic_account_id':line.account_analytic_id.id or False, |
322 | } |
323 | @@ -368,21 +387,20 @@ |
324 | else: |
325 | discount_account_id = data['account_id'] |
326 | |
327 | - discount = data['cash_amount'] * line_ratio |
328 | if invoice.company_id.currency_id.id<>invoice.currency_id.id: |
329 | - discount_amount = discount - tax_amount |
330 | + discount_amount = discount_pay - tax_amount |
331 | amount = cur_obj.compute(cr, uid, invoice.currency_id.id, invoice.company_id.currency_id.id, discount_amount, context=context) |
332 | - |
333 | + |
334 | l4 = { |
335 | - 'debit': direction * (discount - tax_amount)<0 and - direction * (discount - tax_amount), |
336 | - 'credit': direction * (discount - tax_amount)>0 and direction * (discount - tax_amount), |
337 | + 'debit': direction * (discount_pay - total_tax_amount)<0 and - direction * (discount_pay - total_tax_amount), |
338 | + 'credit': direction * (discount_pay - total_tax_amount)>0 and direction * (discount_pay - total_tax_amount), |
339 | 'account_id': discount_account_id, |
340 | 'date': date, |
341 | 'name':name, |
342 | 'currency_id':invoice.currency_id.id or False, |
343 | 'journal_id':data.get('journal_id',False), |
344 | 'tax_code_id':base_code_id, |
345 | - 'tax_amount':tax_amount, |
346 | + 'tax_amount':line.price_unit, |
347 | 'amount_currency':amount and direction * amount or 0.0, |
348 | 'analytic_account_id':line.account_analytic_id.id or False, |
349 | } |
350 | @@ -516,7 +534,7 @@ |
351 | debit+=payment.debit |
352 | credit+=payment.credit |
353 | amount_paid+=abs(debit-credit) |
354 | - |
355 | + |
356 | if data['cash_residual_amount'] == 0.0 or self.pool.get('res.currency').is_zero(cr, uid, invoice.company_id.currency_id, |
357 | (amount_paid - inv_amount_company_currency)): |
358 | return self.pay_and_reconcile(cr, uid, ids, context=context) |
359 | |
360 | === modified file 'account_invoice_cash_discount/wizard/account_pay_invoice_view.xml' |
361 | --- account_invoice_cash_discount/wizard/account_pay_invoice_view.xml 2010-07-26 12:24:39 +0000 |
362 | +++ account_invoice_cash_discount/wizard/account_pay_invoice_view.xml 2010-07-29 13:16:48 +0000 |
363 | @@ -76,7 +76,7 @@ |
364 | <field name="model">account.move.line.memory</field> |
365 | <field name="type">tree</field> |
366 | <field name="arch" type="xml"> |
367 | - <tree string="Account Move Line"> |
368 | + <tree string="Account Move Line" editable="bottom"> |
369 | <field name="date"/> |
370 | <field name="name"/> |
371 | <field name="account_id"/> |
372 | |
373 | === modified file 'account_invoice_cash_discount/wizard/invoice_statement_payment.py' |
374 | --- account_invoice_cash_discount/wizard/invoice_statement_payment.py 2010-07-23 11:30:07 +0000 |
375 | +++ account_invoice_cash_discount/wizard/invoice_statement_payment.py 2010-07-29 13:16:48 +0000 |
376 | @@ -138,47 +138,58 @@ |
377 | 'line_ids': [(6, 0, [line.id])] |
378 | }, context=context) |
379 | |
380 | - ######################################### Calculation for discount and taxes###### |
381 | + ######################################### Calculation for discount and taxes###### |
382 | if line.invoice.id: |
383 | |
384 | discount = 0.0 |
385 | account = False |
386 | - tax_total_amount = 0.0 |
387 | - total_discount = 0.0 |
388 | invoice = obj_inv.browse(cursor, user, line.invoice.id, context=context) |
389 | - |
390 | for invoice_line in invoice.invoice_line: |
391 | + line_tax_amount = 0.0 |
392 | + total_tax_amount = 0.0 |
393 | + #####get the ratio of the line in the total invoice amount |
394 | + 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): |
395 | + line_tax_amount += tax['amount'] |
396 | + line_total = invoice_line.price_subtotal + line_tax_amount |
397 | + invoice_res_amount = invoice.amount_total |
398 | + line_ratio = line_total / invoice_res_amount |
399 | + ########################### |
400 | + amount = obj_inv._get_amount(cursor, user, [invoice.id] ,invoice.residual, invoice.payment_term.id, context=context) |
401 | + invoice_amount = amount['amount'] |
402 | + discount = obj_inv._get_payment(cursor, user, [invoice.id] , invoice_amount, invoice.payment_term.id, context=context) |
403 | + account = obj_inv._get_account(cursor, user, [invoice.id] , invoice.residual, invoice.payment_term.id, context=context) |
404 | + |
405 | + ### discount for the invoice line |
406 | + discount_pay = discount * line_ratio |
407 | if invoice_line.invoice_line_tax_id: |
408 | - amount_invoice_line = obj_inv._get_amount(cursor, user, [invoice.id] , invoice_line.price_subtotal, invoice.payment_term.id, context=context) |
409 | - line_amount = amount_invoice_line['amount'] |
410 | - discount = obj_inv._get_payment(cursor, user, [invoice.id] , line_amount, invoice.payment_term.id, context=context) |
411 | - account = obj_inv._get_account(cursor, user, [invoice.id] , invoice.residual, invoice.payment_term.id, context=context) |
412 | - |
413 | - tax_amount = 0.0 |
414 | - 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): |
415 | - tax_amount = tax['amount'] |
416 | - tax_total_amount += tax['amount'] |
417 | - tax_invoice_id = invoice_tax_obj.search(cursor,user,[('invoice_id','=',invoice.id),('name','=',tax['name'])]) |
418 | + tax_real_amt = 0.0 |
419 | + tax_account_id = False |
420 | + for tax_id in invoice_line.invoice_line_tax_id: |
421 | + tax_data = tax_obj.browse(cursor, user, tax_id.id, context=context) |
422 | + tax_amt = discount_pay * tax_data.amount |
423 | + tax_real_amt = tax_amt / (1 + tax_data.amount) |
424 | + total_tax_amount += tax_real_amt |
425 | + |
426 | + tax_invoice_id = invoice_tax_obj.search(cursor, user,[('invoice_id','=',invoice.id),('name','=',tax_data.name)]) |
427 | for tax_id in tax_invoice_id: |
428 | tax_value = invoice_tax_obj.browse(cursor, user, tax_id) |
429 | tax_account_id = tax_value.account_id.id |
430 | - |
431 | - if tax_amount>0: |
432 | + tax_code_id = tax_value.tax_code_id.id |
433 | + if tax_real_amt>0: |
434 | statement_reconcile_line_obj.create(cursor, user, { |
435 | 'name': line.name, |
436 | - 'amount': tax_amount, |
437 | + 'amount': tax_real_amt, |
438 | 'account_id': tax_account_id, |
439 | 'line_id': reconcile_id, |
440 | }, context=context) |
441 | - |
442 | - if discount>0: |
443 | - total_discount += discount |
444 | - statement_reconcile_line_obj.create(cursor, user, { |
445 | - 'name': line.name, |
446 | - 'amount': discount - tax_amount, |
447 | - 'account_id': account, |
448 | - 'line_id': reconcile_id, |
449 | - }, context=context) |
450 | + if discount>0: |
451 | + discount = discount * line_ratio |
452 | + statement_reconcile_line_obj.create(cursor, user, { |
453 | + 'name': line.name, |
454 | + 'amount': discount - total_tax_amount, |
455 | + 'account_id': account, |
456 | + 'line_id': reconcile_id, |
457 | + }, context=context) |
458 | ########################################################################## |
459 | |
460 | if line.journal_id.type == 'sale': |
461 | @@ -190,7 +201,7 @@ |
462 | |
463 | statement_line_obj.create(cursor, user, { |
464 | 'name': line.name or '?', |
465 | - 'amount': amount, |
466 | + 'amount': invoice_amount, |
467 | 'type': type, |
468 | 'partner_id': line.partner_id.id, |
469 | 'account_id': line.account_id.id, |