diff --git a/base_optional_quick_create/AUTHORS.txt b/base_optional_quick_create/AUTHORS.txt deleted file mode 100644 index 7106ca0eb..000000000 --- a/base_optional_quick_create/AUTHORS.txt +++ /dev/null @@ -1 +0,0 @@ -Lorenzo Battistini diff --git a/base_optional_quick_create/README.rst b/base_optional_quick_create/README.rst new file mode 100644 index 000000000..0441f0e25 --- /dev/null +++ b/base_optional_quick_create/README.rst @@ -0,0 +1,70 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +========================== +Base Optional Quick Create +========================== + +This module allows to avoid to *quick create* new records, through many2one +fields, for a specific model. +You can configure which models should allow *quick create*. +When specified, the *quick create* option will always open the standard create +form. + +Got the idea from https://twitter.com/nbessi/status/337869826028605441 + +Installation +============ + +To install this module, you need to click on install + +Usage +===== + +To use this module, you need to: + + * go into the menu of ir_model + * select the model you want to disable the quick create option + * check the Avoid quick create + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/149/9.0 + +For further information, please visit: + + * https://www.odoo.com/forum/help-1 + +Known issues / Roadmap +====================== + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed feedback +`here `_. + +Credits +======= + +Contributors +------------ + +* Jonathan Nemry +* Lorenzo Battistini + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. + +To contribute to this module, please visit https://odoo-community.org. \ No newline at end of file diff --git a/base_optional_quick_create/__init__.py b/base_optional_quick_create/__init__.py index ed667c0f2..e600c4426 100644 --- a/base_optional_quick_create/__init__.py +++ b/base_optional_quick_create/__init__.py @@ -1,21 +1,5 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright (C) 2013 Agile Business Group sagl () -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# © 2013 Agile Business Group sagl () +# © 2016 ACSONE SA/NA () -from . import model +from . import models diff --git a/base_optional_quick_create/__openerp__.py b/base_optional_quick_create/__openerp__.py index 53c6ad431..e773b3f7d 100644 --- a/base_optional_quick_create/__openerp__.py +++ b/base_optional_quick_create/__openerp__.py @@ -1,45 +1,20 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Copyright (C) 2013 Agile Business Group sagl () -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## +# © 2013 Agile Business Group sagl () +# © 2016 ACSONE SA/NA () { 'name': "Optional quick create", - 'version': '8.0.0.1.0', + 'version': '9.0.1.0.0', 'category': 'Tools', 'summary': "Avoid 'quick create' on m2o fields, on a 'by model' basis", - 'description': """ -This module allows to avoid to *quick create* new records, through many2one -fields, for a specific model. -You can configure which models should allow *quick create*. -When specified, the *quick create* option will always open the standard create -form. - -Got the idea from https://twitter.com/nbessi/status/337869826028605441 -""", 'author': "Agile Business Group,Odoo Community Association (OCA)", 'website': 'http://www.agilebg.com', 'license': 'AGPL-3', "depends": ['base'], "data": [ - 'model_view.xml', + 'views/model_view.xml', ], "demo": [], 'test': [], - 'installable': False + 'installable': True } diff --git a/base_optional_quick_create/model.py b/base_optional_quick_create/model.py deleted file mode 100644 index 00862f0c7..000000000 --- a/base_optional_quick_create/model.py +++ /dev/null @@ -1,63 +0,0 @@ -# -*- coding: utf-8 -*- -############################################################################## -# -# Copyright (C) 2013 Agile Business Group sagl () -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# -############################################################################## - -from openerp.osv import orm, fields -from openerp import SUPERUSER_ID -from openerp.tools.translate import _ - - -class ir_model(orm.Model): - _inherit = 'ir.model' - - _columns = { - '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 _register_hook(self, cr, ids=None): - if ids is None: - ids = self.search(cr, SUPERUSER_ID, []) - 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.check_quick_create = True - return True - - 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]) - 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) - return res diff --git a/base_optional_quick_create/models/__init__.py b/base_optional_quick_create/models/__init__.py new file mode 100644 index 000000000..a32fc06b5 --- /dev/null +++ b/base_optional_quick_create/models/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2013 Agile Business Group sagl () +# © 2016 ACSONE SA/NA () + +from . import ir_model diff --git a/base_optional_quick_create/models/ir_model.py b/base_optional_quick_create/models/ir_model.py new file mode 100644 index 000000000..f82868e68 --- /dev/null +++ b/base_optional_quick_create/models/ir_model.py @@ -0,0 +1,44 @@ +# -*- coding: utf-8 -*- +# © 2013 Agile Business Group sagl () +# © 2016 ACSONE SA/NA () + +from openerp import api, fields, models +from openerp.exceptions import Warning +from openerp import SUPERUSER_ID +from openerp.tools.translate import _ + + +class IrModel(models.Model): + _inherit = 'ir.model' + + avoid_quick_create = fields.Boolean() + + def _wrap_name_create(self, old_create, model): + def wrapper(cr, uid, name, context=None): + raise Warning(_("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, []) + 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.check_quick_create = True + + @api.model + @api.returns('self', lambda value: value.id) + def create(self, vals): + ir_model = super(IrModel, self).create(vals) + self._register_hook(self.env.cr, [ir_model.id]) + return ir_model + + @api.multi + def write(self, vals): + res = super(IrModel, self).write(vals) + self._register_hook(self.env.cr, [self.ids]) + return res diff --git a/base_optional_quick_create/model_view.xml b/base_optional_quick_create/views/model_view.xml similarity index 87% rename from base_optional_quick_create/model_view.xml rename to base_optional_quick_create/views/model_view.xml index f36877fed..add2f4980 100644 --- a/base_optional_quick_create/model_view.xml +++ b/base_optional_quick_create/views/model_view.xml @@ -5,7 +5,7 @@ ir.model - +