[MERGE] forward port of branch 8.0 up to 2b192be
[odoo/odoo.git] / addons / account / res_config.py
index beaad7f..4e870b7 100644 (file)
@@ -144,16 +144,6 @@ class account_config_settings(osv.osv_memory):
             string="Loss Exchange Rate Account",
             domain="[('type', '=', 'other')]"),
     }
-    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)
-        if company_id:
-            company = self.pool.get('res.company').browse(cr, uid, company_id, context=context)
-            res['value'].update({'income_currency_exchange_account_id': company.income_currency_exchange_account_id and company.income_currency_exchange_account_id.id or False, 
-                                 'expense_currency_exchange_account_id': company.expense_currency_exchange_account_id and company.expense_currency_exchange_account_id.id or False})
-        else: 
-            res['value'].update({'income_currency_exchange_account_id': False, 
-                                 'expense_currency_exchange_account_id': False})
-        return res
 
     def _default_company(self, cr, uid, context=None):
         user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
@@ -196,7 +186,6 @@ class account_config_settings(osv.osv_memory):
             else:
                 return (time.strftime('%Y-01-01'), time.strftime('%Y-12-31'), 'month')
 
-
     _defaults = {
         'company_id': _default_company,
         'has_default_company': _default_has_default_company,
@@ -258,6 +247,12 @@ class account_config_settings(osv.osv_memory):
                 'default_sale_tax': isinstance(taxes_id, list) and taxes_id[0] or taxes_id,
                 'default_purchase_tax': isinstance(supplier_taxes_id, list) and supplier_taxes_id[0] or supplier_taxes_id,
             })
+            # update gain/loss exchange rate accounts
+            values.update({
+                'income_currency_exchange_account_id': company.income_currency_exchange_account_id and company.income_currency_exchange_account_id.id or False,
+                'expense_currency_exchange_account_id': company.expense_currency_exchange_account_id and company.expense_currency_exchange_account_id.id or False
+            })
+
         return {'value': values}
 
     def onchange_chart_template_id(self, cr, uid, ids, chart_template_id, context=None):