From 6a28aa2843f99b3d8035985f4232621ce4e92a8e Mon Sep 17 00:00:00 2001 From: Stefan Rijnhart Date: Tue, 26 Jan 2016 12:37:45 +0100 Subject: [PATCH 1/3] [FIX] keep _register_hook's signature and call super --- base_optional_quick_create/model.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/base_optional_quick_create/model.py b/base_optional_quick_create/model.py index 00862f0c7..3963df8d2 100644 --- a/base_optional_quick_create/model.py +++ b/base_optional_quick_create/model.py @@ -37,9 +37,7 @@ class ir_model(orm.Model): _("Can't create quickly. Opening create form")) return wrapper - def _register_hook(self, cr, ids=None): - if ids is None: - ids = self.search(cr, SUPERUSER_ID, []) + def _patch_quick_create(self, cr, ids): for model in self.browse(cr, SUPERUSER_ID, ids): if model.avoid_quick_create: model_name = model.model @@ -50,14 +48,18 @@ class ir_model(orm.Model): model_obj.check_quick_create = True return True + def _register_hook(self, cr): + self._patch_quick_create(cr, self.search(cr, SUPERUSER_ID, [])) + return super(ir_model, self)._register_hook(cr) + def create(self, cr, uid, vals, context=None): res_id = super(ir_model, self).create(cr, uid, vals, context=context) - self._register_hook(cr, [res_id]) + self._patch_quick_create(cr, [res_id]) return res_id def write(self, cr, uid, ids, vals, context=None): if isinstance(ids, (int, long)): ids = [ids] res = super(ir_model, self).write(cr, uid, ids, vals, context=context) - self._register_hook(cr, ids) + self._patch_quick_create(cr, ids) return res From 7fcf65c16ec80971f87c410838c2338f1c046e3e Mon Sep 17 00:00:00 2001 From: Stefan Rijnhart Date: Tue, 26 Jan 2016 13:30:26 +0100 Subject: [PATCH 2/3] [FIX] Odoolint --- base_optional_quick_create/model.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/base_optional_quick_create/model.py b/base_optional_quick_create/model.py index 3963df8d2..01fbee527 100644 --- a/base_optional_quick_create/model.py +++ b/base_optional_quick_create/model.py @@ -23,7 +23,7 @@ from openerp import SUPERUSER_ID from openerp.tools.translate import _ -class ir_model(orm.Model): +class IrModel(orm.Model): _inherit = 'ir.model' _columns = { @@ -50,16 +50,16 @@ class ir_model(orm.Model): def _register_hook(self, cr): self._patch_quick_create(cr, self.search(cr, SUPERUSER_ID, [])) - return super(ir_model, self)._register_hook(cr) + return super(IrModel, self)._register_hook(cr) def create(self, cr, uid, vals, context=None): - res_id = super(ir_model, self).create(cr, uid, vals, context=context) + res_id = super(IrModel, self).create(cr, uid, vals, context=context) self._patch_quick_create(cr, [res_id]) return res_id def write(self, cr, uid, ids, vals, context=None): if isinstance(ids, (int, long)): ids = [ids] - res = super(ir_model, self).write(cr, uid, ids, vals, context=context) + res = super(IrModel, self).write(cr, uid, ids, vals, context=context) self._patch_quick_create(cr, ids) return res From ed4a62bb42288838bcea6f418d938b918fe1171e Mon Sep 17 00:00:00 2001 From: eLBati Date: Thu, 11 Feb 2016 17:06:30 +0100 Subject: [PATCH 3/3] REF using _patch_method for name_create --- base_optional_quick_create/model.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/base_optional_quick_create/model.py b/base_optional_quick_create/model.py index 01fbee527..691b4f5b6 100644 --- a/base_optional_quick_create/model.py +++ b/base_optional_quick_create/model.py @@ -30,21 +30,21 @@ class IrModel(orm.Model): 'avoid_quick_create': fields.boolean('Avoid quick create'), } - def _wrap_name_create(self, old_create, model): - def wrapper(cr, uid, name, context=None): - raise orm.except_orm( - _('Error'), - _("Can't create quickly. Opening create form")) - return wrapper - def _patch_quick_create(self, cr, ids): + + def _wrap_name_create(): + def wrapper(self, cr, uid, name, context=None): + raise orm.except_orm( + _('Error'), + _("Can't create quickly. Opening create form")) + return wrapper + for model in self.browse(cr, SUPERUSER_ID, ids): if model.avoid_quick_create: model_name = model.model model_obj = self.pool.get(model_name) if model_obj and not hasattr(model_obj, 'check_quick_create'): - model_obj.name_create = self._wrap_name_create( - model_obj.name_create, model_name) + model_obj._patch_method('name_create', _wrap_name_create()) model_obj.check_quick_create = True return True