[FIX] account_voucher: validation of refund in multicurrency

Fixing several issues for refunds in multicurrency mode that prevented the moves to be balanced.
The amount_currency needs to use the absolute value, as a refund will have a negative amount.
The sign for currency_rate_difference needs to use the line instead of the voucher as they can have different value. e.g. a voucher of 1000$ with invoice of 1200$ and refund of 200$ will have two lines and their currency_rate_difference should have different signs.
Avoids doubling the value in foreign_currency_diff
Fixes #1490, opw 607118 & 611580
This commit is contained in:
Martin Trigaux 2014-08-06 14:51:48 +02:00
parent d909f763b8
commit 02f0caf1b8
1 changed files with 4 additions and 4 deletions

View File

@ -1055,7 +1055,8 @@ class account_voucher(osv.osv):
'period_id': voucher.period_id.id,
'partner_id': voucher.partner_id.id,
'currency_id': company_currency <> current_currency and current_currency or False,
'amount_currency': company_currency <> current_currency and sign * voucher.amount or 0.0,
'amount_currency': (sign * abs(voucher.amount) # amount < 0 for refunds
if company_currency != current_currency else 0.0),
'date': voucher.date,
'date_maturity': voucher.date_due
}
@ -1217,7 +1218,7 @@ class account_voucher(osv.osv):
if line.amount == line.amount_unreconciled:
if not line.move_line_id:
raise osv.except_osv(_('Wrong voucher line'),_("The invoice you are willing to pay is not valid anymore."))
sign = voucher.type in ('payment', 'purchase') and -1 or 1
sign = line.type =='dr' and -1 or 1
currency_rate_difference = sign * (line.move_line_id.amount_residual - amount)
else:
currency_rate_difference = 0.0
@ -1275,8 +1276,7 @@ class account_voucher(osv.osv):
# otherwise we use the rates of the system
amount_currency = currency_obj.compute(cr, uid, company_currency, line.move_line_id.currency_id.id, move_line['debit']-move_line['credit'], context=ctx)
if line.amount == line.amount_unreconciled:
sign = voucher.type in ('payment', 'purchase') and -1 or 1
foreign_currency_diff = sign * line.move_line_id.amount_residual_currency + amount_currency
foreign_currency_diff = line.move_line_id.amount_residual_currency - abs(amount_currency)
move_line['amount_currency'] = amount_currency
voucher_line = move_line_obj.create(cr, uid, move_line)