From 1b2c400fc13d85318a71ae9cb49b46bfeccadf23 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Wed, 18 Mar 2015 13:33:47 +0100 Subject: [PATCH] [FIX] account_voucher: consistency between exchange rate account and company In the accounting settings, we prevent having gain and loss accounts that are linked to a different company than the one selected for the chart of account. opw: 630494 --- addons/account_voucher/account_voucher.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/addons/account_voucher/account_voucher.py b/addons/account_voucher/account_voucher.py index 25046a68ed6..66da370e2f7 100644 --- a/addons/account_voucher/account_voucher.py +++ b/addons/account_voucher/account_voucher.py @@ -70,13 +70,13 @@ class account_config_settings(osv.osv_memory): type='many2one', relation='account.account', string="Gain Exchange Rate Account", - domain="[('type', '=', 'other')]"), + domain="[('type', '=', 'other'), ('company_id', '=', company_id)]"), 'expense_currency_exchange_account_id': fields.related( 'company_id', 'expense_currency_exchange_account_id', type="many2one", relation='account.account', string="Loss Exchange Rate Account", - domain="[('type', '=', 'other')]"), + domain="[('type', '=', 'other'), ('company_id', '=', company_id)]"), } def onchange_company_id(self, cr, uid, ids, company_id, context=None): res = super(account_config_settings, self).onchange_company_id(cr, uid, ids, company_id, context=context) @@ -89,6 +89,23 @@ class account_config_settings(osv.osv_memory): 'expense_currency_exchange_account_id': False}) return res + def _check_account_gain(self, cr, uid, ids, context=None): + for obj in self.browse(cr, uid, ids, context=context): + if obj.income_currency_exchange_account_id.company_id and obj.company_id != obj.income_currency_exchange_account_id.company_id: + return False + return True + + def _check_account_loss(self, cr, uid, ids, context=None): + for obj in self.browse(cr, uid, ids, context=context): + if obj.expense_currency_exchange_account_id.company_id and obj.company_id != obj.expense_currency_exchange_account_id.company_id: + return False + return True + + _constraints = [ + (_check_account_gain, 'The company of the gain exchange rate account must be the same than the company selected.', ['income_currency_exchange_account_id']), + (_check_account_loss, 'The company of the loss exchange rate account must be the same than the company selected.', ['expense_currency_exchange_account_id']), + ] + class account_voucher(osv.osv): def _check_paid(self, cr, uid, ids, name, args, context=None): res = {}