From 3da294f56a1e025899e180e4c3abeda877a9db53 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Mon, 4 Feb 2013 15:58:24 +0100 Subject: [PATCH 01/11] [IMP] ir_action: averwrite read to add a dynamic_help on model bzr revid: chm@openerp.com-20130204145824-mq423czac9k2inzo --- openerp/addons/base/ir/ir_actions.py | 20 ++++++++++++++++++-- openerp/osv/orm.py | 3 +++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/openerp/addons/base/ir/ir_actions.py b/openerp/addons/base/ir/ir_actions.py index 4404b0a8a50..841e16af01c 100644 --- a/openerp/addons/base/ir/ir_actions.py +++ b/openerp/addons/base/ir/ir_actions.py @@ -216,9 +216,9 @@ class act_window(osv.osv): 'name': fields.char('Action Name', size=64, translate=True), 'type': fields.char('Action Type', size=32, required=True), 'view_id': fields.many2one('ir.ui.view', 'View Ref.', ondelete='cascade'), - 'domain': fields.char('Domain Value', size=250, + 'domain': fields.char('Domain Value', help="Optional domain filtering of the destination data, as a Python expression"), - 'context': fields.char('Context Value', size=250, required=True, + 'context': fields.char('Context Value', required=True, help="Context dictionary as Python expression, empty by default (Default: {})"), 'res_id': fields.integer('Record ID', help="Database ID of record to open in form view, when ``view_mode`` is set to 'form' only"), 'res_model': fields.char('Destination Model', size=64, required=True, @@ -261,6 +261,22 @@ class act_window(osv.osv): 'multi': False, } + def read(self, cr, uid, ids, fields=None, context=None, load='_classic_read'): + results = super(act_window, self).read(cr, uid, ids, fields=fields, context=context, load=load) + + if not fields or 'help' in fields: + context = dict(context) + dic = { + 'active_model' : context.get('active_model', None), + 'active_id' : context.get('active_id', None), + 'active_ids' : context.get('active_ids', None) + } + for res in results: + if res.get('res_model', False): + res['help'] = self.pool.get(res.get('res_model')).dynamic_help(cr, uid, res.get('help', ""), context=dict(context, **eval(res['context'], dic))) + + return results + def for_xml_id(self, cr, uid, module, xml_id, context=None): """ Returns the act_window object created for the provided xml_id diff --git a/openerp/osv/orm.py b/openerp/osv/orm.py index 6056e405b78..1bb98351e23 100644 --- a/openerp/osv/orm.py +++ b/openerp/osv/orm.py @@ -3614,6 +3614,9 @@ class BaseModel(object): return result and result[0] or False return result + def dynamic_help(self, cr, user, help, context=None): + return help + def _read_flat(self, cr, user, ids, fields_to_read, context=None, load='_classic_read'): if not context: context = {} From ec02389784ab1a41d91ab8df6d53c953444e86b4 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Tue, 5 Feb 2013 12:22:58 +0100 Subject: [PATCH 02/11] [FIX] ir_action: read ir.actions.act_window bzr revid: chm@openerp.com-20130205112258-heruqrx53dahqi02 --- openerp/addons/base/ir/ir_actions.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/openerp/addons/base/ir/ir_actions.py b/openerp/addons/base/ir/ir_actions.py index 841e16af01c..aae45805502 100644 --- a/openerp/addons/base/ir/ir_actions.py +++ b/openerp/addons/base/ir/ir_actions.py @@ -265,7 +265,7 @@ class act_window(osv.osv): results = super(act_window, self).read(cr, uid, ids, fields=fields, context=context, load=load) if not fields or 'help' in fields: - context = dict(context) + context = dict(context or {}) dic = { 'active_model' : context.get('active_model', None), 'active_id' : context.get('active_id', None), @@ -273,7 +273,8 @@ class act_window(osv.osv): } for res in results: if res.get('res_model', False): - res['help'] = self.pool.get(res.get('res_model')).dynamic_help(cr, uid, res.get('help', ""), context=dict(context, **eval(res['context'], dic))) + custom_context = dict(context.items() + (eval(res['context'] or "{}", dic) or {}).items()) + res['help'] = self.pool.get(res.get('res_model')).dynamic_help(cr, uid, res.get('help', ""), context=custom_context) return results From db35042ff828b2b0cad8f74292658eb600f4f7f0 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Tue, 5 Feb 2013 16:15:48 +0100 Subject: [PATCH 03/11] [FIX] ir_action: read accept list ids or id bzr revid: chm@openerp.com-20130205151548-t66esec4ygrw6z4v --- openerp/addons/base/ir/ir_actions.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/openerp/addons/base/ir/ir_actions.py b/openerp/addons/base/ir/ir_actions.py index aae45805502..7ea98b3b0cf 100644 --- a/openerp/addons/base/ir/ir_actions.py +++ b/openerp/addons/base/ir/ir_actions.py @@ -262,6 +262,9 @@ class act_window(osv.osv): } def read(self, cr, uid, ids, fields=None, context=None, load='_classic_read'): + u = isinstance(ids, (int, long)) + if u: + ids = [ids] results = super(act_window, self).read(cr, uid, ids, fields=fields, context=context, load=load) if not fields or 'help' in fields: @@ -276,6 +279,8 @@ class act_window(osv.osv): custom_context = dict(context.items() + (eval(res['context'] or "{}", dic) or {}).items()) res['help'] = self.pool.get(res.get('res_model')).dynamic_help(cr, uid, res.get('help', ""), context=custom_context) + if u: + return results[0] return results def for_xml_id(self, cr, uid, module, xml_id, context=None): From 18985e673f7b0d1bdc499020e02987cb4ba45d49 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Tue, 5 Feb 2013 17:09:32 +0100 Subject: [PATCH 04/11] [FIX] ir_action: read context with uid bzr revid: chm@openerp.com-20130205160932-nqr1rk4t3l2yjhrz --- openerp/addons/base/ir/ir_actions.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/openerp/addons/base/ir/ir_actions.py b/openerp/addons/base/ir/ir_actions.py index 7ea98b3b0cf..d1aa04426bb 100644 --- a/openerp/addons/base/ir/ir_actions.py +++ b/openerp/addons/base/ir/ir_actions.py @@ -272,7 +272,8 @@ class act_window(osv.osv): dic = { 'active_model' : context.get('active_model', None), 'active_id' : context.get('active_id', None), - 'active_ids' : context.get('active_ids', None) + 'active_ids' : context.get('active_ids', None), + 'uid' : uid, } for res in results: if res.get('res_model', False): From 8d0ed1edcce082e2dd733e1a7185aa998681ae0a Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Wed, 6 Feb 2013 13:20:39 +0100 Subject: [PATCH 05/11] [FIX] ir_action: catch and mute exception for the safe_eval of context bzr revid: chm@openerp.com-20130206122039-d3mh29qt472qacpm --- openerp/addons/base/ir/ir_actions.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/openerp/addons/base/ir/ir_actions.py b/openerp/addons/base/ir/ir_actions.py index d1aa04426bb..b182ebe2a4d 100644 --- a/openerp/addons/base/ir/ir_actions.py +++ b/openerp/addons/base/ir/ir_actions.py @@ -277,7 +277,12 @@ class act_window(osv.osv): } for res in results: if res.get('res_model', False): - custom_context = dict(context.items() + (eval(res['context'] or "{}", dic) or {}).items()) + try: + with tools.mute_logger("openerp.tools.safe_eval"): + eval_context = eval(res['context'] or "{}", dic) or {} + except Exception: + continue + custom_context = dict(context, **eval_context) res['help'] = self.pool.get(res.get('res_model')).dynamic_help(cr, uid, res.get('help', ""), context=custom_context) if u: From 491c3b73f323f2b538500667bf4dbdb5c3882224 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Thu, 21 Mar 2013 14:32:07 +0100 Subject: [PATCH 06/11] [IMP] code cleaning for get_empty_list_help bzr revid: chm@openerp.com-20130321133207-j4tiibjev6lkeuxa --- openerp/addons/base/ir/ir_actions.py | 2 +- openerp/osv/orm.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/openerp/addons/base/ir/ir_actions.py b/openerp/addons/base/ir/ir_actions.py index 2c7a07489da..c3a33ae0196 100644 --- a/openerp/addons/base/ir/ir_actions.py +++ b/openerp/addons/base/ir/ir_actions.py @@ -284,7 +284,7 @@ class act_window(osv.osv): except Exception: continue custom_context = dict(context, **eval_context) - res['help'] = self.pool.get(res.get('res_model')).dynamic_help(cr, uid, res.get('help', ""), context=custom_context) + res['help'] = self.pool.get(res.get('res_model')).get_empty_list_help(cr, uid, res.get('help', ""), context=custom_context) if u: return results[0] diff --git a/openerp/osv/orm.py b/openerp/osv/orm.py index 24a924836a4..cd1cd926818 100644 --- a/openerp/osv/orm.py +++ b/openerp/osv/orm.py @@ -3604,7 +3604,7 @@ class BaseModel(object): return result and result[0] or False return result - def dynamic_help(self, cr, user, help, context=None): + def get_empty_list_help(self, cr, user, help, context=None): return help def _read_flat(self, cr, user, ids, fields_to_read, context=None, load='_classic_read'): From 01eb15bdfa45bbf4cae85178220c7ab3f192e602 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 22 Mar 2013 10:37:59 +0100 Subject: [PATCH 07/11] [IMP] ir_actions: change var name and add comment bzr revid: chm@openerp.com-20130322093759-cq0uj3c6ucmrpe05 --- openerp/addons/base/ir/ir_actions.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/openerp/addons/base/ir/ir_actions.py b/openerp/addons/base/ir/ir_actions.py index dc8d38df80c..9d2ee186878 100644 --- a/openerp/addons/base/ir/ir_actions.py +++ b/openerp/addons/base/ir/ir_actions.py @@ -263,30 +263,31 @@ class act_window(osv.osv): } def read(self, cr, uid, ids, fields=None, context=None, load='_classic_read'): - u = isinstance(ids, (int, long)) - if u: + """ call the method get_empty_list_help of the model and set the window action help message + """ + ids_int = isinstance(ids, (int, long)) + if ids_int: ids = [ids] results = super(act_window, self).read(cr, uid, ids, fields=fields, context=context, load=load) if not fields or 'help' in fields: context = dict(context or {}) - dic = { - 'active_model' : context.get('active_model', None), - 'active_id' : context.get('active_id', None), - 'active_ids' : context.get('active_ids', None), + eval_dict = { + 'active_model' : context.get('active_model'), + 'active_id' : context.get('active_id'), + 'active_ids' : context.get('active_ids'), 'uid' : uid, } for res in results: - if res.get('res_model', False): + if res.get('res_model'): try: with tools.mute_logger("openerp.tools.safe_eval"): - eval_context = eval(res['context'] or "{}", dic) or {} + eval_context = eval(res['context'] or "{}", eval_dict) or {} except Exception: continue custom_context = dict(context, **eval_context) res['help'] = self.pool.get(res.get('res_model')).get_empty_list_help(cr, uid, res.get('help', ""), context=custom_context) - - if u: + if ids_int: return results[0] return results From 5c091dd8e2ee04fd903c7ef9d1893bc71ae9bd2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 28 Mar 2013 10:23:57 +0100 Subject: [PATCH 08/11] [CLEAN] BaseModel: moved get_empty_list_help method to a better place in the code; added some comments. bzr revid: tde@openerp.com-20130328092357-v3grmw9brp9wtfj0 --- openerp/osv/orm.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/openerp/osv/orm.py b/openerp/osv/orm.py index aa02242570b..b930bd3b5f7 100644 --- a/openerp/osv/orm.py +++ b/openerp/osv/orm.py @@ -3538,6 +3538,14 @@ class BaseModel(object): return res + def get_empty_list_help(self, cr, user, help, context=None): + """ Generic method giving the help message displayed when having + no result to display in a list or kanban view. By default it returns + the help given in parameter that is generally the help message + defined in the action. + """ + return help + def check_field_access_rights(self, cr, user, operation, fields, context=None): """ Check the user access rights on the given fields. This raises Access @@ -3604,9 +3612,6 @@ class BaseModel(object): return result and result[0] or False return result - def get_empty_list_help(self, cr, user, help, context=None): - return help - def _read_flat(self, cr, user, ids, fields_to_read, context=None, load='_classic_read'): if not context: context = {} From c696445656319668f44475ba8b02b576ee7b1912 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 28 Mar 2013 10:38:47 +0100 Subject: [PATCH 09/11] [FIX] ir_action: when truing to get get_empty_list_help, be sure the model actually exists. Issue trigered by some tests. bzr revid: tde@openerp.com-20130328093847-8k4o9vvs4p71a4al --- openerp/addons/base/ir/ir_actions.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/openerp/addons/base/ir/ir_actions.py b/openerp/addons/base/ir/ir_actions.py index 87d04f14bad..1bed8771e47 100644 --- a/openerp/addons/base/ir/ir_actions.py +++ b/openerp/addons/base/ir/ir_actions.py @@ -296,20 +296,21 @@ class act_window(osv.osv): if not fields or 'help' in fields: context = dict(context or {}) eval_dict = { - 'active_model' : context.get('active_model'), - 'active_id' : context.get('active_id'), - 'active_ids' : context.get('active_ids'), - 'uid' : uid, + 'active_model': context.get('active_model'), + 'active_id': context.get('active_id'), + 'active_ids': context.get('active_ids'), + 'uid': uid, } for res in results: - if res.get('res_model'): + model = res.get('res_model') + if model and self.pool.get('model'): try: with tools.mute_logger("openerp.tools.safe_eval"): eval_context = eval(res['context'] or "{}", eval_dict) or {} except Exception: continue custom_context = dict(context, **eval_context) - res['help'] = self.pool.get(res.get('res_model')).get_empty_list_help(cr, uid, res.get('help', ""), context=custom_context) + res['help'] = self.pool.get(model).get_empty_list_help(cr, uid, res.get('help', ""), context=custom_context) if ids_int: return results[0] return results From 140ba0a6a7bf21272e517c0a41d0b3243bee14c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 2 Apr 2013 10:12:34 +0200 Subject: [PATCH 10/11] [FIX] ir_action: no string but var. bzr revid: tde@openerp.com-20130402081234-v6w6oga8q4y23yy4 --- openerp/addons/base/ir/ir_actions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openerp/addons/base/ir/ir_actions.py b/openerp/addons/base/ir/ir_actions.py index 1bed8771e47..c078794ce80 100644 --- a/openerp/addons/base/ir/ir_actions.py +++ b/openerp/addons/base/ir/ir_actions.py @@ -303,7 +303,7 @@ class act_window(osv.osv): } for res in results: model = res.get('res_model') - if model and self.pool.get('model'): + if model and self.pool.get(model): try: with tools.mute_logger("openerp.tools.safe_eval"): eval_context = eval(res['context'] or "{}", eval_dict) or {} From bef293af4b585cbf8701c5d72fe59f1cf1b9c9f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 4 Apr 2013 13:57:19 +0200 Subject: [PATCH 11/11] [IMP] res_partner: customers is now sequence 2, because salesteam will be 1. bzr revid: tde@openerp.com-20130404115719-glq8uqgvyvhm0ukd --- openerp/addons/base/res/res_partner_view.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openerp/addons/base/res/res_partner_view.xml b/openerp/addons/base/res/res_partner_view.xml index c920aba23ae..4f3897e531a 100644 --- a/openerp/addons/base/res/res_partner_view.xml +++ b/openerp/addons/base/res/res_partner_view.xml @@ -10,7 +10,7 @@ - + @@ -420,7 +420,7 @@ - + Customers