diff --git a/CHANGELOG b/CHANGELOG index d28f483b7f..de5cd9185d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Use the right currency to compute balance, debit/credit of accounts + Version 1.2.0 - 2009-04-20 * Bug fixes (see mercurial logs for details) * Allow egg installation diff --git a/account.py b/account.py index f5f267f77f..e24b0fc729 100644 --- a/account.py +++ b/account.py @@ -133,16 +133,22 @@ class Account(ModelSQL, ModelView): line_query = line_obj.query_get(cursor, user, context=context) cursor.execute('SELECT a.id, ' \ 'SUM((COALESCE(l.debit, 0) - COALESCE(l.credit, 0))), ' \ - 'l.currency ' \ + 'c.currency ' \ 'FROM analytic_account_account a ' \ 'LEFT JOIN analytic_account_line l ' \ 'ON (a.id = l.account) ' \ + 'LEFT JOIN account_move_line ml ' \ + 'ON (ml.id = l.move_line) ' \ + 'LEFT JOIN account_account aa ' \ + 'ON (aa.id = ml.account) ' \ + 'LEFT JOIN company_company c ' \ + 'ON (c.id = aa.company) ' \ 'WHERE a.type != \'view\' ' \ 'AND a.id IN (' + \ ','.join(['%s' for x in all_ids]) + ') ' \ 'AND ' + line_query + ' ' \ 'AND a.active ' \ - 'GROUP BY a.id, l.currency', all_ids) + 'GROUP BY a.id, c.currency', all_ids) account_sum = {} id2currency = {} for account_id, sum, currency_id in cursor.fetchall(): @@ -196,16 +202,22 @@ class Account(ModelSQL, ModelView): line_query = line_obj.query_get(cursor, user, context=context) cursor.execute('SELECT a.id, ' \ 'SUM(COALESCE(l.' + name + ', 0)), ' \ - 'l.currency ' \ + 'c.currency ' \ 'FROM analytic_account_account a ' \ 'LEFT JOIN analytic_account_line l ' \ 'ON (a.id = l.account) ' \ + 'LEFT JOIN account_move_line ml ' \ + 'ON (ml.id = l.move_line) ' \ + 'LEFT JOIN account_account aa ' \ + 'ON (aa.id = ml.account) ' \ + 'LEFT JOIN company_company c ' \ + 'ON (c.id = aa.company) ' \ 'WHERE a.type != \'view\' ' \ 'AND a.id IN (' + \ ','.join(['%s' for x in ids]) + ') ' \ 'AND ' + line_query + ' ' \ 'AND a.active ' \ - 'GROUP BY a.id, l.currency', ids) + 'GROUP BY a.id, c.currency', ids) id2currency = {} for account_id, sum, currency_id in cursor.fetchall(): diff --git a/line.py b/line.py index 59d51aa9b3..28ea0f09fd 100644 --- a/line.py +++ b/line.py @@ -14,6 +14,7 @@ class Line(ModelSQL, ModelView): name = fields.Char('Name', required=True) debit = fields.Numeric('Debit', digits=(16, 2)) credit = fields.Numeric('Credit', digits=(16, 2)) + #TODO wrong field as currency comes from move_line currency = fields.Many2One('currency.currency', 'Currency', required=True) account = fields.Many2One('analytic_account.account', 'Account', required=True, select=1, domain=[('type', '!=', 'view')])