Merge lp:~openbig/bigconsulting/account_invoice_cash_discount_milestone1 into lp:bigconsulting
- account_invoice_cash_discount_milestone1
- Merge into addons
Proposed by
gpa(OpenERP)
Status: | Merged |
---|---|
Merged at revision: | 47 |
Proposed branch: | lp:~openbig/bigconsulting/account_invoice_cash_discount_milestone1 |
Merge into: | lp:bigconsulting |
Diff against target: |
636 lines (+217/-139) 5 files modified
account_invoice_cash_discount/account_invoice_cash_discount.py (+37/-33) account_invoice_cash_discount/account_invoice_cash_discount_view.xml (+3/-1) account_invoice_cash_discount/wizard/account_pay_invoice.py (+158/-93) account_invoice_cash_discount/wizard/account_pay_invoice_view.xml (+1/-1) account_invoice_cash_discount/wizard/invoice_statement_payment.py (+18/-11) |
To merge this branch: | bzr merge lp:~openbig/bigconsulting/account_invoice_cash_discount_milestone1 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
openbig | Pending | ||
Review via email: mp+29865@code.launchpad.net |
Commit message
Description of the change
changes in the milestone1 of the account_
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-08-21 12:43:18 +0000 |
3 | +++ account_invoice_cash_discount/account_invoice_cash_discount.py 2010-07-14 12:24:45 +0000 |
4 | @@ -45,6 +45,8 @@ |
5 | 'credit_account_id': fields.many2one('account.account', 'Credit Account'), |
6 | 'debit_account_id': fields.many2one('account.account', 'Debit Account'), |
7 | 'payment_term_ids': fields.one2many('account.payment.term.line', 'cash_account_discount_id', 'Payment Term Lines'), |
8 | + 'day_tolerance': fields.integer('Days Tolerance', digits=(16,6),required=True), |
9 | + 'sup_discount_account_id': fields.many2one('account.account', 'Supplier Discount Account',required=True), |
10 | } |
11 | account_cash_discount() |
12 | |
13 | @@ -61,14 +63,11 @@ |
14 | _inherit = "account.invoice" |
15 | |
16 | def _get_amount(self, cr, uid, ids, resudial_amonut, payment_term, context=None): |
17 | - |
18 | """ |
19 | This function return the Amount to paid according to the payment term cash discount payment term lines |
20 | """ |
21 | - |
22 | if context is None: |
23 | context = {} |
24 | - |
25 | tax_obj = self.pool.get('account.tax') |
26 | invoice = self.browse(cr, uid, ids[0], context=context) |
27 | |
28 | @@ -203,12 +202,14 @@ |
29 | dis = 0.0 |
30 | for discount_line in payment_term_lines.cash_discount_ids: |
31 | if diff_day >= dis and diff_day <= discount_line.delay: |
32 | - account_id = discount_line.discount_account_id.id |
33 | + if invoice.type in ('in_invoice', 'in_refund'): |
34 | + account_id = discount_line.sup_discount_account_id.id |
35 | + else: |
36 | + account_id = discount_line.discount_account_id.id |
37 | dis = discount_line.delay |
38 | return account_id |
39 | |
40 | def pay_and_reconcile(self, cr, uid, ids, pay_amount, pay_account_id, period_id, pay_journal_id, writeoff_acc_id, writeoff_period_id, writeoff_journal_id, context=None, name=''): |
41 | - |
42 | if context is None: |
43 | context = {} |
44 | #TODO check if we can use different period for payment and the writeoff line |
45 | @@ -220,15 +221,12 @@ |
46 | move_line_obj = self.pool.get('account.move.line') |
47 | move_obj = self.pool.get('account.move') |
48 | |
49 | - if 'amount_currency' in context and context['amount_currency']: |
50 | - amount_currency = context['amount_currency'] |
51 | - else: |
52 | - amount_currency = invoice.residual |
53 | amount_discount = 0.0 |
54 | if invoice.payment_term: |
55 | # Return the discount on for the payment term |
56 | - amount_discount = self._get_payment(cr, uid, ids, amount_currency, invoice.payment_term.id, context=context) |
57 | - |
58 | + amount_discount = self._get_payment(cr, uid, ids, pay_amount, invoice.payment_term.id, context=context) |
59 | + |
60 | + |
61 | src_account_id = invoice.account_id.id |
62 | # Take the seq as name for move |
63 | types = {'out_invoice': -1, 'in_invoice': 1, 'out_refund': 1, 'in_refund': -1} |
64 | @@ -257,7 +255,7 @@ |
65 | |
66 | if 'cash_amount' in context and context['cash_amount']: |
67 | discount_amount = context['cash_amount'] |
68 | - |
69 | + |
70 | # Pay attention to the sign for both debit/credit AND amount_currency |
71 | l1 = { |
72 | 'debit': direction * (pay_amount)>0 and direction * (pay_amount), |
73 | @@ -270,7 +268,8 @@ |
74 | 'amount_currency':amount_currency and direction * amount_currency or 0.0, |
75 | } |
76 | |
77 | - ### if we change the amount paid and in the disocunt then it used the changes discount |
78 | + ### if we change the amount paid and in the disocunt then it used the changes discount |
79 | + |
80 | if amount_discount != discount_amount and discount_amount>0.0: |
81 | amount_discount = discount_amount |
82 | |
83 | @@ -291,7 +290,8 @@ |
84 | l1['name'] = name |
85 | l2['name'] = name |
86 | lines = [(0, 0, l1), (0, 0, l2)] |
87 | - |
88 | + |
89 | + ### When we make payment by pay invoice wizard and if found the taxes move then directly take the entry from the wizard |
90 | if 'tax_move_ids' in context and context['tax_move_ids']: |
91 | move_line = context['tax_move_ids'] |
92 | for move_line_id in move_line: |
93 | @@ -337,25 +337,28 @@ |
94 | } |
95 | l3['name'] = name |
96 | lines.append((0, 0, l3)) |
97 | - |
98 | + |
99 | + ### When we make payment by pay invoice wizard and if found the discount moves in wizard discount move then directly take the entry from the wizard |
100 | if 'discount_move_ids' in context and context['discount_move_ids']: |
101 | - dis_move_id = context['discount_move_ids'][0] |
102 | - move_id = move_line_obj.search(cr, uid,[('move_id','=',dis_move_id)]) |
103 | - move_line_data = move_line_obj.browse(cr, uid, move_id[0]) |
104 | - l4 = { |
105 | - 'debit': move_line_data.debit, |
106 | - 'credit':move_line_data.credit, |
107 | - 'account_id': move_line_data.account_id.id, |
108 | - 'partner_id': move_line_data.partner_id.id, |
109 | - 'ref':move_line_data.ref, |
110 | - 'date': move_line_data.date, |
111 | - 'currency_id':currency_id, |
112 | - 'amount_currency':amount_currency and direction * amount_currency or 0.0, |
113 | - 'name':move_line_data.name, |
114 | - } |
115 | - lines.append((0, 0, l4)) |
116 | - |
117 | - move_obj.unlink(cr, uid, context['discount_move_ids']) |
118 | + move_line = context['discount_move_ids'] |
119 | + for move_line_id in move_line: |
120 | + move_line_data = move_line_obj.browse(cr, uid,move_line_id) |
121 | + l4 = { |
122 | + 'debit': move_line_data.debit, |
123 | + 'credit':move_line_data.credit, |
124 | + 'account_id': move_line_data.account_id.id, |
125 | + 'partner_id': move_line_data.partner_id.id, |
126 | + 'ref':move_line_data.ref, |
127 | + 'date': move_line_data.date, |
128 | + 'currency_id':currency_id, |
129 | + 'amount_currency':amount_currency and direction * amount_currency or 0.0, |
130 | + 'name':move_line_data.name, |
131 | + 'tax_code_id':move_line_data.tax_code_id.id, |
132 | + 'tax_amount':move_line_data.tax_amount, |
133 | + } |
134 | + lines.append((0, 0, l4)) |
135 | + move_line_obj.unlink(cr, uid,[move_line_id]) |
136 | + move_obj.unlink(cr, uid,[move_line_data.move_id.id]) |
137 | else: |
138 | if amount_discount>0: |
139 | if 'account_id' in context and context['account_id']: |
140 | @@ -376,7 +379,7 @@ |
141 | } |
142 | l4['name'] = name |
143 | lines.append((0, 0, l4)) |
144 | - |
145 | + |
146 | move = {'ref': ref, 'line_id': lines, 'journal_id': pay_journal_id, 'period_id': period_id, 'date': date} |
147 | move_id = move_obj.create(cr, uid, move, context=context) |
148 | |
149 | @@ -420,5 +423,6 @@ |
150 | type='many2one', relation='account.invoice', fnct_search=_invoice_search), |
151 | } |
152 | account_move_line() |
153 | + |
154 | # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |
155 | |
156 | |
157 | === modified file 'account_invoice_cash_discount/account_invoice_cash_discount_view.xml' |
158 | --- account_invoice_cash_discount/account_invoice_cash_discount_view.xml 2010-08-21 12:43:18 +0000 |
159 | +++ account_invoice_cash_discount/account_invoice_cash_discount_view.xml 2010-07-14 12:24:45 +0000 |
160 | @@ -15,6 +15,8 @@ |
161 | <field name="delay" select="1"/> |
162 | <field name="discount" select="1"/> |
163 | <field name="discount_account_id" /> |
164 | + <field name="day_tolerance"/> |
165 | + <field name="sup_discount_account_id"/> |
166 | <group colspan="4"> |
167 | <separator string="Related Payment Terms Lines" colspan="4"/> |
168 | <field name="payment_term_ids" widget="one2many_list" nolabel="1"/> |
169 | @@ -96,8 +98,8 @@ |
170 | <field name="inherit_id" ref="account.view_payment_term_line_form"/> |
171 | <field name="arch" type="xml"> |
172 | <field name="days2" position="after"> |
173 | - <label string="" colspan="2"/> |
174 | <field name="compl_cash_discount"/> |
175 | + <label string="" colspan="2"/> |
176 | </field> |
177 | </field> |
178 | </record> |
179 | |
180 | === modified file 'account_invoice_cash_discount/wizard/account_pay_invoice.py' |
181 | --- account_invoice_cash_discount/wizard/account_pay_invoice.py 2010-07-06 13:32:32 +0000 |
182 | +++ account_invoice_cash_discount/wizard/account_pay_invoice.py 2010-07-14 12:24:45 +0000 |
183 | @@ -66,7 +66,7 @@ |
184 | 'cal_method_selection': fields.selection([('method_gross_methodology','Calculate Discount with Net Gross Methodology'), |
185 | ('method_net_methodology','Calculate Discount with Net Methodology'),], |
186 | 'Method To Calculation'), |
187 | - 'discount_move_ids': fields.many2many('account.move', 'account_discount_move_rel', 'discount_account_id', 'discount_move_id', 'Account Discount Moves'), |
188 | + 'discount_move_ids': fields.many2many('account.move.line', 'account_discount_move_rel', 'discount_account_id', 'discount_move_id', 'Account Discount Moves'), |
189 | 'tax_move_ids': fields.many2many('account.move.line', 'account_tax_move_rel', 'tax_account_id', 'tax_move_id', 'Account Taxes Moves'), |
190 | } |
191 | |
192 | @@ -79,7 +79,10 @@ |
193 | |
194 | def _get_amount(self, cr, uid, context=None): |
195 | obj_inv = self.pool.get('account.invoice') |
196 | + tax_obj = self.pool.get('account.tax') |
197 | invoice = obj_inv.browse(cr, uid, context['id'], context=context) |
198 | + total_tax_amount = 0.0 |
199 | + total_amount = 0.0 |
200 | amount = obj_inv._get_amount(cr, uid, [context['id']] ,invoice.residual, invoice.payment_term.id, context=context) |
201 | context.update({'found':amount['found']}) |
202 | amount = amount['amount'] |
203 | @@ -89,6 +92,7 @@ |
204 | |
205 | def _get_discount(self, cr, uid, context=None): |
206 | obj_inv = self.pool.get('account.invoice') |
207 | + tax_obj = self.pool.get('account.tax') |
208 | invoice = obj_inv.browse(cr, uid, context['id'], context=context) |
209 | amount = obj_inv._get_amount(cr, uid, [context['id']] ,invoice.residual, invoice.payment_term.id, context=context) |
210 | amount = amount['amount'] |
211 | @@ -149,6 +153,7 @@ |
212 | return {'value' : {'cash_amount':discount_amount,'cash_residual_amount':diff_amount}} |
213 | |
214 | def _calculation(self, cr, uid, ids, context=None): |
215 | + |
216 | invoice_obj = self.pool.get('account.invoice') |
217 | data = self.read(cr, uid, ids,context=context)[0] |
218 | invoice = self.pool.get('account.invoice').browse(cr, uid, context['id'], context=context) |
219 | @@ -161,13 +166,16 @@ |
220 | if data['tax_move_ids']: |
221 | move_line = data['tax_move_ids'] |
222 | for move_line_id in move_line: |
223 | - move_id = move_line_data = move_line_obj.browse(cr, uid,move_line_id).move_id.id |
224 | + move_id = move_line_obj.browse(cr, uid,move_line_id).move_id.id |
225 | move_line_obj.unlink(cr, uid,[move_line_id]) |
226 | move_obj.unlink(cr, uid,[move_id]) |
227 | |
228 | if data['discount_move_ids']: |
229 | - dis_move_id = data['discount_move_ids'][0] |
230 | - move_obj.unlink(cr, uid, data['discount_move_ids']) |
231 | + discount_move_line = data['discount_move_ids'] |
232 | + for move_line_id in discount_move_line: |
233 | + move_id = move_line_obj.browse(cr, uid,move_line_id).move_id.id |
234 | + move_line_obj.unlink(cr, uid,[move_line_id]) |
235 | + move_obj.unlink(cr, uid,[move_id]) |
236 | |
237 | ######## to get ref |
238 | if invoice.type in ('in_invoice', 'in_refund'): |
239 | @@ -182,23 +190,39 @@ |
240 | |
241 | #### to get name |
242 | name = invoice.invoice_line and invoice.invoice_line[0].name or invoice.number |
243 | - |
244 | ##### Entry in the discount account moves and entry in the tax account moves |
245 | - ### Entry for taxes in the line of wizard tax |
246 | + |
247 | if data.get('cash_amount',0.0)>0.0: |
248 | - lines3 = [] |
249 | tax_total_amount = 0.0 |
250 | - line_ids = [] |
251 | + amount = 0.0 |
252 | + discount = 0.0 |
253 | + line_ids = [] |
254 | + discount_line_ids = [] |
255 | + |
256 | + discount_account_id = False |
257 | + tax_code_id = False |
258 | + |
259 | for line in invoice.invoice_line: |
260 | + tax_amount = 0.0 |
261 | + line_tax_amount = 0.0 |
262 | + |
263 | + #####get the ratio of the line in the total invoice amount |
264 | + 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): |
265 | + line_tax_amount = tax['amount'] |
266 | + line_total = line.price_subtotal + line_tax_amount |
267 | + invoice_res_amount = invoice.amount_total |
268 | + line_ratio = line_total / invoice_res_amount |
269 | + ########################### |
270 | + |
271 | if line.invoice_line_tax_id: |
272 | 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): |
273 | tax_amount = tax['amount'] |
274 | - tax_total_amount += tax['amount'] |
275 | tax_invoice_id = invoice_tax_obj.search(cr,uid,[('invoice_id','=',invoice.id),('name','=',tax['name'])]) |
276 | for tax_id in tax_invoice_id: |
277 | tax_value = invoice_tax_obj.browse(cr, uid, tax_id) |
278 | tax_account_id = tax_value.account_id.id |
279 | - |
280 | + tax_code_id = tax_value.tax_code_id.id |
281 | + |
282 | l3 = { |
283 | 'debit': direction * tax_amount<0 and - direction * tax_amount, |
284 | 'credit': direction * tax_amount>0 and direction * tax_amount, |
285 | @@ -210,45 +234,42 @@ |
286 | 'period_id':data.get('period_id',False), |
287 | 'name':name, |
288 | 'tax_code_id':tax_value.tax_code_id.id, |
289 | - 'tax_amount':tax_amount, |
290 | + 'tax_amount':-tax_amount, |
291 | } |
292 | - line_id = move_line_obj.create(cr,uid,l3,context=context) |
293 | + line_id = move_line_obj.create(cr, uid, l3, context=context) |
294 | line_ids.append(line_id) |
295 | + |
296 | + ### if calculation on the Net Methology then in discount field it will take product income account or product category income account |
297 | + |
298 | + if data['cal_method_selection'] == 'method_net_methodology': |
299 | + if line.product_id.property_account_income: |
300 | + discount_account_id = line.product_id.property_account_income.id |
301 | + else: |
302 | + discount_account_id = line.product_id.categ_id.property_account_income_categ.id |
303 | + else: |
304 | + discount_account_id = data['account_id'] |
305 | + |
306 | + discount = data['cash_amount'] * line_ratio |
307 | + l4 = { |
308 | + 'debit': direction * (discount - tax_amount)<0 and - direction * (discount - tax_amount), |
309 | + 'credit': direction * (discount - tax_amount)>0 and direction * (discount - tax_amount), |
310 | + 'account_id': discount_account_id, |
311 | + 'partner_id': invoice.partner_id.id, |
312 | + 'ref':ref, |
313 | + 'date': date, |
314 | + 'name':name, |
315 | + 'journal_id':data.get('journal_id',False), |
316 | + 'period_id':data.get('period_id',False), |
317 | + 'tax_code_id':tax_code_id, |
318 | + 'tax_amount':-tax_amount, |
319 | + } |
320 | + |
321 | + discount_line_id = move_line_obj.create(cr, uid, l4, context=context) |
322 | + discount_line_ids.append(discount_line_id) |
323 | + |
324 | self.write(cr, uid, ids, {'tax_move_ids':[(6,0,line_ids)]}, context) |
325 | - |
326 | - ### Entry for discount in the line of wizard discount |
327 | - lines4 = [] |
328 | - if tax_total_amount>0: |
329 | - data['cash_amount'] = (data['cash_amount'] - tax_total_amount) |
330 | - |
331 | - ############################ if method type net methology than discount account journal account |
332 | - discount_account_id = False |
333 | - |
334 | - if data['cal_method_selection'] == 'method_net_methodology': |
335 | - journal_id = data['journal_id'] |
336 | - if context['type'] == 'out_invoice': |
337 | - discount_account_id = self.pool.get('account.journal').browse(cr, uid, journal_id).default_debit_account_id.id |
338 | - else: |
339 | - discount_account_id = self.pool.get('account.journal').browse(cr, uid, journal_id).default_credit_account_id.id |
340 | - else: |
341 | - discount_account_id = data['account_id'] |
342 | - ############################################### |
343 | - |
344 | - l4 = { |
345 | - 'debit': direction * data.get('cash_amount',0.0)<0 and - direction * data.get('cash_amount',0.0), |
346 | - 'credit': direction * data.get('cash_amount',0.0)>0 and direction * data.get('cash_amount',0.0), |
347 | - 'account_id': discount_account_id, |
348 | - 'partner_id': invoice.partner_id.id, |
349 | - 'ref':ref, |
350 | - 'date': date, |
351 | - 'name':name |
352 | - } |
353 | - |
354 | - lines4.append((0, 0, l4)) |
355 | - move = {'ref': ref, 'line_id': lines4, 'journal_id': data['journal_id'], 'period_id': data['period_id'], } |
356 | - move_id = move_obj.create(cr, uid, move, context=context) |
357 | - self.write(cr, uid, ids, {'discount_move_ids':[(6,0,[move_id])]}, context) |
358 | - |
359 | + self.write(cr, uid, ids, {'discount_move_ids':[(6,0,discount_line_ids)]}, context) |
360 | + |
361 | return True |
362 | |
363 | def default_get(self, cr, uid, fields, context=None): |
364 | @@ -296,7 +317,6 @@ |
365 | if context is None: |
366 | context = {} |
367 | data = self.read(cr, uid, ids,context=context)[0] |
368 | - |
369 | invoice = self.pool.get('account.invoice').browse(cr, uid, context['id'], context) |
370 | journal = self.pool.get('account.journal').browse(cr, uid, data['journal_id'], context) |
371 | # Here we need that: |
372 | @@ -327,38 +347,46 @@ |
373 | amount_paid+=abs(debit-credit) |
374 | |
375 | # Test if there is a difference according to currency rouding setting |
376 | - amount = obj_inv._get_amount(cr, uid, [context['id']] ,invoice.residual, invoice.payment_term.id, context=context) |
377 | - found_h = amount['found'] |
378 | - |
379 | - if found_h: |
380 | - if context.get('discount_move_ids',False): |
381 | - context.update({'discount_move_ids':context['discount_move_ids']}) |
382 | - |
383 | - if context.get('tax_move_ids',False): |
384 | - context.update({'tax_move_ids':context['tax_move_ids']}) |
385 | - |
386 | +# amount = obj_inv._get_amount(cr, uid, [context['id']] ,invoice.residual, invoice.payment_term.id, context=context) |
387 | +# |
388 | +# found_h = amount['found'] |
389 | +# |
390 | +# if found_h: |
391 | + |
392 | + ####### Here when we do make full payment then to get the previous Discount and Tax Move added in context |
393 | + |
394 | + if context.get('discount_move_ids',False): |
395 | + context.update({'discount_move_ids':context['discount_move_ids']}) |
396 | + if context.get('tax_move_ids',False): |
397 | + context.update({'tax_move_ids':context['tax_move_ids']}) |
398 | + if context.get('amount',False): |
399 | + context.update({'amount':context['amount']}) |
400 | + if context.get('cash_amount',False): |
401 | + context.update({'cash_amount':context['cash_amount']}) |
402 | + |
403 | +# return self.pay_and_reconcile(cr, uid, ids, context=context) |
404 | +# else: |
405 | + |
406 | + if self.pool.get('res.currency').is_zero(cr, uid, invoice.company_id.currency_id, |
407 | + (amount_paid - inv_amount_company_currency)) or data['cash_residual_amount'] == 0.0: |
408 | return self.pay_and_reconcile(cr, uid, ids, context=context) |
409 | + |
410 | else: |
411 | - |
412 | - if self.pool.get('res.currency').is_zero(cr, uid, invoice.company_id.currency_id, |
413 | - (amount_paid - inv_amount_company_currency)): |
414 | - return self.pay_and_reconcile(cr, uid, ids, context=context) |
415 | - |
416 | - else: |
417 | - model_data_ids = mod_obj.search(cr, uid,[('model','=','ir.ui.view'),('name','=','view_account_invoice_pay_writeoff')], context=context) |
418 | - resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id'] |
419 | - return { |
420 | - 'name': _('Information addendum'), |
421 | - 'context': context, |
422 | - 'view_type': 'form', |
423 | - 'view_mode': 'form', |
424 | - 'res_model': 'account.invoice.pay.writeoff', |
425 | - 'views': [(resource_id,'form')], |
426 | - 'type': 'ir.actions.act_window', |
427 | - 'target': 'new', |
428 | - } |
429 | - |
430 | + model_data_ids = mod_obj.search(cr, uid,[('model','=','ir.ui.view'),('name','=','view_account_invoice_pay_writeoff')], context=context) |
431 | + resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id'] |
432 | + return { |
433 | + 'name': _('Information addendum'), |
434 | + 'context': context, |
435 | + 'view_type': 'form', |
436 | + 'view_mode': 'form', |
437 | + 'res_model': 'account.invoice.pay.writeoff', |
438 | + 'views': [(resource_id,'form')], |
439 | + 'type': 'ir.actions.act_window', |
440 | + 'target': 'new', |
441 | + } |
442 | + |
443 | def pay_and_reconcile(self, cr, uid, ids, context=None): |
444 | + |
445 | cur_obj = self.pool.get('res.currency') |
446 | if context is None: |
447 | context = {} |
448 | @@ -373,8 +401,11 @@ |
449 | writeoff_journal_id = context['write_off']['writeoff_journal_id'] |
450 | comment = context['write_off']['comment'] |
451 | |
452 | - amount = data['amount'] + data['cash_amount'] |
453 | - |
454 | + if context.get('amount',False): |
455 | + amount = context['amount'] + context.get('cash_amount',0.0) |
456 | + else: |
457 | + amount = data['amount'] + data['cash_amount'] |
458 | + |
459 | invoice = self.pool.get('account.invoice').browse(cr, uid, context['id'], context=context) |
460 | journal = self.pool.get('account.journal').browse(cr, uid, data['journal_id'], context=context) |
461 | # Compute the amount in company's currency, with the journal currency (which is equal to payment currency) |
462 | @@ -384,39 +415,52 @@ |
463 | amount = cur_obj.compute(cr, uid, journal.currency.id, invoice.company_id.currency_id.id, amount, context=ctx) |
464 | currency_id = journal.currency.id |
465 | # Put the paid amount in currency, and the currency, in the context if currency is different from company's currency |
466 | - context.update({'amount_currency':data['amount'] + data['cash_amount'],'currency_id':currency_id}) |
467 | + if context.get('amount',False): |
468 | + context.update({'amount_currency':context['amount'] + context.get('cash_amount',0.0),'currency_id':currency_id}) |
469 | + else: |
470 | + context.update({'amount_currency':data['amount'] + data['cash_amount'],'currency_id':currency_id}) |
471 | |
472 | if invoice.company_id.currency_id.id<>invoice.currency_id.id: |
473 | ctx = {'date':data['date']} |
474 | amount = cur_obj.compute(cr, uid, invoice.currency_id.id, invoice.company_id.currency_id.id, amount, context=ctx) |
475 | currency_id = invoice.currency_id.id |
476 | # Put the paid amount in currency, and the currency, in the context if currency is different from company's currency |
477 | - context.update({'amount_currency':data['amount'] + data['cash_amount'],'currency_id':currency_id}) |
478 | - |
479 | - # Take the choosen date |
480 | - if comment: |
481 | - context.update({'date_p':data['date'],'comment':comment}) |
482 | - else: |
483 | - context.update({'date_p':data['date'],'comment':False}) |
484 | - |
485 | - context.update({'account_id':data['account_id'],'cash_amount':data['cash_amount'],'amount_currency':data['amount'] + data['cash_amount']}) |
486 | + if context.get('amount',False): |
487 | + context.update({'amount_currency':context['amount'] + context.get('cash_amount',0.0),'currency_id':currency_id}) |
488 | + else: |
489 | + context.update({'amount_currency':data['amount'] + data['cash_amount'],'currency_id':currency_id}) |
490 | + |
491 | + context.update({'account_id':data['account_id'],'date_p':data['date'],'comment':comment or False}) |
492 | |
493 | if context.get('discount_move_ids',False): |
494 | - context = context |
495 | + context.update({'discount_move_ids':context['discount_move_ids']}) |
496 | else: |
497 | context.update({'discount_move_ids':data['discount_move_ids']}) |
498 | |
499 | if context.get('tax_move_ids',False): |
500 | - context = context |
501 | + context.update({'tax_move_ids':context['tax_move_ids']}) |
502 | else: |
503 | context.update({'tax_move_ids':data['tax_move_ids']}) |
504 | |
505 | - if data['cash_amount']: |
506 | + if context.get('cash_amount',False): |
507 | + cash_amount = context['cash_amount'] |
508 | + context.update({'cash_amount':context['cash_amount']}) |
509 | + else: |
510 | + cash_amount = data['cash_amount'] |
511 | context.update({'cash_amount':data['cash_amount']}) |
512 | - |
513 | + |
514 | + if journal.currency and invoice.company_id.currency_id.id<>journal.currency.id: |
515 | + cash_amount = cur_obj.compute(cr, uid, journal.currency.id, invoice.company_id.currency_id.id, cash_amount, context=ctx) |
516 | + context.update({'cash_amount':cash_amount}) |
517 | + |
518 | + if invoice.company_id.currency_id.id<>invoice.currency_id.id: |
519 | + cash_amount = cur_obj.compute(cr, uid, journal.currency.id, invoice.company_id.currency_id.id, cash_amount, context=ctx) |
520 | + context.update({'cash_amount':cash_amount}) |
521 | + |
522 | acc_id = journal.default_credit_account_id and journal.default_credit_account_id.id |
523 | if not acc_id: |
524 | raise osv.except_osv(_('Error !'), _('Your journal must have a default credit and debit account.')) |
525 | + |
526 | self.pool.get('account.invoice').pay_and_reconcile(cr, uid, [context['id']], |
527 | amount, acc_id, data['period_id'], data['journal_id'], writeoff_account_id, |
528 | data['period_id'], writeoff_journal_id, context, data['name']) |
529 | @@ -435,7 +479,28 @@ |
530 | if 'Customers Cash Discount Account' in res['fields'][f]['string']: |
531 | res['fields'][f]['string'] = res['fields'][f]['string'].replace('Customers Cash Discount Account',word) |
532 | return res |
533 | - |
534 | + |
535 | + def _cancel_line(self, cr, uid, ids, context=None): |
536 | + move_obj = self.pool.get('account.move') |
537 | + move_line_obj = self.pool.get('account.move.line') |
538 | + data = self.read(cr, uid, ids,context=context)[0] |
539 | + |
540 | + if data['tax_move_ids']: |
541 | + move_line = data['tax_move_ids'] |
542 | + for move_line_id in move_line: |
543 | + move_id = move_line_obj.browse(cr, uid,move_line_id).move_id.id |
544 | + move_line_obj.unlink(cr, uid,[move_line_id]) |
545 | + move_obj.unlink(cr, uid,[move_id]) |
546 | + |
547 | + if data['discount_move_ids']: |
548 | + discount_move_line = data['discount_move_ids'] |
549 | + for move_line_id in discount_move_line: |
550 | + move_id = move_line_obj.browse(cr, uid,move_line_id).move_id.id |
551 | + move_line_obj.unlink(cr, uid,[move_line_id]) |
552 | + move_obj.unlink(cr, uid,[move_id]) |
553 | + |
554 | + return {} |
555 | + |
556 | account_invoice_pay() |
557 | |
558 | class account_message(osv.osv_memory): |
559 | |
560 | === modified file 'account_invoice_cash_discount/wizard/account_pay_invoice_view.xml' |
561 | --- account_invoice_cash_discount/wizard/account_pay_invoice_view.xml 2010-08-21 12:43:18 +0000 |
562 | +++ account_invoice_cash_discount/wizard/account_pay_invoice_view.xml 2010-07-14 12:24:45 +0000 |
563 | @@ -32,7 +32,7 @@ |
564 | </group> |
565 | <group colspan="4" col="6"> |
566 | <label string ="" colspan="2"/> |
567 | - <button icon="gtk-cancel" special="cancel" string="Cancel"/> |
568 | + <button icon="gtk-cancel" string="Cancel" name="_cancel_line" type="object"/> |
569 | <button icon="gtk-execute" string="Partial Payment" name="pay_and_reconcile" type="object"/> |
570 | <button icon="gtk-execute" string="Full-Payment" name="_message" type="object"/> |
571 | </group> |
572 | |
573 | === modified file 'account_invoice_cash_discount/wizard/invoice_statement_payment.py' |
574 | --- account_invoice_cash_discount/wizard/invoice_statement_payment.py 2010-06-30 05:22:29 +0000 |
575 | +++ account_invoice_cash_discount/wizard/invoice_statement_payment.py 2010-07-14 12:24:45 +0000 |
576 | @@ -134,7 +134,7 @@ |
577 | amount=line.debit |
578 | elif line.credit > 0: |
579 | amount=-line.credit |
580 | - |
581 | + print "amount::::::",amount |
582 | reconcile_id = statement_reconcile_obj.create(cursor, user, { |
583 | 'line_ids': [(6, 0, [line.id])] |
584 | }, context=context) |
585 | @@ -145,13 +145,17 @@ |
586 | discount = 0.0 |
587 | account = False |
588 | tax_total_amount = 0.0 |
589 | - |
590 | + total_discount = 0.0 |
591 | invoice = obj_inv.browse(cursor, user, line.invoice.id, context=context) |
592 | - discount = obj_inv._get_payment(cursor, user, [invoice.id] , invoice.residual, invoice.payment_term.id, context=context) |
593 | - account = obj_inv._get_account(cursor, user, [invoice.id] , invoice.residual, invoice.payment_term.id, context=context) |
594 | |
595 | for invoice_line in invoice.invoice_line: |
596 | if invoice_line.invoice_line_tax_id: |
597 | + amount_invoice_line = obj_inv._get_amount(cursor, user, [invoice.id] , invoice_line.price_subtotal, invoice.payment_term.id, context=context) |
598 | + line_amount = amount_invoice_line['amount'] |
599 | + discount = obj_inv._get_payment(cursor, user, [invoice.id] , line_amount, invoice.payment_term.id, context=context) |
600 | + account = obj_inv._get_account(cursor, user, [invoice.id] , invoice.residual, invoice.payment_term.id, context=context) |
601 | + |
602 | + tax_amount = 0.0 |
603 | 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): |
604 | tax_amount = tax['amount'] |
605 | tax_total_amount += tax['amount'] |
606 | @@ -167,13 +171,15 @@ |
607 | 'account_id': tax_account_id, |
608 | 'line_id': reconcile_id, |
609 | }, context=context) |
610 | - if discount>0: |
611 | - statement_reconcile_line_obj.create(cursor, user, { |
612 | - 'name': line.name, |
613 | - 'amount': discount - tax_total_amount, |
614 | - 'account_id': account, |
615 | - 'line_id': reconcile_id, |
616 | - }, context=context) |
617 | + |
618 | + if discount>0: |
619 | + total_discount += discount |
620 | + statement_reconcile_line_obj.create(cursor, user, { |
621 | + 'name': line.name, |
622 | + 'amount': discount - tax_amount, |
623 | + 'account_id': account, |
624 | + 'line_id': reconcile_id, |
625 | + }, context=context) |
626 | ########################################################################## |
627 | |
628 | if line.journal_id.type == 'sale': |
629 | @@ -182,6 +188,7 @@ |
630 | type = 'supplier' |
631 | else: |
632 | type = 'general' |
633 | + |
634 | statement_line_obj.create(cursor, user, { |
635 | 'name': line.name or '?', |
636 | 'amount': amount, |