|
@ -1,10 +1,10 @@ |
|
|
# -*- coding: utf-8 -*- |
|
|
# -*- coding: utf-8 -*- |
|
|
# © 2013 Agile Business Group sagl (<http://www.agilebg.com>) |
|
|
# © 2013 Agile Business Group sagl (<http://www.agilebg.com>) |
|
|
# © 2016 ACSONE SA/NA (<http://acsone.eu>) |
|
|
# © 2016 ACSONE SA/NA (<http://acsone.eu>) |
|
|
|
|
|
# © 2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>) |
|
|
|
|
|
|
|
|
from openerp import api, fields, models, _ |
|
|
|
|
|
from openerp.exceptions import UserError |
|
|
|
|
|
from openerp import SUPERUSER_ID |
|
|
|
|
|
|
|
|
from odoo import api, fields, models, _ |
|
|
|
|
|
from odoo.exceptions import UserError |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class IrModel(models.Model): |
|
|
class IrModel(models.Model): |
|
@ -12,35 +12,38 @@ class IrModel(models.Model): |
|
|
|
|
|
|
|
|
avoid_quick_create = fields.Boolean() |
|
|
avoid_quick_create = fields.Boolean() |
|
|
|
|
|
|
|
|
def _patch_quick_create(self, cr, ids): |
|
|
|
|
|
|
|
|
@api.multi |
|
|
|
|
|
def _patch_quick_create(self): |
|
|
|
|
|
|
|
|
|
|
|
@api.multi |
|
|
def _wrap_name_create(): |
|
|
def _wrap_name_create(): |
|
|
def wrapper(self, cr, uid, name, context=None): |
|
|
|
|
|
|
|
|
def wrapper(self): |
|
|
raise UserError(_("Can't create quickly. Opening create form")) |
|
|
raise UserError(_("Can't create quickly. Opening create form")) |
|
|
return wrapper |
|
|
return wrapper |
|
|
|
|
|
|
|
|
for model in self.browse(cr, SUPERUSER_ID, ids): |
|
|
|
|
|
|
|
|
for model in self: |
|
|
if model.avoid_quick_create: |
|
|
if model.avoid_quick_create: |
|
|
model_name = model.model |
|
|
model_name = model.model |
|
|
model_obj = self.pool.get(model_name) |
|
|
|
|
|
if model_obj and not hasattr(model_obj, 'check_quick_create'): |
|
|
|
|
|
|
|
|
model_obj = self.env.get(model_name) |
|
|
|
|
|
if model_name and not hasattr(model_obj, 'check_quick_create'): |
|
|
model_obj._patch_method('name_create', _wrap_name_create()) |
|
|
model_obj._patch_method('name_create', _wrap_name_create()) |
|
|
model_obj.check_quick_create = True |
|
|
model_obj.check_quick_create = True |
|
|
return True |
|
|
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 _register_hook(self): |
|
|
|
|
|
models = self.search([]) |
|
|
|
|
|
models._patch_quick_create() |
|
|
|
|
|
return super(IrModel, self)._register_hook() |
|
|
|
|
|
|
|
|
@api.model |
|
|
@api.model |
|
|
@api.returns('self', lambda value: value.id) |
|
|
@api.returns('self', lambda value: value.id) |
|
|
def create(self, vals): |
|
|
def create(self, vals): |
|
|
ir_model = super(IrModel, self).create(vals) |
|
|
ir_model = super(IrModel, self).create(vals) |
|
|
self.pool[self._name]._patch_quick_create(self.env.cr, [ir_model.id]) |
|
|
|
|
|
|
|
|
ir_model._patch_quick_create() |
|
|
return ir_model |
|
|
return ir_model |
|
|
|
|
|
|
|
|
@api.multi |
|
|
@api.multi |
|
|
def write(self, vals): |
|
|
def write(self, vals): |
|
|
res = super(IrModel, self).write(vals) |
|
|
res = super(IrModel, self).write(vals) |
|
|
self.pool[self._name]._patch_quick_create(self.env.cr, self.ids) |
|
|
|
|
|
|
|
|
self._patch_quick_create() |
|
|
return res |
|
|
return res |