From c98ab664c329128c22d3bace32bc683bd618eab2 Mon Sep 17 00:00:00 2001 From: Florent de Labarre Date: Sun, 5 Jun 2016 10:59:23 +0200 Subject: [PATCH 01/13] Update V9 --- base_optional_quick_create/AUTHORS.txt | 1 + base_optional_quick_create/__openerp__.py | 7 ++-- base_optional_quick_create/i18n/de.po | 41 ++++++++++++++++++++++ base_optional_quick_create/i18n/en.po | 6 ++-- base_optional_quick_create/i18n/es.po | 42 +++++++++++++++++++++++ base_optional_quick_create/i18n/fr.po | 24 ++++++++----- base_optional_quick_create/i18n/it.po | 41 ++++++++++++++++++++++ base_optional_quick_create/i18n/pt_BR.po | 6 ++-- base_optional_quick_create/i18n/sl.po | 6 ++-- base_optional_quick_create/i18n/tr.po | 41 ++++++++++++++++++++++ base_optional_quick_create/model.py | 36 ++++++++++--------- base_optional_quick_create/model_view.xml | 2 +- 12 files changed, 215 insertions(+), 38 deletions(-) create mode 100644 base_optional_quick_create/i18n/de.po create mode 100644 base_optional_quick_create/i18n/es.po create mode 100644 base_optional_quick_create/i18n/it.po create mode 100644 base_optional_quick_create/i18n/tr.po diff --git a/base_optional_quick_create/AUTHORS.txt b/base_optional_quick_create/AUTHORS.txt index 7106ca0eb6c..d9d84d62f90 100644 --- a/base_optional_quick_create/AUTHORS.txt +++ b/base_optional_quick_create/AUTHORS.txt @@ -1 +1,2 @@ Lorenzo Battistini +Contributor 2016 Florent de Labarre diff --git a/base_optional_quick_create/__openerp__.py b/base_optional_quick_create/__openerp__.py index 53c6ad431ae..33bbe70e7b4 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,7 +21,7 @@ { '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': """ @@ -32,7 +33,7 @@ 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'], @@ -41,5 +42,5 @@ ], "demo": [], 'test': [], - 'installable': False + "installable": True } 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..ac8b223b6b8 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" "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 index 00862f0c70d..ac5d8b57160 100644 --- a/base_optional_quick_create/model.py +++ b/base_optional_quick_create/model.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 @@ -18,46 +19,47 @@ # ############################################################################## -from openerp.osv import orm, fields +from openerp.osv import osv, fields from openerp import SUPERUSER_ID +from openerp.exceptions import UserError, AccessError from openerp.tools.translate import _ -class ir_model(orm.Model): +class IrModel(osv.osv): _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 _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 - 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._patch_method('name_create', _wrap_name_create()) 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(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) - self._register_hook(cr, [res_id]) + 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) - self._register_hook(cr, ids) + res = super(IrModel, self).write(cr, uid, ids, vals, context=context) + self._patch_quick_create(cr, ids) return res diff --git a/base_optional_quick_create/model_view.xml b/base_optional_quick_create/model_view.xml index f36877fed4e..add2f498007 100644 --- a/base_optional_quick_create/model_view.xml +++ b/base_optional_quick_create/model_view.xml @@ -5,7 +5,7 @@ ir.model - + From bfa1bfdba3e451c931c70328c3cf316ec9495b40 Mon Sep 17 00:00:00 2001 From: Florent de Labarre Date: Sun, 5 Jun 2016 18:14:02 +0200 Subject: [PATCH 02/13] Conformity Use Model Add README --- base_optional_quick_create/README.rst | 86 +++++++++++++++++++ base_optional_quick_create/__init__.py | 2 +- base_optional_quick_create/__openerp__.py | 11 +-- .../base_optional_quick_create.py | 64 ++++++++++++++ .../base_optional_quick_create_view.xml | 14 +++ .../i18n/base_optional_quick_create.pot | 2 +- base_optional_quick_create/i18n/fr.po | 2 +- 7 files changed, 168 insertions(+), 13 deletions(-) create mode 100644 base_optional_quick_create/README.rst create mode 100644 base_optional_quick_create/base_optional_quick_create.py create mode 100644 base_optional_quick_create/base_optional_quick_create_view.xml diff --git a/base_optional_quick_create/README.rst b/base_optional_quick_create/README.rst new file mode 100644 index 00000000000..b7a632fa4c7 --- /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 +====================== + +* ... + +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 33bbe70e7b4..2c1c1ba9caf 100644 --- a/base_optional_quick_create/__openerp__.py +++ b/base_optional_quick_create/__openerp__.py @@ -24,21 +24,12 @@ '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), 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': [], 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..b373953ecb2 --- /dev/null +++ b/base_optional_quick_create/base_optional_quick_create.py @@ -0,0 +1,64 @@ +# -*- 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 import SUPERUSER_ID +from openerp.exceptions import UserError, AccessError +from openerp.tools.translate import _ + + +class IrModel(models.Model): + _inherit = 'ir.model' + + avoid_quick_create = fields.boolean('Disabled quick create') + + @api.model + 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): + 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 + return True + @api.model + def _register_hook(self, cr): + self._patch_quick_create(cr, self.search(cr, SUPERUSER_ID, [])) + return super(IrModel, self)._register_hook(cr) + @api.model + 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 + @api.multi + 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 diff --git a/base_optional_quick_create/base_optional_quick_create_view.xml b/base_optional_quick_create/base_optional_quick_create_view.xml new file mode 100644 index 00000000000..add2f498007 --- /dev/null +++ b/base_optional_quick_create/base_optional_quick_create_view.xml @@ -0,0 +1,14 @@ + + + + + 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/fr.po b/base_optional_quick_create/i18n/fr.po index ac8b223b6b8..b75691f7ec7 100644 --- a/base_optional_quick_create/i18n/fr.po +++ b/base_optional_quick_create/i18n/fr.po @@ -14,7 +14,7 @@ # 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: 2016-05-12 14:33+0000\n" "PO-Revision-Date: 2016-05-08 17:01+0000\n" From 0942596ea26815f3e1210611a7afa8d3f143e1a9 Mon Sep 17 00:00:00 2001 From: Florent de Labarre Date: Sun, 5 Jun 2016 18:19:43 +0200 Subject: [PATCH 03/13] Remove old files --- base_optional_quick_create/AUTHORS.txt | 2 - base_optional_quick_create/model.py | 65 ----------------------- base_optional_quick_create/model_view.xml | 14 ----- 3 files changed, 81 deletions(-) delete mode 100644 base_optional_quick_create/AUTHORS.txt delete mode 100644 base_optional_quick_create/model.py delete mode 100644 base_optional_quick_create/model_view.xml diff --git a/base_optional_quick_create/AUTHORS.txt b/base_optional_quick_create/AUTHORS.txt deleted file mode 100644 index d9d84d62f90..00000000000 --- a/base_optional_quick_create/AUTHORS.txt +++ /dev/null @@ -1,2 +0,0 @@ -Lorenzo Battistini -Contributor 2016 Florent de Labarre diff --git a/base_optional_quick_create/model.py b/base_optional_quick_create/model.py deleted file mode 100644 index ac5d8b57160..00000000000 --- a/base_optional_quick_create/model.py +++ /dev/null @@ -1,65 +0,0 @@ -# -*- 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.osv import osv, fields -from openerp import SUPERUSER_ID -from openerp.exceptions import UserError, AccessError -from openerp.tools.translate import _ - - -class IrModel(osv.osv): - _inherit = 'ir.model' - - _columns = { - 'avoid_quick_create': fields.boolean('Avoid quick create'), - } - - 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): - 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 - 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 diff --git a/base_optional_quick_create/model_view.xml b/base_optional_quick_create/model_view.xml deleted file mode 100644 index add2f498007..00000000000 --- a/base_optional_quick_create/model_view.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - ir.model - - - - - - - - - From d57c2ab192bedd5b65163843a747c29db00ffb25 Mon Sep 17 00:00:00 2001 From: Florent de Labarre Date: Sun, 5 Jun 2016 18:22:46 +0200 Subject: [PATCH 04/13] Update Readme --- base_optional_quick_create/README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base_optional_quick_create/README.rst b/base_optional_quick_create/README.rst index b7a632fa4c7..17717331a63 100644 --- a/base_optional_quick_create/README.rst +++ b/base_optional_quick_create/README.rst @@ -46,7 +46,7 @@ To use this module, you need to: Known issues / Roadmap ====================== -* ... +* No roadmap Bug Tracker =========== From 850c7b788eba4ccc14e56cf4ac853b06b7921325 Mon Sep 17 00:00:00 2001 From: Florent de Labarre Date: Sun, 5 Jun 2016 18:28:20 +0200 Subject: [PATCH 05/13] update test_flake --- base_optional_quick_create/__openerp__.py | 3 ++- base_optional_quick_create/base_optional_quick_create.py | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/base_optional_quick_create/__openerp__.py b/base_optional_quick_create/__openerp__.py index 2c1c1ba9caf..d4ef735a648 100644 --- a/base_optional_quick_create/__openerp__.py +++ b/base_optional_quick_create/__openerp__.py @@ -24,7 +24,8 @@ 'version': '9.0.0.1.0', 'category': 'Tools', 'summary': "Avoid 'quick create' on m2o fields, on a 'by model' basis", - 'author': "Agile Business Group,Odoo Community Association (OCA), Florent de Labarre", + 'author': "Agile Business Group,Odoo Community \ + Association (OCA), Florent de Labarre", 'website': 'http://www.agilebg.com', 'license': 'AGPL-3', "depends": ['base'], diff --git a/base_optional_quick_create/base_optional_quick_create.py b/base_optional_quick_create/base_optional_quick_create.py index b373953ecb2..824c19886b0 100644 --- a/base_optional_quick_create/base_optional_quick_create.py +++ b/base_optional_quick_create/base_optional_quick_create.py @@ -21,7 +21,7 @@ from openerp import api, fields, models, _ from openerp import SUPERUSER_ID -from openerp.exceptions import UserError, AccessError +from openerp.exceptions import UserError from openerp.tools.translate import _ @@ -29,7 +29,7 @@ class IrModel(models.Model): _inherit = 'ir.model' avoid_quick_create = fields.boolean('Disabled quick create') - + @api.model def _patch_quick_create(self, cr, ids): @@ -46,15 +46,18 @@ def wrapper(self, cr, uid, name, context=None): model_obj._patch_method('name_create', _wrap_name_create()) model_obj.check_quick_create = True return True + @api.model def _register_hook(self, cr): self._patch_quick_create(cr, self.search(cr, SUPERUSER_ID, [])) return super(IrModel, self)._register_hook(cr) + @api.model 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 + @api.multi def write(self, cr, uid, ids, vals, context=None): if isinstance(ids, (int, long)): From 48ac3ed81c6113eecc8690faed3d3361cabf4785 Mon Sep 17 00:00:00 2001 From: Florent de Labarre Date: Sun, 5 Jun 2016 18:41:39 +0200 Subject: [PATCH 06/13] update field avoid quick create --- base_optional_quick_create/base_optional_quick_create.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/base_optional_quick_create/base_optional_quick_create.py b/base_optional_quick_create/base_optional_quick_create.py index 824c19886b0..e08f58fe768 100644 --- a/base_optional_quick_create/base_optional_quick_create.py +++ b/base_optional_quick_create/base_optional_quick_create.py @@ -28,7 +28,8 @@ class IrModel(models.Model): _inherit = 'ir.model' - avoid_quick_create = fields.boolean('Disabled quick create') + avoid_quick_create = fields.Boolean(string = 'Disabled quick create', + help="Check this box if you want to disable the quick create") @api.model def _patch_quick_create(self, cr, ids): From fc25d4d97b74d287f017931999646108c636f92e Mon Sep 17 00:00:00 2001 From: Florent de Labarre Date: Sun, 5 Jun 2016 18:44:26 +0200 Subject: [PATCH 07/13] update field avoid_quick_create --- base_optional_quick_create/base_optional_quick_create.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/base_optional_quick_create/base_optional_quick_create.py b/base_optional_quick_create/base_optional_quick_create.py index e08f58fe768..44c3741f03e 100644 --- a/base_optional_quick_create/base_optional_quick_create.py +++ b/base_optional_quick_create/base_optional_quick_create.py @@ -28,8 +28,8 @@ class IrModel(models.Model): _inherit = 'ir.model' - avoid_quick_create = fields.Boolean(string = 'Disabled quick create', - help="Check this box if you want to disable the quick create") + avoid_quick_create = fields.Boolean(string='Disabled quick create', + help="Check this box if you want to disable the quick create") @api.model def _patch_quick_create(self, cr, ids): From f6845f299328eec744bbe6aff2b03b163ae9033c Mon Sep 17 00:00:00 2001 From: Florent de Labarre Date: Sun, 5 Jun 2016 18:47:49 +0200 Subject: [PATCH 08/13] add indent --- base_optional_quick_create/base_optional_quick_create.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base_optional_quick_create/base_optional_quick_create.py b/base_optional_quick_create/base_optional_quick_create.py index 44c3741f03e..cef89c93caa 100644 --- a/base_optional_quick_create/base_optional_quick_create.py +++ b/base_optional_quick_create/base_optional_quick_create.py @@ -29,7 +29,7 @@ class IrModel(models.Model): _inherit = 'ir.model' avoid_quick_create = fields.Boolean(string='Disabled quick create', - help="Check this box if you want to disable the quick create") + help="Check this box if you want to disable the quick create") @api.model def _patch_quick_create(self, cr, ids): From b106fcbd4743e2c1d4e7b4db2b92e7baa97d8eb6 Mon Sep 17 00:00:00 2001 From: Florent de Labarre Date: Sun, 5 Jun 2016 18:52:31 +0200 Subject: [PATCH 09/13] add indent --- base_optional_quick_create/base_optional_quick_create.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/base_optional_quick_create/base_optional_quick_create.py b/base_optional_quick_create/base_optional_quick_create.py index cef89c93caa..5233449eb02 100644 --- a/base_optional_quick_create/base_optional_quick_create.py +++ b/base_optional_quick_create/base_optional_quick_create.py @@ -29,7 +29,8 @@ class IrModel(models.Model): _inherit = 'ir.model' avoid_quick_create = fields.Boolean(string='Disabled quick create', - help="Check this box if you want to disable the quick create") + help="Check this box if you want to \ + disable the quick create") @api.model def _patch_quick_create(self, cr, ids): From 3a36c080a7e8030e4a5aa071ef66f4b89d808b9f Mon Sep 17 00:00:00 2001 From: Florent de Labarre Date: Sun, 5 Jun 2016 18:57:33 +0200 Subject: [PATCH 10/13] update field --- base_optional_quick_create/base_optional_quick_create.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/base_optional_quick_create/base_optional_quick_create.py b/base_optional_quick_create/base_optional_quick_create.py index 5233449eb02..a9bf9863fd2 100644 --- a/base_optional_quick_create/base_optional_quick_create.py +++ b/base_optional_quick_create/base_optional_quick_create.py @@ -28,9 +28,7 @@ class IrModel(models.Model): _inherit = 'ir.model' - avoid_quick_create = fields.Boolean(string='Disabled quick create', - help="Check this box if you want to \ - disable the quick create") + avoid_quick_create = fields.Boolean(string='Disabled quick create', help="Check this box if you want to disable the quick create") @api.model def _patch_quick_create(self, cr, ids): From a0aad7aca8c88d3a0a2a8c8be9f33b7df486b8d9 Mon Sep 17 00:00:00 2001 From: Florent de Labarre Date: Sun, 5 Jun 2016 20:23:59 +0200 Subject: [PATCH 11/13] @api v7 --- .../base_optional_quick_create.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/base_optional_quick_create/base_optional_quick_create.py b/base_optional_quick_create/base_optional_quick_create.py index a9bf9863fd2..6c83d00ade1 100644 --- a/base_optional_quick_create/base_optional_quick_create.py +++ b/base_optional_quick_create/base_optional_quick_create.py @@ -20,17 +20,18 @@ ############################################################################## from openerp import api, fields, models, _ -from openerp import SUPERUSER_ID 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', help="Check this box if you want to disable the quick create") - - @api.model + avoid_quick_create = fields.Boolean(string='Disabled quick create', + help="Check this box if you\ + want to disable the quick create") + @api.v7 def _patch_quick_create(self, cr, ids): def _wrap_name_create(): @@ -46,19 +47,16 @@ def wrapper(self, cr, uid, name, context=None): model_obj._patch_method('name_create', _wrap_name_create()) model_obj.check_quick_create = True return True - - @api.model + @api.v7 def _register_hook(self, cr): self._patch_quick_create(cr, self.search(cr, SUPERUSER_ID, [])) return super(IrModel, self)._register_hook(cr) - - @api.model + @api.v7 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 - - @api.multi + @api.v7 def write(self, cr, uid, ids, vals, context=None): if isinstance(ids, (int, long)): ids = [ids] From 13c6545937433dc4f18f6183c0eff75b58c96e89 Mon Sep 17 00:00:00 2001 From: Florent de Labarre Date: Sun, 5 Jun 2016 20:27:46 +0200 Subject: [PATCH 12/13] remove help --- base_optional_quick_create/base_optional_quick_create.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/base_optional_quick_create/base_optional_quick_create.py b/base_optional_quick_create/base_optional_quick_create.py index 6c83d00ade1..ef0d5e83705 100644 --- a/base_optional_quick_create/base_optional_quick_create.py +++ b/base_optional_quick_create/base_optional_quick_create.py @@ -28,9 +28,8 @@ class IrModel(models.Model): _inherit = 'ir.model' - avoid_quick_create = fields.Boolean(string='Disabled quick create', - help="Check this box if you\ - want to disable the quick create") + avoid_quick_create = fields.Boolean(string='Disabled quick create',) + @api.v7 def _patch_quick_create(self, cr, ids): @@ -47,15 +46,18 @@ def wrapper(self, cr, uid, name, context=None): model_obj._patch_method('name_create', _wrap_name_create()) model_obj.check_quick_create = True return True + @api.v7 def _register_hook(self, cr): self._patch_quick_create(cr, self.search(cr, SUPERUSER_ID, [])) 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) 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)): From c4155025c773bacdb3062c25d0f9438ba5527e14 Mon Sep 17 00:00:00 2001 From: IguanaYachts Date: Mon, 6 Jun 2016 09:08:52 +0200 Subject: [PATCH 13/13] update --- .../base_optional_quick_create.py | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/base_optional_quick_create/base_optional_quick_create.py b/base_optional_quick_create/base_optional_quick_create.py index ef0d5e83705..ea0e9400ceb 100644 --- a/base_optional_quick_create/base_optional_quick_create.py +++ b/base_optional_quick_create/base_optional_quick_create.py @@ -39,23 +39,24 @@ def wrapper(self, cr, uid, name, context=None): 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 + 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): - self._patch_quick_create(cr, self.search(cr, SUPERUSER_ID, [])) + 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) - self._patch_quick_create(cr, [res_id]) + if vals.get('avoid_quick_create'): + self._patch_quick_create(cr, [res_id]) return res_id @api.v7 @@ -63,5 +64,12 @@ 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) + 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