From 3c71cd0697d95da94eca98c3133018ecbc9bff42 Mon Sep 17 00:00:00 2001 From: "qdp-launchpad@tinyerp.com" <> Date: Wed, 5 Jan 2011 14:34:15 +0100 Subject: [PATCH] [FIX] account: forward port of the fix of the reconcile method on account.move.line in cases of multi-currency uses bzr revid: qdp-launchpad@tinyerp.com-20110105133415-hdx72lmvi3f7scvb --- addons/account/account_move_line.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/addons/account/account_move_line.py b/addons/account/account_move_line.py index 2522e53b2a0..73e03629da9 100644 --- a/addons/account/account_move_line.py +++ b/addons/account/account_move_line.py @@ -771,6 +771,19 @@ class account_move_line(osv.osv): libelle = context['comment'] else: libelle = _('Write-Off') + + cur_obj = self.pool.get('res.currency') + cur_id = False + amount_currency_writeoff = 0.0 + if context.get('company_currency_id',False) != context.get('currency_id',False): + cur_id = context.get('currency_id',False) + for line in unrec_lines: + if line.currency_id and line.currency_id.id == context.get('currency_id',False): + amount_currency_writeoff += line.amount_currency + else: + tmp_amount = cur_obj.compute(cr, uid, line.account_id.company_id.currency_id.id, context.get('currency_id',False), abs(line.debit-line.credit), context={'date': line.date}) + amount_currency_writeoff += (line.debit > 0) and tmp_amount or -tmp_amount + writeoff_lines = [ (0, 0, { 'name': libelle, @@ -779,8 +792,8 @@ class account_move_line(osv.osv): 'account_id': account_id, 'date': date, 'partner_id': partner_id, - 'currency_id': account.currency_id.id or False, - 'amount_currency': account.currency_id.id and -currency or 0.0 + 'currency_id': cur_id or (account.currency_id.id or False), + 'amount_currency': amount_currency_writeoff and -1 * amount_currency_writeoff or (account.currency_id.id and -1 * currency or 0.0) }), (0, 0, { 'name': libelle, @@ -789,7 +802,9 @@ class account_move_line(osv.osv): 'account_id': writeoff_acc_id, 'analytic_account_id': context.get('analytic_id', False), 'date': date, - 'partner_id': partner_id + 'partner_id': partner_id, + 'currency_id': cur_id or (account.currency_id.id or False), + 'amount_currency': amount_currency_writeoff and amount_currency_writeoff or (account.currency_id.id and currency or 0.0) }) ] @@ -802,6 +817,8 @@ class account_move_line(osv.osv): }) writeoff_line_ids = self.search(cr, uid, [('move_id', '=', writeoff_move_id), ('account_id', '=', account_id)]) + if account_id == writeoff_acc_id: + writeoff_line_ids = [writeoff_line_ids[1]] ids += writeoff_line_ids r_id = move_rec_obj.create(cr, uid, { @@ -1283,4 +1300,4 @@ class account_move_line(osv.osv): account_move_line() -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: