Merge lp:~openbig/bigconsulting/changes_in_mileston into lp:bigconsulting
- changes_in_mileston
- Merge into addons
Proposed by
gpa(OpenERP)
Status: | Merged |
---|---|
Merged at revision: | 57 |
Proposed branch: | lp:~openbig/bigconsulting/changes_in_mileston |
Merge into: | lp:bigconsulting |
Diff against target: |
475 lines (+144/-102) 4 files modified
account_invoice_cash_discount/account_invoice_cash_discount.py (+42/-29) account_invoice_cash_discount/wizard/account_pay_invoice.py (+63/-45) 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+31285@code.launchpad.net |
This proposal supersedes 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.
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:50:59 +0000 | |||
4 | @@ -317,24 +317,30 @@ | |||
5 | 317 | if amount_discount>0.0: | 317 | if amount_discount>0.0: |
6 | 318 | for line in invoice.invoice_line: | 318 | for line in invoice.invoice_line: |
7 | 319 | if line.invoice_line_tax_id: | 319 | if line.invoice_line_tax_id: |
12 | 320 | 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): | 320 | total_tax_amount = 0.0 |
13 | 321 | tax_amount = tax['amount'] | 321 | for tax_id in line.invoice_line_tax_id: |
14 | 322 | tax_total_amount += tax['amount'] | 322 | tax_data = tax_obj.browse(cr, uid, tax_id.id, context=context) |
15 | 323 | tax_invoice_id = invoice_tax_obj.search(cr,uid,[('invoice_id','=',invoice.id),('name','=',tax['name'])]) | 323 | tax_amt = amount_discount * tax_data.amount |
16 | 324 | tax_real_amt = tax_amt / (1 + tax_data.amount) | ||
17 | 325 | total_tax_amount += tax_real_amt | ||
18 | 326 | tax_invoice_id = invoice_tax_obj.search(cr,uid,[('invoice_id','=',invoice.id),('name','=',tax_data.name)]) | ||
19 | 327 | |||
20 | 324 | for tax_id in tax_invoice_id: | 328 | for tax_id in tax_invoice_id: |
21 | 325 | tax_value = invoice_tax_obj.browse(cr, uid, tax_id) | 329 | tax_value = invoice_tax_obj.browse(cr, uid, tax_id) |
22 | 326 | tax_account_id = tax_value.account_id.id | 330 | tax_account_id = tax_value.account_id.id |
23 | 331 | tax_code_id = tax_value.tax_code_id.id | ||
24 | 332 | |||
25 | 327 | l3 = { | 333 | l3 = { |
28 | 328 | 'debit': direction * tax_amount<0 and - direction * tax_amount, | 334 | 'debit': direction * tax_real_amt<0 and - direction * tax_real_amt, |
29 | 329 | 'credit': direction * tax_amount>0 and direction * tax_amount, | 335 | 'credit': direction * tax_real_amt>0 and direction * tax_real_amt, |
30 | 330 | 'account_id': tax_account_id, | 336 | 'account_id': tax_account_id, |
31 | 331 | 'partner_id': invoice.partner_id.id, | 337 | 'partner_id': invoice.partner_id.id, |
32 | 332 | 'ref':ref, | 338 | 'ref':ref, |
33 | 333 | 'date': date, | 339 | 'date': date, |
34 | 334 | 'currency_id':currency_id, | 340 | 'currency_id':currency_id, |
35 | 335 | 'amount_currency':amount_currency and direction * amount_currency or 0.0, | 341 | 'amount_currency':amount_currency and direction * amount_currency or 0.0, |
38 | 336 | 'tax_code_id':tax_value.tax_code_id.id, | 342 | 'tax_code_id':tax_code_id, |
39 | 337 | 'tax_amount':tax_amount, | 343 | 'tax_amount':tax_real_amt, |
40 | 338 | } | 344 | } |
41 | 339 | l3['name'] = name | 345 | l3['name'] = name |
42 | 340 | lines.append((0, 0, l3)) | 346 | lines.append((0, 0, l3)) |
43 | @@ -358,41 +364,49 @@ | |||
44 | 358 | 'tax_amount':move_line_data.tax_amount, | 364 | 'tax_amount':move_line_data.tax_amount, |
45 | 359 | } | 365 | } |
46 | 360 | lines.append((0, 0, l4)) | 366 | lines.append((0, 0, l4)) |
47 | 361 | |||
48 | 362 | else: | 367 | else: |
49 | 363 | if amount_discount>0: | 368 | if amount_discount>0: |
50 | 364 | account_id = False | 369 | account_id = False |
51 | 365 | if 'account_id' in context and context['account_id']: | 370 | if 'account_id' in context and context['account_id']: |
52 | 366 | account_id = context['account_id'] | 371 | account_id = context['account_id'] |
57 | 367 | # if tax_total_amount>0: | 372 | |
54 | 368 | # amount_discount = (amount_discount - tax_total_amount) | ||
55 | 369 | # else: | ||
56 | 370 | # amount_discount = amount_discount | ||
58 | 371 | for line in invoice.invoice_line: | 373 | for line in invoice.invoice_line: |
59 | 372 | line_tax_amount = 0.0 | 374 | line_tax_amount = 0.0 |
60 | 373 | tax_amount = 0.0 | 375 | tax_amount = 0.0 |
61 | 374 | discount = 0.0 | 376 | discount = 0.0 |
63 | 375 | 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): | 377 | for tax in tax_obj.compute(cr, uid, line.invoice_line_tax_id, line.price_subtotal/line.quantity, line.quantity, invoice.address_invoice_id.id, line.product_id, invoice.partner_id): |
64 | 376 | line_tax_amount = tax['amount'] | 378 | line_tax_amount = tax['amount'] |
65 | 377 | 379 | ||
66 | 378 | line_total = line.price_subtotal + line_tax_amount | 380 | line_total = line.price_subtotal + line_tax_amount |
67 | 379 | invoice_res_amount = invoice.amount_total | 381 | invoice_res_amount = invoice.amount_total |
68 | 380 | line_ratio = line_total / invoice_res_amount | 382 | line_ratio = line_total / invoice_res_amount |
69 | 381 | 383 | ||
75 | 382 | discount = amount_discount * line_ratio | 384 | discount_ratio = amount_discount * line_ratio |
76 | 383 | 385 | total_tax_amount = 0.0 | |
77 | 384 | 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): | 386 | |
78 | 385 | tax_amount = tax['amount'] | 387 | for tax_id in line.invoice_line_tax_id: |
79 | 386 | 388 | tax_data = tax_obj.browse(cr, uid, tax_id.id, context=context) | |
80 | 389 | tax_amt = discount_ratio * tax_data.amount | ||
81 | 390 | tax_real_amt = tax_amt / (1 + tax_data.amount) | ||
82 | 391 | total_tax_amount += tax_real_amt | ||
83 | 392 | |||
84 | 393 | tax_invoice_id = invoice_tax_obj.search(cr,uid,[('invoice_id','=',invoice.id),('name','=',tax_data.name)]) | ||
85 | 394 | for tax_id in tax_invoice_id: | ||
86 | 395 | tax_value = invoice_tax_obj.browse(cr, uid, tax_id) | ||
87 | 396 | tax_account_id = tax_value.account_id.id | ||
88 | 397 | base_code_id = tax_value.base_code_id.id | ||
89 | 398 | |||
90 | 387 | l4 = { | 399 | l4 = { |
93 | 388 | 'debit': direction * (discount - tax_amount)<0 and - direction * (discount - tax_amount), | 400 | 'debit': direction * (discount - total_tax_amount)<0 and - direction * (discount - total_tax_amount), |
94 | 389 | 'credit': direction * (discount - tax_amount)>0 and direction * (discount - tax_amount), | 401 | 'credit': direction * (discount - total_tax_amount)>0 and direction * (discount - total_tax_amount), |
95 | 390 | 'account_id': account_id, | 402 | 'account_id': account_id, |
96 | 391 | 'partner_id': invoice.partner_id.id, | 403 | 'partner_id': invoice.partner_id.id, |
97 | 392 | 'ref':ref, | 404 | 'ref':ref, |
98 | 393 | 'date': date, | 405 | 'date': date, |
99 | 394 | 'currency_id':currency_id, | 406 | 'currency_id':currency_id, |
100 | 395 | 'amount_currency':amount_currency and direction * amount_currency or 0.0, | 407 | 'amount_currency':amount_currency and direction * amount_currency or 0.0, |
101 | 408 | 'tax_code_id':base_code_id, | ||
102 | 409 | 'tax_amount':line.price_unit, | ||
103 | 396 | } | 410 | } |
104 | 397 | l4['name'] = name | 411 | l4['name'] = name |
105 | 398 | lines.append((0, 0, l4)) | 412 | lines.append((0, 0, l4)) |
106 | @@ -530,9 +544,9 @@ | |||
107 | 530 | amount = res_currency_obj.compute(cr, uid, st.currency.id, | 544 | amount = res_currency_obj.compute(cr, uid, st.currency.id, |
108 | 531 | company_currency_id, move.amount, context=context, | 545 | company_currency_id, move.amount, context=context, |
109 | 532 | account=acc_cur) | 546 | account=acc_cur) |
113 | 533 | if move.reconcile_id and move.reconcile_id.line_new_ids: | 547 | # if move.reconcile_id and move.reconcile_id.line_new_ids: |
114 | 534 | for newline in move.reconcile_id.line_new_ids: | 548 | # for newline in move.reconcile_id.line_new_ids: |
115 | 535 | amount += newline.amount | 549 | # amount += newline.amount |
116 | 536 | 550 | ||
117 | 537 | val = { | 551 | val = { |
118 | 538 | 'name': move.name, | 552 | 'name': move.name, |
119 | @@ -569,9 +583,10 @@ | |||
120 | 569 | val['amount_currency'] = amount_cur | 583 | val['amount_currency'] = amount_cur |
121 | 570 | 584 | ||
122 | 571 | torec.append(account_move_line_obj.create(cr, uid, val , context=context)) | 585 | torec.append(account_move_line_obj.create(cr, uid, val , context=context)) |
124 | 572 | 586 | newline_sum = 0.0 | |
125 | 573 | if move.reconcile_id and move.reconcile_id.line_new_ids: | 587 | if move.reconcile_id and move.reconcile_id.line_new_ids: |
126 | 574 | for newline in move.reconcile_id.line_new_ids: | 588 | for newline in move.reconcile_id.line_new_ids: |
127 | 589 | newline_sum += newline.amount | ||
128 | 575 | account_move_line_obj.create(cr, uid, { | 590 | account_move_line_obj.create(cr, uid, { |
129 | 576 | 'name': newline.name or move.name, | 591 | 'name': newline.name or move.name, |
130 | 577 | 'date': move.date, | 592 | 'date': move.date, |
131 | @@ -673,8 +688,6 @@ | |||
132 | 673 | 'amount_currency': amount_currency, | 688 | 'amount_currency': amount_currency, |
133 | 674 | 'currency_id': currency_id, | 689 | 'currency_id': currency_id, |
134 | 675 | }, context=context) | 690 | }, context=context) |
135 | 676 | else: | ||
136 | 677 | continue | ||
137 | 678 | 691 | ||
138 | 679 | account_move_line_obj.create(cr, uid, { | 692 | account_move_line_obj.create(cr, uid, { |
139 | 680 | 'name': move.name, | 693 | 'name': move.name, |
140 | @@ -683,8 +696,8 @@ | |||
141 | 683 | 'move_id': move_id, | 696 | 'move_id': move_id, |
142 | 684 | 'partner_id': ((move.partner_id) and move.partner_id.id) or False, | 697 | 'partner_id': ((move.partner_id) and move.partner_id.id) or False, |
143 | 685 | 'account_id': account_id, | 698 | 'account_id': account_id, |
146 | 686 | 'credit': ((amount < 0) and -amount) or 0.0, | 699 | 'credit': (((amount-newline_sum) < 0) and -(amount-newline_sum)) or 0.0, |
147 | 687 | 'debit': ((amount > 0) and amount) or 0.0, | 700 | 'debit': (((amount-newline_sum) > 0) and (amount-newline_sum)) or 0.0, |
148 | 688 | 'statement_id': st.id, | 701 | 'statement_id': st.id, |
149 | 689 | 'journal_id': st.journal_id.id, | 702 | 'journal_id': st.journal_id.id, |
150 | 690 | 'period_id': st.period_id.id, | 703 | 'period_id': st.period_id.id, |
151 | 691 | 704 | ||
152 | === modified file 'account_invoice_cash_discount/wizard/account_pay_invoice.py' | |||
153 | --- account_invoice_cash_discount/wizard/account_pay_invoice.py 2010-07-27 14:33:57 +0000 | |||
154 | +++ account_invoice_cash_discount/wizard/account_pay_invoice.py 2010-07-29 13:50:59 +0000 | |||
155 | @@ -140,43 +140,42 @@ | |||
156 | 140 | discount_account_id = self._get_account(cr, uid, context=context) | 140 | discount_account_id = self._get_account(cr, uid, context=context) |
157 | 141 | if discount>0.0: | 141 | if discount>0.0: |
158 | 142 | for line in invoice.invoice_line: | 142 | for line in invoice.invoice_line: |
160 | 143 | tax_amount = 0.0 | 143 | total_tax_amount = 0.0 |
161 | 144 | ######## | ||
162 | 144 | line_tax_amount = 0.0 | 145 | line_tax_amount = 0.0 |
167 | 145 | 146 | for tax in tax_obj.compute(cr, uid, line.invoice_line_tax_id, line.price_subtotal/line.quantity, line.quantity, invoice.address_invoice_id.id, line.product_id, invoice.partner_id): | |
168 | 146 | 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): | 147 | line_tax_amount += tax['amount'] |
165 | 147 | line_tax_amount = tax['amount'] | ||
166 | 148 | |||
169 | 149 | line_total = line.price_subtotal + line_tax_amount | 148 | line_total = line.price_subtotal + line_tax_amount |
170 | 150 | invoice_res_amount = invoice.amount_total | 149 | invoice_res_amount = invoice.amount_total |
171 | 151 | line_ratio = line_total / invoice_res_amount | 150 | line_ratio = line_total / invoice_res_amount |
172 | 151 | ##################################################### | ||
173 | 152 | discount_pay = discount * line_ratio | ||
174 | 152 | 153 | ||
175 | 153 | if line.invoice_line_tax_id: | 154 | if line.invoice_line_tax_id: |
179 | 154 | 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): | 155 | for tax_id in line.invoice_line_tax_id: |
180 | 155 | tax_amount = tax['amount'] | 156 | tax_data = tax_obj.browse(cr, uid, tax_id.id, context=context) |
181 | 156 | tax_invoice_id = invoice_tax_obj.search(cr,uid,[('invoice_id','=',invoice.id),('name','=',tax['name'])]) | 157 | tax_amt = discount_pay * tax_data.amount |
182 | 158 | tax_real_amt = tax_amt / (1 + tax_data.amount) | ||
183 | 159 | total_tax_amount += tax_real_amt | ||
184 | 160 | tax_invoice_id = invoice_tax_obj.search(cr,uid,[('invoice_id','=',invoice.id),('name','=',tax_data.name)]) | ||
185 | 157 | for tax_id in tax_invoice_id: | 161 | for tax_id in tax_invoice_id: |
186 | 158 | tax_value = invoice_tax_obj.browse(cr, uid, tax_id) | 162 | tax_value = invoice_tax_obj.browse(cr, uid, tax_id) |
187 | 159 | tax_account_id = tax_value.account_id.id | ||
188 | 160 | base_code_id = tax_value.base_code_id.id | 163 | base_code_id = tax_value.base_code_id.id |
194 | 161 | 164 | ||
190 | 162 | if invoice.company_id.currency_id.id<>invoice.currency_id.id: | ||
191 | 163 | amount = cur_obj.compute(cr, uid, invoice.currency_id.id, invoice.company_id.currency_id.id, tax_amount, context=context) | ||
192 | 164 | |||
193 | 165 | discount_pay = discount * line_ratio | ||
195 | 166 | if invoice.company_id.currency_id.id<>invoice.currency_id.id: | 165 | if invoice.company_id.currency_id.id<>invoice.currency_id.id: |
197 | 167 | discount_amount = discount - tax_amount | 166 | discount_amount = discount - tax_real_amt |
198 | 168 | amount = cur_obj.compute(cr, uid, invoice.currency_id.id, invoice.company_id.currency_id.id, discount_amount, context=context) | 167 | amount = cur_obj.compute(cr, uid, invoice.currency_id.id, invoice.company_id.currency_id.id, discount_amount, context=context) |
200 | 169 | 168 | ||
201 | 170 | l4 = { | 169 | l4 = { |
204 | 171 | 'debit': direction * (discount_pay - tax_amount)<0 and - direction * (discount_pay - tax_amount), | 170 | 'debit': direction * (discount_pay - total_tax_amount)<0 and - direction * (discount_pay - total_tax_amount), |
205 | 172 | 'credit': direction * (discount_pay - tax_amount)>0 and direction * (discount_pay - tax_amount), | 171 | 'credit': direction * (discount_pay - total_tax_amount)>0 and direction * (discount_pay - total_tax_amount), |
206 | 173 | 'account_id': discount_account_id, | 172 | 'account_id': discount_account_id, |
207 | 174 | 'date': date, | 173 | 'date': date, |
208 | 175 | 'name':name, | 174 | 'name':name, |
209 | 176 | 'currency_id':invoice.currency_id.id or False, | 175 | 'currency_id':invoice.currency_id.id or False, |
210 | 177 | 'journal_id':invoice.journal_id.id, | 176 | 'journal_id':invoice.journal_id.id, |
211 | 178 | 'tax_code_id':base_code_id, | 177 | 'tax_code_id':base_code_id, |
213 | 179 | 'tax_amount':tax_amount, | 178 | 'tax_amount':line.price_unit, |
214 | 180 | 'amount_currency':amount and direction * amount or 0.0, | 179 | 'amount_currency':amount and direction * amount or 0.0, |
215 | 181 | 'analytic_account_id':line.account_analytic_id.id or False, | 180 | 'analytic_account_id':line.account_analytic_id.id or False, |
216 | 182 | } | 181 | } |
217 | @@ -206,33 +205,47 @@ | |||
218 | 206 | line_ids = [] | 205 | line_ids = [] |
219 | 207 | 206 | ||
220 | 208 | tax_code_id = False | 207 | tax_code_id = False |
221 | 208 | tax_account_id = False | ||
222 | 209 | discount = self._get_discount(cr, uid, context=context) | 209 | discount = self._get_discount(cr, uid, context=context) |
223 | 210 | if discount>0.0: | 210 | if discount>0.0: |
224 | 211 | for line in invoice.invoice_line: | 211 | for line in invoice.invoice_line: |
225 | 212 | tax_amount = 0.0 | ||
226 | 213 | line_tax_amount = 0.0 | 212 | line_tax_amount = 0.0 |
227 | 213 | total_tax_amount = 0.0 | ||
228 | 214 | ############# Ratio##### | ||
229 | 215 | for tax in tax_obj.compute(cr, uid, line.invoice_line_tax_id, line.price_subtotal/line.quantity, line.quantity, invoice.address_invoice_id.id, line.product_id, invoice.partner_id): | ||
230 | 216 | line_tax_amount += tax['amount'] | ||
231 | 217 | line_total = line.price_subtotal + line_tax_amount | ||
232 | 218 | invoice_res_amount = invoice.amount_total | ||
233 | 219 | line_ratio = line_total / invoice_res_amount | ||
234 | 220 | ############# | ||
235 | 221 | ### discount for the invoice line | ||
236 | 222 | discount_pay = discount * line_ratio | ||
237 | 223 | |||
238 | 214 | if line.invoice_line_tax_id: | 224 | if line.invoice_line_tax_id: |
242 | 215 | 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): | 225 | for tax_id in line.invoice_line_tax_id: |
243 | 216 | tax_amount = tax['amount'] | 226 | tax_data = tax_obj.browse(cr, uid, tax_id.id, context=context) |
244 | 217 | tax_invoice_id = invoice_tax_obj.search(cr,uid,[('invoice_id','=',invoice.id),('name','=',tax['name'])]) | 227 | tax_amt = discount_pay * tax_data.amount |
245 | 228 | tax_real_amt = tax_amt / (1 + tax_data.amount) | ||
246 | 229 | total_tax_amount += tax_real_amt | ||
247 | 230 | tax_invoice_id = invoice_tax_obj.search(cr,uid,[('invoice_id','=',invoice.id),('name','=',tax_data.name)]) | ||
248 | 218 | for tax_id in tax_invoice_id: | 231 | for tax_id in tax_invoice_id: |
249 | 219 | tax_value = invoice_tax_obj.browse(cr, uid, tax_id) | 232 | tax_value = invoice_tax_obj.browse(cr, uid, tax_id) |
250 | 220 | tax_account_id = tax_value.account_id.id | 233 | tax_account_id = tax_value.account_id.id |
251 | 221 | tax_code_id = tax_value.tax_code_id.id | 234 | tax_code_id = tax_value.tax_code_id.id |
253 | 222 | 235 | ||
254 | 223 | if invoice.company_id.currency_id.id<>invoice.currency_id.id: | 236 | if invoice.company_id.currency_id.id<>invoice.currency_id.id: |
255 | 224 | amount = cur_obj.compute(cr, uid, invoice.currency_id.id, invoice.company_id.currency_id.id, tax_amount, context=context) | 237 | amount = cur_obj.compute(cr, uid, invoice.currency_id.id, invoice.company_id.currency_id.id, tax_amount, context=context) |
257 | 225 | 238 | ||
258 | 226 | l3 = { | 239 | l3 = { |
261 | 227 | 'debit': direction * tax_amount<0 and - direction * tax_amount, | 240 | 'debit': direction * tax_real_amt<0 and - direction * tax_real_amt, |
262 | 228 | 'credit': direction * tax_amount>0 and direction * tax_amount, | 241 | 'credit': direction * tax_real_amt>0 and direction * tax_real_amt, |
263 | 229 | 'account_id': tax_account_id, | 242 | 'account_id': tax_account_id, |
264 | 230 | 'date': date, | 243 | 'date': date, |
265 | 231 | 'journal_id':invoice.journal_id.id or False, | 244 | 'journal_id':invoice.journal_id.id or False, |
266 | 232 | 'name':name, | 245 | 'name':name, |
267 | 233 | 'currency_id':invoice.currency_id.id or False, | 246 | 'currency_id':invoice.currency_id.id or False, |
270 | 234 | 'tax_code_id':tax_value.tax_code_id.id, | 247 | 'tax_code_id':tax_code_id, |
271 | 235 | 'tax_amount':-tax_amount, | 248 | 'tax_amount':(discount_pay-tax_real_amt), |
272 | 236 | 'amount_currency':amount and direction * amount or 0.0, | 249 | 'amount_currency':amount and direction * amount or 0.0, |
273 | 237 | 'analytic_account_id':line.account_analytic_id.id or False, | 250 | 'analytic_account_id':line.account_analytic_id.id or False, |
274 | 238 | } | 251 | } |
275 | @@ -311,22 +324,28 @@ | |||
276 | 311 | discount_account_id = False | 324 | discount_account_id = False |
277 | 312 | tax_code_id = False | 325 | tax_code_id = False |
278 | 313 | base_code_id = False | 326 | base_code_id = False |
279 | 327 | tax_account_id = False | ||
280 | 314 | 328 | ||
281 | 315 | for line in invoice.invoice_line: | 329 | for line in invoice.invoice_line: |
282 | 316 | tax_amount = 0.0 | 330 | tax_amount = 0.0 |
283 | 317 | line_tax_amount = 0.0 | 331 | line_tax_amount = 0.0 |
285 | 318 | 332 | total_tax_amount = 0.0 | |
286 | 319 | #####get the ratio of the line in the total invoice amount | 333 | #####get the ratio of the line in the total invoice amount |
288 | 320 | 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): | 334 | for tax in tax_obj.compute(cr, uid, line.invoice_line_tax_id, line.price_subtotal/line.quantity, line.quantity, invoice.address_invoice_id.id, line.product_id, invoice.partner_id): |
289 | 321 | line_tax_amount = tax['amount'] | 335 | line_tax_amount = tax['amount'] |
290 | 322 | line_total = line.price_subtotal + line_tax_amount | 336 | line_total = line.price_subtotal + line_tax_amount |
291 | 323 | invoice_res_amount = invoice.amount_total | 337 | invoice_res_amount = invoice.amount_total |
292 | 324 | line_ratio = line_total / invoice_res_amount | 338 | line_ratio = line_total / invoice_res_amount |
293 | 325 | ########################### | 339 | ########################### |
294 | 340 | discount_pay = data['cash_amount'] * line_ratio | ||
295 | 326 | if line.invoice_line_tax_id: | 341 | if line.invoice_line_tax_id: |
299 | 327 | 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): | 342 | for tax_id in line.invoice_line_tax_id: |
300 | 328 | tax_amount = tax['amount'] | 343 | tax_data = tax_obj.browse(cr, uid, tax_id.id, context=context) |
301 | 329 | tax_invoice_id = invoice_tax_obj.search(cr,uid,[('invoice_id','=',invoice.id),('name','=',tax['name'])]) | 344 | tax_amt = discount_pay * tax_data.amount |
302 | 345 | tax_real_amt = tax_amt / (1 + tax_data.amount) | ||
303 | 346 | total_tax_amount += tax_real_amt | ||
304 | 347 | |||
305 | 348 | tax_invoice_id = invoice_tax_obj.search(cr,uid,[('invoice_id','=',invoice.id),('name','=',tax_data.name)]) | ||
306 | 330 | for tax_id in tax_invoice_id: | 349 | for tax_id in tax_invoice_id: |
307 | 331 | tax_value = invoice_tax_obj.browse(cr, uid, tax_id) | 350 | tax_value = invoice_tax_obj.browse(cr, uid, tax_id) |
308 | 332 | tax_account_id = tax_value.account_id.id | 351 | tax_account_id = tax_value.account_id.id |
309 | @@ -337,15 +356,15 @@ | |||
310 | 337 | amount = cur_obj.compute(cr, uid, invoice.currency_id.id, invoice.company_id.currency_id.id, tax_amount, context=context) | 356 | amount = cur_obj.compute(cr, uid, invoice.currency_id.id, invoice.company_id.currency_id.id, tax_amount, context=context) |
311 | 338 | 357 | ||
312 | 339 | l3 = { | 358 | l3 = { |
315 | 340 | 'debit': direction * tax_amount<0 and - direction * tax_amount, | 359 | 'debit': direction * tax_real_amt<0 and - direction * tax_real_amt, |
316 | 341 | 'credit': direction * tax_amount>0 and direction * tax_amount, | 360 | 'credit': direction * tax_real_amt>0 and direction * tax_real_amt, |
317 | 342 | 'account_id': tax_account_id, | 361 | 'account_id': tax_account_id, |
318 | 343 | 'date': date, | 362 | 'date': date, |
319 | 344 | 'journal_id':data.get('journal_id',False) , | 363 | 'journal_id':data.get('journal_id',False) , |
320 | 345 | 'name':name, | 364 | 'name':name, |
321 | 346 | 'currency_id':invoice.currency_id.id or False, | 365 | 'currency_id':invoice.currency_id.id or False, |
324 | 347 | 'tax_code_id':tax_value.tax_code_id.id, | 366 | 'tax_code_id':tax_code_id, |
325 | 348 | 'tax_amount':-tax_amount, | 367 | 'tax_amount':(discount_pay-tax_real_amt), |
326 | 349 | 'amount_currency':amount and direction * amount or 0.0, | 368 | 'amount_currency':amount and direction * amount or 0.0, |
327 | 350 | 'analytic_account_id':line.account_analytic_id.id or False, | 369 | 'analytic_account_id':line.account_analytic_id.id or False, |
328 | 351 | } | 370 | } |
329 | @@ -368,21 +387,20 @@ | |||
330 | 368 | else: | 387 | else: |
331 | 369 | discount_account_id = data['account_id'] | 388 | discount_account_id = data['account_id'] |
332 | 370 | 389 | ||
333 | 371 | discount = data['cash_amount'] * line_ratio | ||
334 | 372 | if invoice.company_id.currency_id.id<>invoice.currency_id.id: | 390 | if invoice.company_id.currency_id.id<>invoice.currency_id.id: |
336 | 373 | discount_amount = discount - tax_amount | 391 | discount_amount = discount_pay - tax_amount |
337 | 374 | amount = cur_obj.compute(cr, uid, invoice.currency_id.id, invoice.company_id.currency_id.id, discount_amount, context=context) | 392 | amount = cur_obj.compute(cr, uid, invoice.currency_id.id, invoice.company_id.currency_id.id, discount_amount, context=context) |
339 | 375 | 393 | ||
340 | 376 | l4 = { | 394 | l4 = { |
343 | 377 | 'debit': direction * (discount - tax_amount)<0 and - direction * (discount - tax_amount), | 395 | 'debit': direction * (discount_pay - total_tax_amount)<0 and - direction * (discount_pay - total_tax_amount), |
344 | 378 | 'credit': direction * (discount - tax_amount)>0 and direction * (discount - tax_amount), | 396 | 'credit': direction * (discount_pay - total_tax_amount)>0 and direction * (discount_pay - total_tax_amount), |
345 | 379 | 'account_id': discount_account_id, | 397 | 'account_id': discount_account_id, |
346 | 380 | 'date': date, | 398 | 'date': date, |
347 | 381 | 'name':name, | 399 | 'name':name, |
348 | 382 | 'currency_id':invoice.currency_id.id or False, | 400 | 'currency_id':invoice.currency_id.id or False, |
349 | 383 | 'journal_id':data.get('journal_id',False), | 401 | 'journal_id':data.get('journal_id',False), |
350 | 384 | 'tax_code_id':base_code_id, | 402 | 'tax_code_id':base_code_id, |
352 | 385 | 'tax_amount':tax_amount, | 403 | 'tax_amount':line.price_unit, |
353 | 386 | 'amount_currency':amount and direction * amount or 0.0, | 404 | 'amount_currency':amount and direction * amount or 0.0, |
354 | 387 | 'analytic_account_id':line.account_analytic_id.id or False, | 405 | 'analytic_account_id':line.account_analytic_id.id or False, |
355 | 388 | } | 406 | } |
356 | @@ -516,7 +534,7 @@ | |||
357 | 516 | debit+=payment.debit | 534 | debit+=payment.debit |
358 | 517 | credit+=payment.credit | 535 | credit+=payment.credit |
359 | 518 | amount_paid+=abs(debit-credit) | 536 | amount_paid+=abs(debit-credit) |
361 | 519 | 537 | ||
362 | 520 | if data['cash_residual_amount'] == 0.0 or self.pool.get('res.currency').is_zero(cr, uid, invoice.company_id.currency_id, | 538 | if data['cash_residual_amount'] == 0.0 or self.pool.get('res.currency').is_zero(cr, uid, invoice.company_id.currency_id, |
363 | 521 | (amount_paid - inv_amount_company_currency)): | 539 | (amount_paid - inv_amount_company_currency)): |
364 | 522 | return self.pay_and_reconcile(cr, uid, ids, context=context) | 540 | return self.pay_and_reconcile(cr, uid, ids, context=context) |
365 | 523 | 541 | ||
366 | === modified file 'account_invoice_cash_discount/wizard/account_pay_invoice_view.xml' | |||
367 | --- account_invoice_cash_discount/wizard/account_pay_invoice_view.xml 2010-07-26 12:24:39 +0000 | |||
368 | +++ account_invoice_cash_discount/wizard/account_pay_invoice_view.xml 2010-07-29 13:50:59 +0000 | |||
369 | @@ -76,7 +76,7 @@ | |||
370 | 76 | <field name="model">account.move.line.memory</field> | 76 | <field name="model">account.move.line.memory</field> |
371 | 77 | <field name="type">tree</field> | 77 | <field name="type">tree</field> |
372 | 78 | <field name="arch" type="xml"> | 78 | <field name="arch" type="xml"> |
374 | 79 | <tree string="Account Move Line"> | 79 | <tree string="Account Move Line" editable="bottom"> |
375 | 80 | <field name="date"/> | 80 | <field name="date"/> |
376 | 81 | <field name="name"/> | 81 | <field name="name"/> |
377 | 82 | <field name="account_id"/> | 82 | <field name="account_id"/> |
378 | 83 | 83 | ||
379 | === modified file 'account_invoice_cash_discount/wizard/invoice_statement_payment.py' | |||
380 | --- account_invoice_cash_discount/wizard/invoice_statement_payment.py 2010-07-23 11:30:07 +0000 | |||
381 | +++ account_invoice_cash_discount/wizard/invoice_statement_payment.py 2010-07-29 13:50:59 +0000 | |||
382 | @@ -138,47 +138,58 @@ | |||
383 | 138 | 'line_ids': [(6, 0, [line.id])] | 138 | 'line_ids': [(6, 0, [line.id])] |
384 | 139 | }, context=context) | 139 | }, context=context) |
385 | 140 | 140 | ||
387 | 141 | ######################################### Calculation for discount and taxes###### | 141 | ######################################### Calculation for discount and taxes###### |
388 | 142 | if line.invoice.id: | 142 | if line.invoice.id: |
389 | 143 | 143 | ||
390 | 144 | discount = 0.0 | 144 | discount = 0.0 |
391 | 145 | account = False | 145 | account = False |
392 | 146 | tax_total_amount = 0.0 | ||
393 | 147 | total_discount = 0.0 | ||
394 | 148 | invoice = obj_inv.browse(cursor, user, line.invoice.id, context=context) | 146 | invoice = obj_inv.browse(cursor, user, line.invoice.id, context=context) |
395 | 149 | |||
396 | 150 | for invoice_line in invoice.invoice_line: | 147 | for invoice_line in invoice.invoice_line: |
397 | 148 | line_tax_amount = 0.0 | ||
398 | 149 | total_tax_amount = 0.0 | ||
399 | 150 | #####get the ratio of the line in the total invoice amount | ||
400 | 151 | for tax in tax_obj.compute(cursor, user, invoice_line.invoice_line_tax_id, invoice_line.price_subtotal/line.quantity, invoice_line.quantity, invoice.address_invoice_id.id, invoice_line.product_id, invoice.partner_id): | ||
401 | 152 | line_tax_amount += tax['amount'] | ||
402 | 153 | line_total = invoice_line.price_subtotal + line_tax_amount | ||
403 | 154 | invoice_res_amount = invoice.amount_total | ||
404 | 155 | line_ratio = line_total / invoice_res_amount | ||
405 | 156 | ########################### | ||
406 | 157 | amount = obj_inv._get_amount(cursor, user, [invoice.id] ,invoice.residual, invoice.payment_term.id, context=context) | ||
407 | 158 | invoice_amount = amount['amount'] | ||
408 | 159 | discount = obj_inv._get_payment(cursor, user, [invoice.id] , invoice_amount, invoice.payment_term.id, context=context) | ||
409 | 160 | account = obj_inv._get_account(cursor, user, [invoice.id] , invoice.residual, invoice.payment_term.id, context=context) | ||
410 | 161 | |||
411 | 162 | ### discount for the invoice line | ||
412 | 163 | discount_pay = discount * line_ratio | ||
413 | 151 | if invoice_line.invoice_line_tax_id: | 164 | if invoice_line.invoice_line_tax_id: |
424 | 152 | amount_invoice_line = obj_inv._get_amount(cursor, user, [invoice.id] , invoice_line.price_subtotal, invoice.payment_term.id, context=context) | 165 | tax_real_amt = 0.0 |
425 | 153 | line_amount = amount_invoice_line['amount'] | 166 | tax_account_id = False |
426 | 154 | discount = obj_inv._get_payment(cursor, user, [invoice.id] , line_amount, invoice.payment_term.id, context=context) | 167 | for tax_id in invoice_line.invoice_line_tax_id: |
427 | 155 | account = obj_inv._get_account(cursor, user, [invoice.id] , invoice.residual, invoice.payment_term.id, context=context) | 168 | tax_data = tax_obj.browse(cursor, user, tax_id.id, context=context) |
428 | 156 | 169 | tax_amt = discount_pay * tax_data.amount | |
429 | 157 | tax_amount = 0.0 | 170 | tax_real_amt = tax_amt / (1 + tax_data.amount) |
430 | 158 | 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): | 171 | total_tax_amount += tax_real_amt |
431 | 159 | tax_amount = tax['amount'] | 172 | |
432 | 160 | tax_total_amount += tax['amount'] | 173 | tax_invoice_id = invoice_tax_obj.search(cursor, user,[('invoice_id','=',invoice.id),('name','=',tax_data.name)]) |
423 | 161 | tax_invoice_id = invoice_tax_obj.search(cursor,user,[('invoice_id','=',invoice.id),('name','=',tax['name'])]) | ||
433 | 162 | for tax_id in tax_invoice_id: | 174 | for tax_id in tax_invoice_id: |
434 | 163 | tax_value = invoice_tax_obj.browse(cursor, user, tax_id) | 175 | tax_value = invoice_tax_obj.browse(cursor, user, tax_id) |
435 | 164 | tax_account_id = tax_value.account_id.id | 176 | tax_account_id = tax_value.account_id.id |
438 | 165 | 177 | tax_code_id = tax_value.tax_code_id.id | |
439 | 166 | if tax_amount>0: | 178 | if tax_real_amt>0: |
440 | 167 | statement_reconcile_line_obj.create(cursor, user, { | 179 | statement_reconcile_line_obj.create(cursor, user, { |
441 | 168 | 'name': line.name, | 180 | 'name': line.name, |
443 | 169 | 'amount': tax_amount, | 181 | 'amount': tax_real_amt, |
444 | 170 | 'account_id': tax_account_id, | 182 | 'account_id': tax_account_id, |
445 | 171 | 'line_id': reconcile_id, | 183 | 'line_id': reconcile_id, |
446 | 172 | }, context=context) | 184 | }, context=context) |
456 | 173 | 185 | if discount>0: | |
457 | 174 | if discount>0: | 186 | discount = discount * line_ratio |
458 | 175 | total_discount += discount | 187 | statement_reconcile_line_obj.create(cursor, user, { |
459 | 176 | statement_reconcile_line_obj.create(cursor, user, { | 188 | 'name': line.name, |
460 | 177 | 'name': line.name, | 189 | 'amount': discount - total_tax_amount, |
461 | 178 | 'amount': discount - tax_amount, | 190 | 'account_id': account, |
462 | 179 | 'account_id': account, | 191 | 'line_id': reconcile_id, |
463 | 180 | 'line_id': reconcile_id, | 192 | }, context=context) |
455 | 181 | }, context=context) | ||
464 | 182 | ########################################################################## | 193 | ########################################################################## |
465 | 183 | 194 | ||
466 | 184 | if line.journal_id.type == 'sale': | 195 | if line.journal_id.type == 'sale': |
467 | @@ -190,7 +201,7 @@ | |||
468 | 190 | 201 | ||
469 | 191 | statement_line_obj.create(cursor, user, { | 202 | statement_line_obj.create(cursor, user, { |
470 | 192 | 'name': line.name or '?', | 203 | 'name': line.name or '?', |
472 | 193 | 'amount': amount, | 204 | 'amount': invoice_amount, |
473 | 194 | 'type': type, | 205 | 'type': type, |
474 | 195 | 'partner_id': line.partner_id.id, | 206 | 'partner_id': line.partner_id.id, |
475 | 196 | 'account_id': line.account_id.id, | 207 | 'account_id': line.account_id.id, |