From 901a88bf256524b778052315e3d039fa13a0c86d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thibault=20Delavall=C3=A9e?= Date: Mon, 13 Feb 2012 16:03:22 +0100 Subject: [PATCH] [IMP] When trying to launch the Chart of Accounts configuration wizard, there is now a check of the number of unconfigured companies. This prevents from having a wizard impossible to execute due to the lack of company_id. Also cleaned a bit the code in account_view.xml (ir_actions_server_action_wizard_multi_chart id). bzr revid: tde@openerp.com-20120213150322-a8d6kx5047r0sdd9 --- addons/account/account_view.xml | 11 ++++++++--- addons/account/installer.py | 16 ++++++++++++---- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/addons/account/account_view.xml b/addons/account/account_view.xml index 8790712..a7d3eb2 100644 --- a/addons/account/account_view.xml +++ b/addons/account/account_view.xml @@ -2491,11 +2491,16 @@ -act_window_ids = pool.get('ir.actions.act_window').search(cr, uid,[('name', 'in', ('Accounting Chart Configuration', 'Generate Chart of Accounts from a Chart Template'))], context=context) +account_installer_obj = self.pool.get('account.installer') +account_installer_obj.check_unconfigured_cmp(cr, uid, context=context) +action_ids = [] +ref = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'account', 'action_wizard_multi_chart') +if ref: + action_ids += [ref[1]] ref = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'account', 'action_account_configuration_installer') if ref: - act_window_ids += [ref[1]] -todo_ids = pool.get('ir.actions.todo').search(cr, uid, [('action_id', 'in', act_window_ids)], context=context) + action_ids += [ref[1]] +todo_ids = pool.get('ir.actions.todo').search(cr, uid, [('action_id', 'in', action_ids)], context=context) pool.get('ir.actions.todo').write(cr, uid, todo_ids, {'state':'open'}, context=context) action = pool.get('res.config').next(cr, uid, [], context) diff --git a/addons/account/installer.py b/addons/account/installer.py index d1b19ef..e7b8efa 100644 --- a/addons/account/installer.py +++ b/addons/account/installer.py @@ -78,15 +78,23 @@ class account_installer(osv.osv_memory): 'has_default_company': _default_has_default_company, 'charts': 'configurable' } - - def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): - res = super(account_installer, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar,submenu=False) + + def get_unconfigured_cmp(self, cr, uid, context=None): cmp_select = [] company_ids = self.pool.get('res.company').search(cr, uid, [], context=context) - #display in the widget selection of companies, only the companies that haven't been configured yet (but don't care about the demo chart of accounts) cr.execute("SELECT company_id FROM account_account WHERE active = 't' AND account_account.parent_id IS NULL AND name != %s", ("Chart For Automated Tests",)) configured_cmp = [r[0] for r in cr.fetchall()] unconfigured_cmp = list(set(company_ids)-set(configured_cmp)) + return unconfigured_cmp + + def check_unconfigured_cmp(self, cr, uid, context=None): + if not self.get_unconfigured_cmp(cr, uid, context=context): + raise osv.except_osv(_('No unconfigured company !'), _("There are currently no company without chart of account. The wizard will therefore not be executed.")) + + def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): + res = super(account_installer, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar,submenu=False) + cmp_select = [] + unconfigured_cmp = self.get_unconfigured_cmp(cr, uid, context=context) for field in res['fields']: if field == 'company_id': res['fields'][field]['domain'] = [('id','in',unconfigured_cmp)] -- 1.7.10.4