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 | 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,16 +364,12 @@ | |||
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 | @@ -379,20 +381,32 @@ | |||
62 | 379 | invoice_res_amount = invoice.amount_total | 381 | invoice_res_amount = invoice.amount_total |
63 | 380 | line_ratio = line_total / invoice_res_amount | 382 | line_ratio = line_total / invoice_res_amount |
64 | 381 | 383 | ||
70 | 382 | discount = amount_discount * line_ratio | 384 | discount_ratio = amount_discount * line_ratio |
71 | 383 | 385 | total_tax_amount = 0.0 | |
72 | 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 | |
73 | 385 | tax_amount = tax['amount'] | 387 | for tax_id in line.invoice_line_tax_id: |
74 | 386 | 388 | tax_data = tax_obj.browse(cr, uid, tax_id.id, context=context) | |
75 | 389 | tax_amt = discount_ratio * tax_data.amount | ||
76 | 390 | tax_real_amt = tax_amt / (1 + tax_data.amount) | ||
77 | 391 | total_tax_amount += tax_real_amt | ||
78 | 392 | |||
79 | 393 | tax_invoice_id = invoice_tax_obj.search(cr,uid,[('invoice_id','=',invoice.id),('name','=',tax_data.name)]) | ||
80 | 394 | for tax_id in tax_invoice_id: | ||
81 | 395 | tax_value = invoice_tax_obj.browse(cr, uid, tax_id) | ||
82 | 396 | tax_account_id = tax_value.account_id.id | ||
83 | 397 | base_code_id = tax_value.base_code_id.id | ||
84 | 398 | |||
85 | 387 | l4 = { | 399 | l4 = { |
88 | 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), |
89 | 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), |
90 | 390 | 'account_id': account_id, | 402 | 'account_id': account_id, |
91 | 391 | 'partner_id': invoice.partner_id.id, | 403 | 'partner_id': invoice.partner_id.id, |
92 | 392 | 'ref':ref, | 404 | 'ref':ref, |
93 | 393 | 'date': date, | 405 | 'date': date, |
94 | 394 | 'currency_id':currency_id, | 406 | 'currency_id':currency_id, |
95 | 395 | 'amount_currency':amount_currency and direction * amount_currency or 0.0, | 407 | 'amount_currency':amount_currency and direction * amount_currency or 0.0, |
96 | 408 | 'tax_code_id':base_code_id, | ||
97 | 409 | 'tax_amount':line.price_unit, | ||
98 | 396 | } | 410 | } |
99 | 397 | l4['name'] = name | 411 | l4['name'] = name |
100 | 398 | lines.append((0, 0, l4)) | 412 | lines.append((0, 0, l4)) |
101 | @@ -530,9 +544,9 @@ | |||
102 | 530 | amount = res_currency_obj.compute(cr, uid, st.currency.id, | 544 | amount = res_currency_obj.compute(cr, uid, st.currency.id, |
103 | 531 | company_currency_id, move.amount, context=context, | 545 | company_currency_id, move.amount, context=context, |
104 | 532 | account=acc_cur) | 546 | account=acc_cur) |
108 | 533 | if move.reconcile_id and move.reconcile_id.line_new_ids: | 547 | # if move.reconcile_id and move.reconcile_id.line_new_ids: |
109 | 534 | for newline in move.reconcile_id.line_new_ids: | 548 | # for newline in move.reconcile_id.line_new_ids: |
110 | 535 | amount += newline.amount | 549 | # amount += newline.amount |
111 | 536 | 550 | ||
112 | 537 | val = { | 551 | val = { |
113 | 538 | 'name': move.name, | 552 | 'name': move.name, |
114 | @@ -569,9 +583,10 @@ | |||
115 | 569 | val['amount_currency'] = amount_cur | 583 | val['amount_currency'] = amount_cur |
116 | 570 | 584 | ||
117 | 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)) |
119 | 572 | 586 | newline_sum = 0.0 | |
120 | 573 | if move.reconcile_id and move.reconcile_id.line_new_ids: | 587 | if move.reconcile_id and move.reconcile_id.line_new_ids: |
121 | 574 | for newline in move.reconcile_id.line_new_ids: | 588 | for newline in move.reconcile_id.line_new_ids: |
122 | 589 | newline_sum += newline.amount | ||
123 | 575 | account_move_line_obj.create(cr, uid, { | 590 | account_move_line_obj.create(cr, uid, { |
124 | 576 | 'name': newline.name or move.name, | 591 | 'name': newline.name or move.name, |
125 | 577 | 'date': move.date, | 592 | 'date': move.date, |
126 | @@ -673,8 +688,6 @@ | |||
127 | 673 | 'amount_currency': amount_currency, | 688 | 'amount_currency': amount_currency, |
128 | 674 | 'currency_id': currency_id, | 689 | 'currency_id': currency_id, |
129 | 675 | }, context=context) | 690 | }, context=context) |
130 | 676 | else: | ||
131 | 677 | continue | ||
132 | 678 | 691 | ||
133 | 679 | account_move_line_obj.create(cr, uid, { | 692 | account_move_line_obj.create(cr, uid, { |
134 | 680 | 'name': move.name, | 693 | 'name': move.name, |
135 | @@ -683,8 +696,8 @@ | |||
136 | 683 | 'move_id': move_id, | 696 | 'move_id': move_id, |
137 | 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, |
138 | 685 | 'account_id': account_id, | 698 | 'account_id': account_id, |
141 | 686 | 'credit': ((amount < 0) and -amount) or 0.0, | 699 | 'credit': (((amount-newline_sum) < 0) and -(amount-newline_sum)) or 0.0, |
142 | 687 | 'debit': ((amount > 0) and amount) or 0.0, | 700 | 'debit': (((amount-newline_sum) > 0) and (amount-newline_sum)) or 0.0, |
143 | 688 | 'statement_id': st.id, | 701 | 'statement_id': st.id, |
144 | 689 | 'journal_id': st.journal_id.id, | 702 | 'journal_id': st.journal_id.id, |
145 | 690 | 'period_id': st.period_id.id, | 703 | 'period_id': st.period_id.id, |
146 | 691 | 704 | ||
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 | 142 | for line in invoice.invoice_line: | 142 | for line in invoice.invoice_line: |
152 | 143 | tax_amount = 0.0 | 143 | tax_amount = 0.0 |
153 | 144 | line_tax_amount = 0.0 | 144 | line_tax_amount = 0.0 |
155 | 145 | 145 | ######## | |
156 | 146 | line_tax_amount = 0.0 | ||
157 | 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 | 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 | 147 | line_tax_amount = tax['amount'] | 148 | line_tax_amount += tax['amount'] |
159 | 148 | |||
161 | 149 | line_total = line.price_subtotal + line_tax_amount | 149 | line_total = line.price_subtotal + line_tax_amount |
162 | 150 | invoice_res_amount = invoice.amount_total | 150 | invoice_res_amount = invoice.amount_total |
163 | 151 | line_ratio = line_total / invoice_res_amount | 151 | line_ratio = line_total / invoice_res_amount |
164 | 152 | ##################################################### | ||
165 | 153 | discount_pay = discount * line_ratio | ||
166 | 152 | 154 | ||
167 | 153 | if line.invoice_line_tax_id: | 155 | if line.invoice_line_tax_id: |
171 | 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): | 156 | total_tax_amount = 0.0 |
172 | 155 | tax_amount = tax['amount'] | 157 | for tax_id in line.invoice_line_tax_id: |
173 | 156 | tax_invoice_id = invoice_tax_obj.search(cr,uid,[('invoice_id','=',invoice.id),('name','=',tax['name'])]) | 158 | tax_data = tax_obj.browse(cr, uid, tax_id.id, context=context) |
174 | 159 | |||
175 | 160 | tax_amt = discount_pay * tax_data.amount | ||
176 | 161 | tax_real_amt = tax_amt / (1 + tax_data.amount) | ||
177 | 162 | total_tax_amount += tax_real_amt | ||
178 | 163 | tax_invoice_id = invoice_tax_obj.search(cr,uid,[('invoice_id','=',invoice.id),('name','=',tax_data.name)]) | ||
179 | 164 | |||
180 | 157 | for tax_id in tax_invoice_id: | 165 | for tax_id in tax_invoice_id: |
181 | 158 | tax_value = invoice_tax_obj.browse(cr, uid, tax_id) | 166 | tax_value = invoice_tax_obj.browse(cr, uid, tax_id) |
182 | 159 | tax_account_id = tax_value.account_id.id | ||
183 | 160 | base_code_id = tax_value.base_code_id.id | 167 | base_code_id = tax_value.base_code_id.id |
189 | 161 | 168 | ||
190 | 162 | if invoice.company_id.currency_id.id<>invoice.currency_id.id: | 169 | |
186 | 163 | amount = cur_obj.compute(cr, uid, invoice.currency_id.id, invoice.company_id.currency_id.id, tax_amount, context=context) | ||
187 | 164 | |||
188 | 165 | discount_pay = discount * line_ratio | ||
191 | 166 | if invoice.company_id.currency_id.id<>invoice.currency_id.id: | 170 | if invoice.company_id.currency_id.id<>invoice.currency_id.id: |
193 | 167 | discount_amount = discount - tax_amount | 171 | discount_amount = discount - tax_real_amt |
194 | 168 | amount = cur_obj.compute(cr, uid, invoice.currency_id.id, invoice.company_id.currency_id.id, discount_amount, context=context) | 172 | amount = cur_obj.compute(cr, uid, invoice.currency_id.id, invoice.company_id.currency_id.id, discount_amount, context=context) |
195 | 169 | 173 | ||
196 | 170 | l4 = { | 174 | l4 = { |
199 | 171 | 'debit': direction * (discount_pay - tax_amount)<0 and - direction * (discount_pay - tax_amount), | 175 | 'debit': direction * (discount_pay - total_tax_amount)<0 and - direction * (discount_pay - total_tax_amount), |
200 | 172 | 'credit': direction * (discount_pay - tax_amount)>0 and direction * (discount_pay - tax_amount), | 176 | 'credit': direction * (discount_pay - total_tax_amount)>0 and direction * (discount_pay - total_tax_amount), |
201 | 173 | 'account_id': discount_account_id, | 177 | 'account_id': discount_account_id, |
202 | 174 | 'date': date, | 178 | 'date': date, |
203 | 175 | 'name':name, | 179 | 'name':name, |
204 | 176 | 'currency_id':invoice.currency_id.id or False, | 180 | 'currency_id':invoice.currency_id.id or False, |
205 | 177 | 'journal_id':invoice.journal_id.id, | 181 | 'journal_id':invoice.journal_id.id, |
206 | 178 | 'tax_code_id':base_code_id, | 182 | 'tax_code_id':base_code_id, |
208 | 179 | 'tax_amount':tax_amount, | 183 | 'tax_amount':line.price_unit, |
209 | 180 | 'amount_currency':amount and direction * amount or 0.0, | 184 | 'amount_currency':amount and direction * amount or 0.0, |
210 | 181 | 'analytic_account_id':line.account_analytic_id.id or False, | 185 | 'analytic_account_id':line.account_analytic_id.id or False, |
211 | 182 | } | 186 | } |
212 | @@ -206,33 +210,48 @@ | |||
213 | 206 | line_ids = [] | 210 | line_ids = [] |
214 | 207 | 211 | ||
215 | 208 | tax_code_id = False | 212 | tax_code_id = False |
216 | 213 | tax_account_id = False | ||
217 | 209 | discount = self._get_discount(cr, uid, context=context) | 214 | discount = self._get_discount(cr, uid, context=context) |
218 | 210 | if discount>0.0: | 215 | if discount>0.0: |
219 | 211 | for line in invoice.invoice_line: | 216 | for line in invoice.invoice_line: |
220 | 212 | tax_amount = 0.0 | ||
221 | 213 | line_tax_amount = 0.0 | 217 | line_tax_amount = 0.0 |
222 | 218 | total_tax_amount = 0.0 | ||
223 | 219 | ############# Ratio##### | ||
224 | 220 | 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 | 221 | line_tax_amount += tax['amount'] | ||
226 | 222 | line_total = line.price_subtotal + line_tax_amount | ||
227 | 223 | invoice_res_amount = invoice.amount_total | ||
228 | 224 | line_ratio = line_total / invoice_res_amount | ||
229 | 225 | ############# | ||
230 | 226 | |||
231 | 227 | ### discount for the invoice line | ||
232 | 228 | discount_pay = discount * line_ratio | ||
233 | 229 | |||
234 | 214 | if line.invoice_line_tax_id: | 230 | if line.invoice_line_tax_id: |
238 | 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): | 231 | for tax_id in line.invoice_line_tax_id: |
239 | 216 | tax_amount = tax['amount'] | 232 | tax_data = tax_obj.browse(cr, uid, tax_id.id, context=context) |
240 | 217 | tax_invoice_id = invoice_tax_obj.search(cr,uid,[('invoice_id','=',invoice.id),('name','=',tax['name'])]) | 233 | tax_amt = discount_pay * tax_data.amount |
241 | 234 | tax_real_amt = tax_amt / (1 + tax_data.amount) | ||
242 | 235 | total_tax_amount += tax_real_amt | ||
243 | 236 | tax_invoice_id = invoice_tax_obj.search(cr,uid,[('invoice_id','=',invoice.id),('name','=',tax_data.name)]) | ||
244 | 218 | for tax_id in tax_invoice_id: | 237 | for tax_id in tax_invoice_id: |
245 | 219 | tax_value = invoice_tax_obj.browse(cr, uid, tax_id) | 238 | tax_value = invoice_tax_obj.browse(cr, uid, tax_id) |
246 | 220 | tax_account_id = tax_value.account_id.id | 239 | tax_account_id = tax_value.account_id.id |
247 | 221 | tax_code_id = tax_value.tax_code_id.id | 240 | tax_code_id = tax_value.tax_code_id.id |
249 | 222 | 241 | ||
250 | 223 | if invoice.company_id.currency_id.id<>invoice.currency_id.id: | 242 | if invoice.company_id.currency_id.id<>invoice.currency_id.id: |
251 | 224 | amount = cur_obj.compute(cr, uid, invoice.currency_id.id, invoice.company_id.currency_id.id, tax_amount, context=context) | 243 | amount = cur_obj.compute(cr, uid, invoice.currency_id.id, invoice.company_id.currency_id.id, tax_amount, context=context) |
253 | 225 | 244 | ||
254 | 226 | l3 = { | 245 | l3 = { |
257 | 227 | 'debit': direction * tax_amount<0 and - direction * tax_amount, | 246 | 'debit': direction * tax_real_amt<0 and - direction * tax_real_amt, |
258 | 228 | 'credit': direction * tax_amount>0 and direction * tax_amount, | 247 | 'credit': direction * tax_real_amt>0 and direction * tax_real_amt, |
259 | 229 | 'account_id': tax_account_id, | 248 | 'account_id': tax_account_id, |
260 | 230 | 'date': date, | 249 | 'date': date, |
261 | 231 | 'journal_id':invoice.journal_id.id or False, | 250 | 'journal_id':invoice.journal_id.id or False, |
262 | 232 | 'name':name, | 251 | 'name':name, |
263 | 233 | 'currency_id':invoice.currency_id.id or False, | 252 | 'currency_id':invoice.currency_id.id or False, |
266 | 234 | 'tax_code_id':tax_value.tax_code_id.id, | 253 | 'tax_code_id':tax_code_id, |
267 | 235 | 'tax_amount':-tax_amount, | 254 | 'tax_amount':discount_pay, |
268 | 236 | 'amount_currency':amount and direction * amount or 0.0, | 255 | 'amount_currency':amount and direction * amount or 0.0, |
269 | 237 | 'analytic_account_id':line.account_analytic_id.id or False, | 256 | 'analytic_account_id':line.account_analytic_id.id or False, |
270 | 238 | } | 257 | } |
271 | @@ -315,18 +334,23 @@ | |||
272 | 315 | for line in invoice.invoice_line: | 334 | for line in invoice.invoice_line: |
273 | 316 | tax_amount = 0.0 | 335 | tax_amount = 0.0 |
274 | 317 | line_tax_amount = 0.0 | 336 | line_tax_amount = 0.0 |
276 | 318 | 337 | total_tax_amount = 0.0 | |
277 | 319 | #####get the ratio of the line in the total invoice amount | 338 | #####get the ratio of the line in the total invoice amount |
278 | 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): | 339 | 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): |
280 | 321 | line_tax_amount = tax['amount'] | 340 | line_tax_amount += tax['amount'] |
281 | 322 | line_total = line.price_subtotal + line_tax_amount | 341 | line_total = line.price_subtotal + line_tax_amount |
282 | 323 | invoice_res_amount = invoice.amount_total | 342 | invoice_res_amount = invoice.amount_total |
283 | 324 | line_ratio = line_total / invoice_res_amount | 343 | line_ratio = line_total / invoice_res_amount |
284 | 325 | ########################### | 344 | ########################### |
285 | 345 | discount_pay = data['cash_amount'] * line_ratio | ||
286 | 326 | if line.invoice_line_tax_id: | 346 | if line.invoice_line_tax_id: |
290 | 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): | 347 | for tax_id in line.invoice_line_tax_id: |
291 | 328 | tax_amount = tax['amount'] | 348 | tax_data = tax_obj.browse(cr, uid, tax_id.id, context=context) |
292 | 329 | tax_invoice_id = invoice_tax_obj.search(cr,uid,[('invoice_id','=',invoice.id),('name','=',tax['name'])]) | 349 | tax_amt = discount_pay * tax_data.amount |
293 | 350 | tax_real_amt = tax_amt / (1 + tax_data.amount) | ||
294 | 351 | total_tax_amount += tax_real_amt | ||
295 | 352 | |||
296 | 353 | tax_invoice_id = invoice_tax_obj.search(cr,uid,[('invoice_id','=',invoice.id),('name','=',tax_data.name)]) | ||
297 | 330 | for tax_id in tax_invoice_id: | 354 | for tax_id in tax_invoice_id: |
298 | 331 | tax_value = invoice_tax_obj.browse(cr, uid, tax_id) | 355 | tax_value = invoice_tax_obj.browse(cr, uid, tax_id) |
299 | 332 | tax_account_id = tax_value.account_id.id | 356 | tax_account_id = tax_value.account_id.id |
300 | @@ -337,15 +361,15 @@ | |||
301 | 337 | amount = cur_obj.compute(cr, uid, invoice.currency_id.id, invoice.company_id.currency_id.id, tax_amount, context=context) | 361 | amount = cur_obj.compute(cr, uid, invoice.currency_id.id, invoice.company_id.currency_id.id, tax_amount, context=context) |
302 | 338 | 362 | ||
303 | 339 | l3 = { | 363 | l3 = { |
306 | 340 | 'debit': direction * tax_amount<0 and - direction * tax_amount, | 364 | 'debit': direction * tax_real_amt<0 and - direction * tax_real_amt, |
307 | 341 | 'credit': direction * tax_amount>0 and direction * tax_amount, | 365 | 'credit': direction * tax_real_amt>0 and direction * tax_real_amt, |
308 | 342 | 'account_id': tax_account_id, | 366 | 'account_id': tax_account_id, |
309 | 343 | 'date': date, | 367 | 'date': date, |
310 | 344 | 'journal_id':data.get('journal_id',False) , | 368 | 'journal_id':data.get('journal_id',False) , |
311 | 345 | 'name':name, | 369 | 'name':name, |
312 | 346 | 'currency_id':invoice.currency_id.id or False, | 370 | 'currency_id':invoice.currency_id.id or False, |
313 | 347 | 'tax_code_id':tax_value.tax_code_id.id, | 371 | 'tax_code_id':tax_value.tax_code_id.id, |
315 | 348 | 'tax_amount':-tax_amount, | 372 | 'tax_amount':discount_pay, |
316 | 349 | 'amount_currency':amount and direction * amount or 0.0, | 373 | 'amount_currency':amount and direction * amount or 0.0, |
317 | 350 | 'analytic_account_id':line.account_analytic_id.id or False, | 374 | 'analytic_account_id':line.account_analytic_id.id or False, |
318 | 351 | } | 375 | } |
319 | @@ -368,21 +392,20 @@ | |||
320 | 368 | else: | 392 | else: |
321 | 369 | discount_account_id = data['account_id'] | 393 | discount_account_id = data['account_id'] |
322 | 370 | 394 | ||
323 | 371 | discount = data['cash_amount'] * line_ratio | ||
324 | 372 | if invoice.company_id.currency_id.id<>invoice.currency_id.id: | 395 | if invoice.company_id.currency_id.id<>invoice.currency_id.id: |
326 | 373 | discount_amount = discount - tax_amount | 396 | discount_amount = discount_pay - tax_amount |
327 | 374 | amount = cur_obj.compute(cr, uid, invoice.currency_id.id, invoice.company_id.currency_id.id, discount_amount, context=context) | 397 | amount = cur_obj.compute(cr, uid, invoice.currency_id.id, invoice.company_id.currency_id.id, discount_amount, context=context) |
329 | 375 | 398 | ||
330 | 376 | l4 = { | 399 | l4 = { |
333 | 377 | 'debit': direction * (discount - tax_amount)<0 and - direction * (discount - tax_amount), | 400 | 'debit': direction * (discount_pay - total_tax_amount)<0 and - direction * (discount_pay - total_tax_amount), |
334 | 378 | 'credit': direction * (discount - tax_amount)>0 and direction * (discount - tax_amount), | 401 | 'credit': direction * (discount_pay - total_tax_amount)>0 and direction * (discount_pay - total_tax_amount), |
335 | 379 | 'account_id': discount_account_id, | 402 | 'account_id': discount_account_id, |
336 | 380 | 'date': date, | 403 | 'date': date, |
337 | 381 | 'name':name, | 404 | 'name':name, |
338 | 382 | 'currency_id':invoice.currency_id.id or False, | 405 | 'currency_id':invoice.currency_id.id or False, |
339 | 383 | 'journal_id':data.get('journal_id',False), | 406 | 'journal_id':data.get('journal_id',False), |
340 | 384 | 'tax_code_id':base_code_id, | 407 | 'tax_code_id':base_code_id, |
342 | 385 | 'tax_amount':tax_amount, | 408 | 'tax_amount':line.price_unit, |
343 | 386 | 'amount_currency':amount and direction * amount or 0.0, | 409 | 'amount_currency':amount and direction * amount or 0.0, |
344 | 387 | 'analytic_account_id':line.account_analytic_id.id or False, | 410 | 'analytic_account_id':line.account_analytic_id.id or False, |
345 | 388 | } | 411 | } |
346 | @@ -516,7 +539,7 @@ | |||
347 | 516 | debit+=payment.debit | 539 | debit+=payment.debit |
348 | 517 | credit+=payment.credit | 540 | credit+=payment.credit |
349 | 518 | amount_paid+=abs(debit-credit) | 541 | amount_paid+=abs(debit-credit) |
351 | 519 | 542 | ||
352 | 520 | if data['cash_residual_amount'] == 0.0 or self.pool.get('res.currency').is_zero(cr, uid, invoice.company_id.currency_id, | 543 | if data['cash_residual_amount'] == 0.0 or self.pool.get('res.currency').is_zero(cr, uid, invoice.company_id.currency_id, |
353 | 521 | (amount_paid - inv_amount_company_currency)): | 544 | (amount_paid - inv_amount_company_currency)): |
354 | 522 | return self.pay_and_reconcile(cr, uid, ids, context=context) | 545 | return self.pay_and_reconcile(cr, uid, ids, context=context) |
355 | 523 | 546 | ||
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 | 76 | <field name="model">account.move.line.memory</field> | 76 | <field name="model">account.move.line.memory</field> |
361 | 77 | <field name="type">tree</field> | 77 | <field name="type">tree</field> |
362 | 78 | <field name="arch" type="xml"> | 78 | <field name="arch" type="xml"> |
364 | 79 | <tree string="Account Move Line"> | 79 | <tree string="Account Move Line" editable="bottom"> |
365 | 80 | <field name="date"/> | 80 | <field name="date"/> |
366 | 81 | <field name="name"/> | 81 | <field name="name"/> |
367 | 82 | <field name="account_id"/> | 82 | <field name="account_id"/> |
368 | 83 | 83 | ||
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 | 138 | 'line_ids': [(6, 0, [line.id])] | 138 | 'line_ids': [(6, 0, [line.id])] |
374 | 139 | }, context=context) | 139 | }, context=context) |
375 | 140 | 140 | ||
377 | 141 | ######################################### Calculation for discount and taxes###### | 141 | ######################################### Calculation for discount and taxes###### |
378 | 142 | if line.invoice.id: | 142 | if line.invoice.id: |
379 | 143 | 143 | ||
380 | 144 | discount = 0.0 | 144 | discount = 0.0 |
381 | 145 | account = False | 145 | account = False |
382 | 146 | tax_total_amount = 0.0 | ||
383 | 147 | total_discount = 0.0 | ||
384 | 148 | invoice = obj_inv.browse(cursor, user, line.invoice.id, context=context) | 146 | invoice = obj_inv.browse(cursor, user, line.invoice.id, context=context) |
385 | 149 | |||
386 | 150 | for invoice_line in invoice.invoice_line: | 147 | for invoice_line in invoice.invoice_line: |
387 | 148 | line_tax_amount = 0.0 | ||
388 | 149 | total_tax_amount = 0.0 | ||
389 | 150 | #####get the ratio of the line in the total invoice amount | ||
390 | 151 | 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 | 152 | line_tax_amount += tax['amount'] | ||
392 | 153 | line_total = invoice_line.price_subtotal + line_tax_amount | ||
393 | 154 | invoice_res_amount = invoice.amount_total | ||
394 | 155 | line_ratio = line_total / invoice_res_amount | ||
395 | 156 | ########################### | ||
396 | 157 | amount = obj_inv._get_amount(cursor, user, [invoice.id] ,invoice.residual, invoice.payment_term.id, context=context) | ||
397 | 158 | invoice_amount = amount['amount'] | ||
398 | 159 | discount = obj_inv._get_payment(cursor, user, [invoice.id] , invoice_amount, invoice.payment_term.id, context=context) | ||
399 | 160 | account = obj_inv._get_account(cursor, user, [invoice.id] , invoice.residual, invoice.payment_term.id, context=context) | ||
400 | 161 | |||
401 | 162 | ### discount for the invoice line | ||
402 | 163 | discount_pay = discount * line_ratio | ||
403 | 151 | if invoice_line.invoice_line_tax_id: | 164 | if invoice_line.invoice_line_tax_id: |
414 | 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 |
415 | 153 | line_amount = amount_invoice_line['amount'] | 166 | for tax_id in invoice_line.invoice_line_tax_id: |
416 | 154 | discount = obj_inv._get_payment(cursor, user, [invoice.id] , line_amount, invoice.payment_term.id, context=context) | 167 | tax_data = tax_obj.browse(cursor, user, tax_id.id, context=context) |
417 | 155 | account = obj_inv._get_account(cursor, user, [invoice.id] , invoice.residual, invoice.payment_term.id, context=context) | 168 | tax_amt = discount_pay * tax_data.amount |
418 | 156 | 169 | tax_real_amt = tax_amt / (1 + tax_data.amount) | |
419 | 157 | tax_amount = 0.0 | 170 | total_tax_amount += tax_real_amt |
420 | 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 | |
421 | 159 | tax_amount = tax['amount'] | 172 | tax_invoice_id = invoice_tax_obj.search(cursor, user,[('invoice_id','=',invoice.id),('name','=',tax_data.name)]) |
412 | 160 | tax_total_amount += tax['amount'] | ||
413 | 161 | tax_invoice_id = invoice_tax_obj.search(cursor,user,[('invoice_id','=',invoice.id),('name','=',tax['name'])]) | ||
422 | 162 | for tax_id in tax_invoice_id: | 173 | for tax_id in tax_invoice_id: |
423 | 163 | tax_value = invoice_tax_obj.browse(cursor, user, tax_id) | 174 | tax_value = invoice_tax_obj.browse(cursor, user, tax_id) |
424 | 164 | tax_account_id = tax_value.account_id.id | 175 | tax_account_id = tax_value.account_id.id |
427 | 165 | 176 | ||
428 | 166 | if tax_amount>0: | 177 | if tax_real_amt>0: |
429 | 167 | statement_reconcile_line_obj.create(cursor, user, { | 178 | statement_reconcile_line_obj.create(cursor, user, { |
430 | 168 | 'name': line.name, | 179 | 'name': line.name, |
432 | 169 | 'amount': tax_amount, | 180 | 'amount': tax_real_amt, |
433 | 170 | 'account_id': tax_account_id, | 181 | 'account_id': tax_account_id, |
434 | 171 | 'line_id': reconcile_id, | 182 | 'line_id': reconcile_id, |
435 | 172 | }, context=context) | 183 | }, context=context) |
445 | 173 | 184 | if discount>0: | |
446 | 174 | if discount>0: | 185 | discount = discount * line_ratio |
447 | 175 | total_discount += discount | 186 | statement_reconcile_line_obj.create(cursor, user, { |
448 | 176 | statement_reconcile_line_obj.create(cursor, user, { | 187 | 'name': line.name, |
449 | 177 | 'name': line.name, | 188 | 'amount': discount - total_tax_amount, |
450 | 178 | 'amount': discount - tax_amount, | 189 | 'account_id': account, |
451 | 179 | 'account_id': account, | 190 | 'line_id': reconcile_id, |
452 | 180 | 'line_id': reconcile_id, | 191 | }, context=context) |
444 | 181 | }, context=context) | ||
453 | 182 | ########################################################################## | 192 | ########################################################################## |
454 | 183 | 193 | ||
455 | 184 | if line.journal_id.type == 'sale': | 194 | if line.journal_id.type == 'sale': |
456 | @@ -190,7 +200,7 @@ | |||
457 | 190 | 200 | ||
458 | 191 | statement_line_obj.create(cursor, user, { | 201 | statement_line_obj.create(cursor, user, { |
459 | 192 | 'name': line.name or '?', | 202 | 'name': line.name or '?', |
461 | 193 | 'amount': amount, | 203 | 'amount': invoice_amount, |
462 | 194 | 'type': type, | 204 | 'type': type, |
463 | 195 | 'partner_id': line.partner_id.id, | 205 | 'partner_id': line.partner_id.id, |
464 | 196 | 'account_id': line.account_id.id, | 206 | 'account_id': line.account_id.id, |