diff --git a/addons/account/account.py b/addons/account/account.py index da2a74f5353..0bf8a6ef713 100644 --- a/addons/account/account.py +++ b/addons/account/account.py @@ -3070,22 +3070,23 @@ class wizard_multi_charts_accounts(osv.osv_memory): 'complete_tax_set': fields.boolean('Complete Set of Taxes', help='This boolean helps you to choose if you want to propose to the user to encode the sales and purchase rates or use the usual m2o fields. This last choice assumes that the set of tax defined for the chosen template is complete'), } - def onchange_company_id(self, cr, uid, ids, company_id, context=None): - currency_id = False - if company_id: - currency_id = self.pool.get('res.company').browse(cr, uid, company_id, context=context).currency_id.id - return {'value': {'currency_id': currency_id}} - def onchange_tax_rate(self, cr, uid, ids, rate=False, context=None): return {'value': {'purchase_tax_rate': rate or False}} def onchange_chart_template_id(self, cr, uid, ids, chart_template_id=False, context=None): res = {} tax_templ_obj = self.pool.get('account.tax.template') + ir_values = self.pool.get('ir.values') res['value'] = {'complete_tax_set': False, 'sale_tax': False, 'purchase_tax': False} if chart_template_id: data = self.pool.get('account.chart.template').browse(cr, uid, chart_template_id, context=context) - res['value'].update({'complete_tax_set': data.complete_tax_set}) + #set currecy_id based on selected COA template using ir.vaalues else current users company's currency + value_id = ir_values.search(cr, uid, [('model', '=', 'account.chart.template'), ('res_id', '=', chart_template_id)], limit=1, context=context) + if value_id: + currency_id = int(ir_values.browse(cr, uid, value_id[0], context=context).value) + else: + currency_id = self.pool.get('res.users').browse(cr, uid, uid, context=context).company_id.currency_id.id + res['value'].update({'complete_tax_set': data.complete_tax_set, 'currency_id': currency_id}) if data.complete_tax_set: # default tax is given by the lowest sequence. For same sequence we will take the latest created as it will be the case for tax created while isntalling the generic chart of account sale_tax_ids = tax_templ_obj.search(cr, uid, [("chart_template_id" @@ -3101,6 +3102,7 @@ class wizard_multi_charts_accounts(osv.osv_memory): def default_get(self, cr, uid, fields, context=None): res = super(wizard_multi_charts_accounts, self).default_get(cr, uid, fields, context=context) tax_templ_obj = self.pool.get('account.tax.template') + data_obj = self.pool.get('ir.model.data') if 'bank_accounts_id' in fields: res.update({'bank_accounts_id': [{'acc_name': _('Cash'), 'account_type': 'cash'},{'acc_name': _('Bank'), 'account_type': 'bank'}]}) @@ -3117,7 +3119,12 @@ class wizard_multi_charts_accounts(osv.osv_memory): ids = self.pool.get('account.chart.template').search(cr, uid, [('visible', '=', True)], context=context) if ids: if 'chart_template_id' in fields: - res.update({'only_one_chart_template': len(ids) == 1, 'chart_template_id': ids[0]}) + #in order to set default chart which was last created set max of ids. + chart_id = max(ids) + if context.get("default_charts"): + data_id = data_obj.search(cr, uid, [('model', '=', 'account.chart.template'), ('module', '=', context.get("default_charts"))], context=context) + chart_id = data_obj.browse(cr, uid, data_id[0], context=context).res_id + res.update({'only_one_chart_template': len(ids) == 1, 'chart_template_id': chart_id}) if 'sale_tax' in fields: sale_tax_ids = tax_templ_obj.search(cr, uid, [("chart_template_id" , "=", ids[0]), ('type_tax_use', 'in', ('sale','all'))], order="sequence") diff --git a/addons/account/account_installer.xml b/addons/account/account_installer.xml index b03babc63ac..8d1b25b299f 100644 --- a/addons/account/account_installer.xml +++ b/addons/account/account_installer.xml @@ -10,7 +10,7 @@ diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml index 10d9bf786f7..16ba8f4a8dd 100644 --- a/addons/account/account_view.xml +++ b/addons/account/account_view.xml @@ -2125,7 +2125,7 @@ - +