diff --git a/base_optional_quick_create/AUTHORS.txt b/base_optional_quick_create/AUTHORS.txt deleted file mode 100644 index 7106ca0eb6c..00000000000 --- 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 00000000000..17717331a63 --- /dev/null +++ b/base_optional_quick_create/README.rst @@ -0,0 +1,86 @@ +.. 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 + +===================== +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 Instal + +#. Do this ... + +Configuration +============= + +To configure this module, you need to: + +#. Go to in Setting/Technical Setting/Database Structure/Model +#. Tick Avoid Quick Create, to disabled the quick create + +Usage +===== + +To use this module, you need to: + +#. No things + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/{repo_id}/{branch} + +.. repo_id is available in https://github.com/OCA/maintainer-tools/blob/master/tools/repos_with_ids.txt +.. branch is "8.0" for example + +Known issues / Roadmap +====================== + +* No 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. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Agile Business Group sagl () +* Florent de Labarre + +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 ed667c0f258..e76d7b83d09 100644 --- a/base_optional_quick_create/__init__.py +++ b/base_optional_quick_create/__init__.py @@ -18,4 +18,4 @@ # ############################################################################## -from . import model +from . import base_optional_quick_create diff --git a/base_optional_quick_create/__openerp__.py b/base_optional_quick_create/__openerp__.py index 53c6ad431ae..d4ef735a648 100644 --- a/base_optional_quick_create/__openerp__.py +++ b/base_optional_quick_create/__openerp__.py @@ -2,6 +2,7 @@ ############################################################################## # # Copyright (C) 2013 Agile Business Group sagl () +# Contributor 2016 Florent de Labarre # # 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 @@ -20,26 +21,18 @@ { 'name': "Optional quick create", - 'version': '8.0.0.1.0', + 'version': '9.0.0.1.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)", + 'author': "Agile Business Group,Odoo Community \ + Association (OCA), Florent de Labarre", 'website': 'http://www.agilebg.com', 'license': 'AGPL-3', "depends": ['base'], "data": [ - 'model_view.xml', + 'base_optional_quick_create_view.xml', ], "demo": [], 'test': [], - 'installable': False + "installable": True } diff --git a/base_optional_quick_create/base_optional_quick_create.py b/base_optional_quick_create/base_optional_quick_create.py new file mode 100644 index 00000000000..ea0e9400ceb --- /dev/null +++ b/base_optional_quick_create/base_optional_quick_create.py @@ -0,0 +1,75 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (C) 2013 Agile Business Group sagl () +# Contributor 2016 Florent de Labarre +# +# 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 import api, fields, models, _ +from openerp.exceptions import UserError +from openerp.tools.translate import _ +from openerp import SUPERUSER_ID + + +class IrModel(models.Model): + _inherit = 'ir.model' + + avoid_quick_create = fields.Boolean(string='Disabled quick create',) + + @api.v7 + def _patch_quick_create(self, cr, ids): + + def _wrap_name_create(): + def wrapper(self, cr, uid, name, context=None): + raise UserError(_("Can't create quickly. Opening create form")) + return wrapper + + for model in self.browse(cr, SUPERUSER_ID, ids): + model_name = model.model + model_obj = self.pool.get(model_name) + if model_obj and not hasattr(model_obj.name_create, 'origin'): + model_obj._patch_method('name_create', _wrap_name_create()) + return True + + @api.v7 + def _register_hook(self, cr): + ids = self.search( + cr, SUPERUSER_ID, [('avoid_quick_create', '=', True)]) + self._patch_quick_create(cr, ids) + return super(IrModel, self)._register_hook(cr) + + @api.v7 + def create(self, cr, uid, vals, context=None): + res_id = super(IrModel, self).create(cr, uid, vals, context=context) + if vals.get('avoid_quick_create'): + self._patch_quick_create(cr, [res_id]) + return res_id + + @api.v7 + 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) + if 'avoid_quick_create' in vals: + if vals['avoid_quick_create']: + self._patch_quick_create(cr, ids) + else: + for model in self.browse(cr, uid, ids, context=context): + model_obj = self.pool[model.model] + if hasattr(model_obj.name_create, 'origin'): + model_obj._revert_method('name_create') + return res diff --git a/base_optional_quick_create/model_view.xml b/base_optional_quick_create/base_optional_quick_create_view.xml similarity index 87% rename from base_optional_quick_create/model_view.xml rename to base_optional_quick_create/base_optional_quick_create_view.xml index f36877fed4e..add2f498007 100644 --- a/base_optional_quick_create/model_view.xml +++ b/base_optional_quick_create/base_optional_quick_create_view.xml @@ -5,7 +5,7 @@ ir.model - + diff --git a/base_optional_quick_create/i18n/base_optional_quick_create.pot b/base_optional_quick_create/i18n/base_optional_quick_create.pot index 222dc31b61a..c9550a241bd 100644 --- a/base_optional_quick_create/i18n/base_optional_quick_create.pot +++ b/base_optional_quick_create/i18n/base_optional_quick_create.pot @@ -4,7 +4,7 @@ # msgid "" msgstr "" -"Project-Id-Version: OpenERP Server 7.0\n" +"Project-Id-Version: OpenERP Server 9.0\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2014-03-14 17:41+0000\n" "PO-Revision-Date: 2014-03-14 17:41+0000\n" diff --git a/base_optional_quick_create/i18n/de.po b/base_optional_quick_create/i18n/de.po new file mode 100644 index 00000000000..28f837857a6 --- /dev/null +++ b/base_optional_quick_create/i18n/de.po @@ -0,0 +1,41 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_optional_quick_create +# +# Translators: +# Rudolf Schnapka , 2016 +msgid "" +msgstr "" +"Project-Id-Version: server-tools (8.0)\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-03-12 02:05+0000\n" +"PO-Revision-Date: 2016-01-18 14:01+0000\n" +"Last-Translator: Rudolf Schnapka \n" +"Language-Team: German (http://www.transifex.com/oca/OCA-server-tools-8-0/language/de/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: de\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: base_optional_quick_create +#: field:ir.model,avoid_quick_create:0 +msgid "Avoid quick create" +msgstr "Vermeide Schnellanlage" + +#. module: base_optional_quick_create +#: code:addons/base_optional_quick_create/model.py:39 +#, python-format +msgid "Can't create quickly. Opening create form" +msgstr "Kann nicht schnell-anlegen. Öffne Anlageformular" + +#. module: base_optional_quick_create +#: code:addons/base_optional_quick_create/model.py:38 +#, python-format +msgid "Error" +msgstr "Fehler" + +#. module: base_optional_quick_create +#: model:ir.model,name:base_optional_quick_create.model_ir_model +msgid "Models" +msgstr "Modelle" diff --git a/base_optional_quick_create/i18n/en.po b/base_optional_quick_create/i18n/en.po index f38fbec3bc0..a64398d38de 100644 --- a/base_optional_quick_create/i18n/en.po +++ b/base_optional_quick_create/i18n/en.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: server-tools (8.0)\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2015-09-29 11:14+0000\n" +"POT-Creation-Date: 2016-03-12 02:05+0000\n" "PO-Revision-Date: 2015-09-18 13:54+0000\n" "Last-Translator: OCA Transbot \n" "Language-Team: English (http://www.transifex.com/oca/OCA-server-tools-8-0/language/en/)\n" @@ -23,13 +23,13 @@ msgid "Avoid quick create" msgstr "Avoid quick create" #. module: base_optional_quick_create -#: code:addons/base_optional_quick_create/model.py:37 +#: code:addons/base_optional_quick_create/model.py:39 #, python-format msgid "Can't create quickly. Opening create form" msgstr "Can't create quickly. Opening create form" #. module: base_optional_quick_create -#: code:addons/base_optional_quick_create/model.py:36 +#: code:addons/base_optional_quick_create/model.py:38 #, python-format msgid "Error" msgstr "Error" diff --git a/base_optional_quick_create/i18n/es.po b/base_optional_quick_create/i18n/es.po new file mode 100644 index 00000000000..615f0b341fc --- /dev/null +++ b/base_optional_quick_create/i18n/es.po @@ -0,0 +1,42 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_optional_quick_create +# +# Translators: +# Antonio Trueba, 2016 +# Antonio Trueba, 2016 +msgid "" +msgstr "" +"Project-Id-Version: server-tools (8.0)\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-03-12 02:05+0000\n" +"PO-Revision-Date: 2016-02-10 16:46+0000\n" +"Last-Translator: Antonio Trueba\n" +"Language-Team: Spanish (http://www.transifex.com/oca/OCA-server-tools-8-0/language/es/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: es\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: base_optional_quick_create +#: field:ir.model,avoid_quick_create:0 +msgid "Avoid quick create" +msgstr "" + +#. module: base_optional_quick_create +#: code:addons/base_optional_quick_create/model.py:39 +#, python-format +msgid "Can't create quickly. Opening create form" +msgstr "" + +#. module: base_optional_quick_create +#: code:addons/base_optional_quick_create/model.py:38 +#, python-format +msgid "Error" +msgstr "Error" + +#. module: base_optional_quick_create +#: model:ir.model,name:base_optional_quick_create.model_ir_model +msgid "Models" +msgstr "Modelos" diff --git a/base_optional_quick_create/i18n/fr.po b/base_optional_quick_create/i18n/fr.po index 94f8070529d..b75691f7ec7 100644 --- a/base_optional_quick_create/i18n/fr.po +++ b/base_optional_quick_create/i18n/fr.po @@ -3,14 +3,22 @@ # * base_optional_quick_create # # Translators: -# FIRST AUTHOR , 2014 +# Armando Vulcano Junior , 2015 +# Christophe CHAUVET , 2016 +# FIRST AUTHOR , 2012,2014 +# Hotellook, 2014 +# Jarmo Kortetjärvi , 2016 +# Matjaž Mozetič , 2015-2016 +# Paolo Valier, 2016 +# Rudolf Schnapka , 2016 +# SaFi J. , 2015 msgid "" msgstr "" -"Project-Id-Version: server-tools (8.0)\n" +"Project-Id-Version: server-tools (9.0)\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2015-09-29 11:14+0000\n" -"PO-Revision-Date: 2015-09-18 13:54+0000\n" -"Last-Translator: OCA Transbot \n" +"POT-Creation-Date: 2016-05-12 14:33+0000\n" +"PO-Revision-Date: 2016-05-08 17:01+0000\n" +"Last-Translator: Christophe CHAUVET \n" "Language-Team: French (http://www.transifex.com/oca/OCA-server-tools-8-0/language/fr/)\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -21,16 +29,16 @@ msgstr "" #. module: base_optional_quick_create #: field:ir.model,avoid_quick_create:0 msgid "Avoid quick create" -msgstr "" +msgstr "Éviter la création rapide" #. module: base_optional_quick_create -#: code:addons/base_optional_quick_create/model.py:37 +#: code:addons/base_optional_quick_create/model.py:39 #, python-format msgid "Can't create quickly. Opening create form" -msgstr "" +msgstr "Impossible de créer rapidement. Ouverture du formualire de création" #. module: base_optional_quick_create -#: code:addons/base_optional_quick_create/model.py:36 +#: code:addons/base_optional_quick_create/model.py:38 #, python-format msgid "Error" msgstr "Erreur" diff --git a/base_optional_quick_create/i18n/it.po b/base_optional_quick_create/i18n/it.po new file mode 100644 index 00000000000..e40fa933a43 --- /dev/null +++ b/base_optional_quick_create/i18n/it.po @@ -0,0 +1,41 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_optional_quick_create +# +# Translators: +# Paolo Valier, 2016 +msgid "" +msgstr "" +"Project-Id-Version: server-tools (8.0)\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-03-17 15:36+0000\n" +"PO-Revision-Date: 2016-03-13 09:05+0000\n" +"Last-Translator: Paolo Valier\n" +"Language-Team: Italian (http://www.transifex.com/oca/OCA-server-tools-8-0/language/it/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: it\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: base_optional_quick_create +#: field:ir.model,avoid_quick_create:0 +msgid "Avoid quick create" +msgstr "Impedisci creazione immediata" + +#. module: base_optional_quick_create +#: code:addons/base_optional_quick_create/model.py:39 +#, python-format +msgid "Can't create quickly. Opening create form" +msgstr "Non è possibile creare immediatamente. Apro il form Crea" + +#. module: base_optional_quick_create +#: code:addons/base_optional_quick_create/model.py:38 +#, python-format +msgid "Error" +msgstr "Errore" + +#. module: base_optional_quick_create +#: model:ir.model,name:base_optional_quick_create.model_ir_model +msgid "Models" +msgstr "Modelli" diff --git a/base_optional_quick_create/i18n/pt_BR.po b/base_optional_quick_create/i18n/pt_BR.po index 4746da62dd5..dc436fc52f0 100644 --- a/base_optional_quick_create/i18n/pt_BR.po +++ b/base_optional_quick_create/i18n/pt_BR.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: server-tools (8.0)\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2015-09-29 11:14+0000\n" +"POT-Creation-Date: 2016-03-12 02:05+0000\n" "PO-Revision-Date: 2015-09-18 21:14+0000\n" "Last-Translator: Armando Vulcano Junior \n" "Language-Team: Portuguese (Brazil) (http://www.transifex.com/oca/OCA-server-tools-8-0/language/pt_BR/)\n" @@ -24,13 +24,13 @@ msgid "Avoid quick create" msgstr "Evite criação rápida" #. module: base_optional_quick_create -#: code:addons/base_optional_quick_create/model.py:37 +#: code:addons/base_optional_quick_create/model.py:39 #, python-format msgid "Can't create quickly. Opening create form" msgstr "Não pode criar rapidamente; Abrindo formulário de criação" #. module: base_optional_quick_create -#: code:addons/base_optional_quick_create/model.py:36 +#: code:addons/base_optional_quick_create/model.py:38 #, python-format msgid "Error" msgstr "Erro" diff --git a/base_optional_quick_create/i18n/sl.po b/base_optional_quick_create/i18n/sl.po index f7f462a57e1..f3c257a6cca 100644 --- a/base_optional_quick_create/i18n/sl.po +++ b/base_optional_quick_create/i18n/sl.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: server-tools (8.0)\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2015-09-29 11:14+0000\n" +"POT-Creation-Date: 2016-03-12 02:05+0000\n" "PO-Revision-Date: 2015-09-24 11:46+0000\n" "Last-Translator: Matjaž Mozetič \n" "Language-Team: Slovenian (http://www.transifex.com/oca/OCA-server-tools-8-0/language/sl/)\n" @@ -24,13 +24,13 @@ msgid "Avoid quick create" msgstr "Izogibanje hitremu ustvarjanju" #. module: base_optional_quick_create -#: code:addons/base_optional_quick_create/model.py:37 +#: code:addons/base_optional_quick_create/model.py:39 #, python-format msgid "Can't create quickly. Opening create form" msgstr "Ne morete hitro ustvariti. Odpiram obrazec za ustvarjanje" #. module: base_optional_quick_create -#: code:addons/base_optional_quick_create/model.py:36 +#: code:addons/base_optional_quick_create/model.py:38 #, python-format msgid "Error" msgstr "Napaka" diff --git a/base_optional_quick_create/i18n/tr.po b/base_optional_quick_create/i18n/tr.po new file mode 100644 index 00000000000..fc10db1a907 --- /dev/null +++ b/base_optional_quick_create/i18n/tr.po @@ -0,0 +1,41 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * base_optional_quick_create +# +# Translators: +# Ahmet Altınışık , 2016 +msgid "" +msgstr "" +"Project-Id-Version: server-tools (8.0)\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-03-12 02:05+0000\n" +"PO-Revision-Date: 2016-01-31 14:58+0000\n" +"Last-Translator: Ahmet Altınışık \n" +"Language-Team: Turkish (http://www.transifex.com/oca/OCA-server-tools-8-0/language/tr/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: tr\n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" + +#. module: base_optional_quick_create +#: field:ir.model,avoid_quick_create:0 +msgid "Avoid quick create" +msgstr "Hızlı oluşturmadan sakın" + +#. module: base_optional_quick_create +#: code:addons/base_optional_quick_create/model.py:39 +#, python-format +msgid "Can't create quickly. Opening create form" +msgstr "Hızlı oluşturulamıyor. Oluştur formu açılıyor." + +#. module: base_optional_quick_create +#: code:addons/base_optional_quick_create/model.py:38 +#, python-format +msgid "Error" +msgstr "Hata" + +#. module: base_optional_quick_create +#: model:ir.model,name:base_optional_quick_create.model_ir_model +msgid "Models" +msgstr "Modeller" diff --git a/base_optional_quick_create/model.py b/base_optional_quick_create/model.py deleted file mode 100644 index 00862f0c70d..00000000000 --- 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