From 4548d730475a0d2e389ab0a438c68685e6cfc8f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Thu, 28 Feb 2008 17:28:10 +0100 Subject: [PATCH] Add framework to handle configuration wizard - One object where module subscribe the configuration wizards - One wizard that loop throw all the open configuration wizards --- trytond/ir/module/module.py | 96 ++++++++++++++++++++++++++++++++++++ trytond/ir/module/module.xml | 50 +++++++++++++++++++ 2 files changed, 146 insertions(+) diff --git a/trytond/ir/module/module.py b/trytond/ir/module/module.py index 1d0839ea23..0e5e0f7665 100644 --- a/trytond/ir/module/module.py +++ b/trytond/ir/module/module.py @@ -449,6 +449,102 @@ class ModuleDependency(OSV): ModuleDependency() +class ModuleConfigWizardItem(OSV): + "Config wizard to run after installing module" + _name = 'ir.module.module.config_wizard.item' + _description = __doc__ + name = fields.Char('Name', size=64, required=True, readonly=True) + sequence= fields.Integer('Sequence') + state = fields.Selection([ + ('open', 'Open'), + ('done', 'Done'), + ], string='State', required=True) + _order = 'sequence' + + def default_state(self, cursor, user, context=None): + return 'open' + + def default_sequence(self, cursor, user, context=None): + return 10 + +ModuleConfigWizardItem() + + +class ModuleConfigWizardFirst(WizardOSV): + _name = 'ir.module.module.config_wizard.first' + +ModuleConfigWizardFirst() + + +class ModuleConfigWizard(Wizard): + 'Run config wizards' + _name = 'ir.module.module.config_wizard' + states = { + 'init': { + 'result': { + 'type': 'choice', + 'next_state': '_first', + }, + }, + 'first': { + 'result': { + 'type': 'form', + 'object': 'ir.module.module.config_wizard.first', + 'state': [ + ('end', 'Cancel', 'gtk-cancel'), + ('wizard', 'Ok', 'gtk-ok', True), + ], + }, + }, + 'wizard': { + 'result': { + 'type': 'action', + 'action': '_action_wizard', + 'state': 'next', + }, + }, + 'next': { + 'result': { + 'type': 'choice', + 'next_state': '_next', + }, + }, + } + + def _first(self, cursor, user, data, context=None): + res = self._next(cursor, user, data, context=context) + if res == 'wizard': + return 'first' + return res + + def _action_wizard(self, cursor, user, data, context=None): + item_obj = self.pool.get('ir.module.module.config_wizard.item') + item_ids = item_obj.search(cursor, user, [ + ('state', '=', 'open'), + ], limit=1, context=context) + if item_ids: + item = item_obj.browse(cursor, user, item_ids[0], context=context) + item_obj.write(cursor, user, item.id, { + 'state': 'done', + }, context=context) + return { + 'type': 'ir.action.wizard', + 'wiz_name': item.name, + } + return {} + + def _next(self, cursor, user, data, context=None): + item_obj = self.pool.get('ir.module.module.config_wizard.item') + item_ids = item_obj.search(cursor, user, [ + ('state', '=', 'open'), + ], context=context) + if item_ids: + return 'wizard' + return 'end' + +ModuleConfigWizard() + + class ModuleUpdateListInit(WizardOSV): _name = 'ir.module.module.update_list.init' diff --git a/trytond/ir/module/module.xml b/trytond/ir/module/module.xml index a14a12e70e..aae8f9a18c 100644 --- a/trytond/ir/module/module.xml +++ b/trytond/ir/module/module.xml @@ -104,6 +104,56 @@ + + ir.module.module.config_wizard.item + tree + + + + + + + ]]> + + + + Config Wizard Items + ir.module.module.config_wizard.item + form + + + + + + + + + Module Configuration + ir.module.module.config_wizard + + + ir.module.module.config_wizard.first + form + + + + + + + + ]]> + + Update Module List ir.module.module.update_list