From 90b194eb957983f90822daadbeb565867c48bad9 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Tue, 6 Mar 2012 11:46:46 +0100 Subject: [PATCH] [IMP] res.config.settings: improve doc and call execute upon saving records bzr revid: rco@openerp.com-20120306104646-bijuv403kcy2o9cs --- openerp/addons/base/res/res_config.py | 42 +++++++++++++++++++-------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/openerp/addons/base/res/res_config.py b/openerp/addons/base/res/res_config.py index 459695e298f..f3226acbe3b 100644 --- a/openerp/addons/base/res/res_config.py +++ b/openerp/addons/base/res/res_config.py @@ -404,33 +404,50 @@ class res_config_settings(osv.osv_memory): To make such a 'settings' wizard, define a model like:: class my_config_wizard(osv.osv_memory): - _name = 'sale.config.prefs' + _name = 'my.settings' _inherit = 'res.config.settings' _columns = { - 'default_foo': fields.type(..., default_model='model'), - 'group_bar': fields.boolean(..., group='base.group_user', implied_group='xml_id'), + 'default_foo': fields.type(..., default_model='my.model'), + 'group_bar': fields.boolean(..., group='base.group_user', implied_group='my.group'), 'module_baz': fields.boolean(...), 'other_field': fields.type(...), } - The method ``execute`` provides some support based on a naming convention: + The method ``execute`` is automatically called after creating and writing on records. + It provides some support based on a naming convention: * For a field like 'default_XXX', ``execute`` sets the (global) default value of the field 'XXX' in the model named by ``default_model`` to the field's value. * For a boolean field like 'group_XXX', ``execute`` adds/removes 'implied_group' to/from the implied groups of 'group', depending on the field's value. - By default 'group' is the group Employee. + By default 'group' is the group Employee. Groups are given by their xml id. * For a boolean field like 'module_XXX', ``execute`` triggers the immediate installation of the module named 'XXX' if the field has value ``True``. - * For other fields, the method ``execute`` only record their value for future - invocations of the wizard. Override the method to define their effect. + * For the other fields, the method ``execute`` invokes all methods with a name + that starts with 'set_'; such methods can be defined to implement the effect + of those fields. + + The method ``default_get`` retrieves values that reflect the current status of the + fields like 'default_XXX', 'group_XXX' and 'module_XXX'. It also invokes all methods + with a name that starts with 'get_default_'; such methods can be defined to provide + current values for other fields. """ _name = 'res.config.settings' _inherit = 'res.config' + def create(self, cr, uid, values, context=None): + id = super(res_config_settings, self).create(cr, uid, values, context) + self.execute(cr, uid, [id], context) + return id + + def write(self, cr, uid, ids, values, context=None): + res = super(res_config_settings, self).write(cr, uid, ids, values, context) + self.execute(cr, uid, ids, context) + return res + def _get_classified_fields(self, cr, uid, context=None): """ return a dictionary with the fields classified by category:: @@ -484,7 +501,7 @@ class res_config_settings(osv.osv_memory): # other fields: call all methods that start with 'get_default_' for method in dir(self): - if method.startswith('get_default'): + if method.startswith('get_default_'): res.update(getattr(self, method)(cr, uid, fields, context)) return res @@ -525,12 +542,13 @@ class res_config_settings(osv.osv_memory): getattr(self, method)(cr, uid, ids, context) # module fields: install immediately the selected modules - to_install = [] + to_install_ids = [] for name, module in classified['module']: if config[name] and module.state == 'uninstalled': - to_install.append(module.id) - if to_install: - return ir_module.button_immediate_install(cr, uid, to_install, context) + to_install_ids.append(module.id) + if to_install_ids: + ir_module.button_immediate_install(cr, uid, to_install_ids, context) + return {} res_config_settings()