diff --git a/base_optional_quick_create/model.py b/base_optional_quick_create/model.py index 691b4f5b6cb..0d062e80dcc 100644 --- a/base_optional_quick_create/model.py +++ b/base_optional_quick_create/model.py @@ -31,35 +31,23 @@ class IrModel(orm.Model): } def _patch_quick_create(self, cr, ids): - - def _wrap_name_create(): + def _wrap_name_create(ir_model): def wrapper(self, cr, uid, name, context=None): - raise orm.except_orm( - _('Error'), - _("Can't create quickly. Opening create form")) + if ir_model.avoid_quick_create: + raise orm.except_orm( + _('Error'), + _("Can't create quickly. Opening create form")) + else: + return _wrap_name_create.origin( + self, cr, uid, name, context=context) 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._patch_method('name_create', _wrap_name_create()) - model_obj.check_quick_create = True + self.pool.get(model.model)._patch_method( + 'name_create', _wrap_name_create(model)) + return True def _register_hook(self, cr): self._patch_quick_create(cr, self.search(cr, SUPERUSER_ID, [])) return super(IrModel, self)._register_hook(cr) - - def create(self, cr, uid, vals, context=None): - 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(IrModel, self).write(cr, uid, ids, vals, context=context) - self._patch_quick_create(cr, ids) - return res