Merge lp:~zaber/openobject-addons/refund-payment into lp:openobject-addons/6.1

Proposed by Don Kirkby
Status: Needs review
Proposed branch: lp:~zaber/openobject-addons/refund-payment
Merge into: lp:openobject-addons/6.1
Diff against target: 110 lines (+18/-8)
2 files modified
account_voucher/account_voucher.py (+14/-7)
account_voucher/invoice.py (+4/-1)
To merge this branch: bzr merge lp:~zaber/openobject-addons/refund-payment
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+159906@code.launchpad.net

Description of the change

Fix for bug 865854 that handles foreign currencies.

To post a comment you must log in.

Unmerged revisions

7186. By Don Kirkby

[IMP] Default a negative payment amount when paying a refund.

7185. By Don Kirkby

[FIX] Handle foreign currencies correctly when paying a refund.

7184. By Don Kirkby

[MERGE] 6.1-opw-574543-pso fix for refund payment.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account_voucher/account_voucher.py'
2--- account_voucher/account_voucher.py 2012-12-05 17:57:01 +0000
3+++ account_voucher/account_voucher.py 2013-04-19 23:32:27 +0000
4@@ -192,7 +192,7 @@
5 debit += l['amount']
6 for l in line_cr_ids:
7 credit += l['amount']
8- return abs(amount - abs(credit - debit))
9+ return abs(abs(amount) - abs(credit - debit))
10
11 def onchange_line_ids(self, cr, uid, ids, line_dr_ids, line_cr_ids, amount, voucher_currency, context=None):
12 context = context or {}
13@@ -221,7 +221,7 @@
14 for l in voucher.line_cr_ids:
15 credit += l.amount
16 currency = voucher.currency_id or voucher.company_id.currency_id
17- res[voucher.id] = currency_obj.round(cr, uid, currency, abs(voucher.amount - abs(credit - debit)))
18+ res[voucher.id] = currency_obj.round(cr, uid, currency, abs(abs(voucher.amount) - abs(credit - debit)))
19 return res
20
21 def _paid_amount_in_company_currency(self, cr, uid, ids, name, args, context=None):
22@@ -238,7 +238,7 @@
23 voucher_rate = self.browse(cr, uid, voucher.id, context=ctx).currency_id.rate
24 company_currency_rate = voucher.company_id.currency_id.rate
25 rate = voucher_rate * company_currency_rate
26- res[voucher.id] = self.pool.get('res.currency').round(cr, uid, voucher.company_id.currency_id, (voucher.amount / rate))
27+ res[voucher.id] = self.pool.get('res.currency').round(cr, uid, voucher.company_id.currency_id, (voucher.amount * rate))
28 return res
29
30 _name = 'account.voucher'
31@@ -276,7 +276,7 @@
32 \n* The \'Pro-forma\' when voucher is in Pro-forma state,voucher does not have an voucher number. \
33 \n* The \'Posted\' state is used when user create voucher,a voucher number is generated and voucher entries are created in account \
34 \n* The \'Cancelled\' state is used when user cancel voucher.'),
35- 'amount': fields.float('Total', digits_compute=dp.get_precision('Account'), required=True, readonly=True, states={'draft':[('readonly',False)]}),
36+ 'amount': fields.float('Total', digits_compute=dp.get_precision('Account'), required=True, readonly=True, states={'draft':[('readonly',False)]}, help="During refund payment, add negative amount."),
37 'tax_amount':fields.float('Tax Amount', digits_compute=dp.get_precision('Account'), readonly=True, states={'draft':[('readonly',False)]}),
38 'reference': fields.char('Ref #', size=64, readonly=True, states={'draft':[('readonly',False)]}, help="Transaction reference number."),
39 'number': fields.char('Number', size=32, readonly=True,),
40@@ -674,6 +674,7 @@
41 amount = min(amount_unreconciled, abs(total_credit))
42 rs['amount'] = amount
43 total_credit -= amount
44+ rs['amount'] = abs(rs['amount'])
45
46 if rs['amount_unreconciled'] == rs['amount']:
47 rs['reconcile'] = True
48@@ -869,7 +870,7 @@
49 'period_id': voucher_brw.period_id.id,
50 'partner_id': voucher_brw.partner_id.id,
51 'currency_id': company_currency <> current_currency and current_currency or False,
52- 'amount_currency': company_currency <> current_currency and sign * voucher_brw.amount or 0.0,
53+ 'amount_currency': company_currency <> current_currency and sign * abs(voucher_brw.amount) or 0.0,
54 'date': voucher_brw.date,
55 'date_maturity': voucher_brw.date_due
56 }
57@@ -1024,6 +1025,12 @@
58 # currency rate difference
59 if line.amount == line.amount_unreconciled:
60 currency_rate_difference = line.move_line_id.amount_residual - amount
61+ if voucher_brw.type in ('payment', 'purchase'):
62+ if line.type == 'cr':
63+ currency_rate_difference *= -1
64+ else:
65+ if line.type == 'dr':
66+ currency_rate_difference *= -1
67 else:
68 currency_rate_difference = 0.0
69 move_line = {
70@@ -1084,7 +1091,7 @@
71 # otherwise we use the rates of the system (giving the voucher date in the context)
72 amount_currency = currency_obj.compute(cr, uid, company_currency, line.move_line_id.currency_id.id, move_line['debit']-move_line['credit'], context=ctx)
73 if line.amount == line.amount_unreconciled and line.move_line_id.currency_id.id == voucher_currency:
74- sign = voucher_brw.type in ('payment', 'purchase') and -1 or 1
75+ sign = line.type == 'dr' and -1 or 1
76 foreign_currency_diff = sign * line.move_line_id.amount_residual_currency + amount_currency
77
78 move_line['amount_currency'] = amount_currency
79@@ -1461,7 +1468,7 @@
80 def _check_amount(self, cr, uid, ids, context=None):
81 for obj in self.browse(cr, uid, ids, context=context):
82 if obj.voucher_id:
83- diff = abs(obj.amount) - obj.voucher_id.amount
84+ diff = abs(obj.amount) - abs(obj.voucher_id.amount)
85 if not self.pool.get('res.currency').is_zero(cr, uid, obj.statement_id.currency, diff):
86 return False
87 return True
88
89=== modified file 'account_voucher/invoice.py'
90--- account_voucher/invoice.py 2011-10-27 21:11:24 +0000
91+++ account_voucher/invoice.py 2013-04-19 23:32:27 +0000
92@@ -28,6 +28,9 @@
93 def invoice_pay_customer(self, cr, uid, ids, context=None):
94 if not ids: return []
95 inv = self.browse(cr, uid, ids[0], context=context)
96+ default_amount = inv.residual
97+ if inv.type in ('out_refund', 'in_refund'):
98+ default_amount *= -1
99 return {
100 'name':_("Pay Invoice"),
101 'view_mode': 'form',
102@@ -40,7 +43,7 @@
103 'domain': '[]',
104 'context': {
105 'default_partner_id': inv.partner_id.id,
106- 'default_amount': inv.residual,
107+ 'default_amount': default_amount,
108 'default_name':inv.name,
109 'close_after_process': True,
110 'invoice_type':inv.type,