Merge lp:~elbati/server-env-tools/adding_base_optional_quick_create_7 into lp:~server-env-tools-core-editors/server-env-tools/7.0

Proposed by Lorenzo Battistini
Status: Merged
Merged at revision: 42
Proposed branch: lp:~elbati/server-env-tools/adding_base_optional_quick_create_7
Merge into: lp:~server-env-tools-core-editors/server-env-tools/7.0
Diff against target: 163 lines (+138/-0)
5 files modified
base_optional_quick_create/AUTHORS.txt (+1/-0)
base_optional_quick_create/__init__.py (+20/-0)
base_optional_quick_create/__openerp__.py (+43/-0)
base_optional_quick_create/model.py (+60/-0)
base_optional_quick_create/model_view.xml (+14/-0)
To merge this branch: bzr merge lp:~elbati/server-env-tools/adding_base_optional_quick_create_7
Reviewer Review Type Date Requested Status
Guewen Baconnier @ Camptocamp code review, no test Approve
Holger Brunn (Therp) Approve
Review via email: mp+170569@code.launchpad.net

Description of the change

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.

To post a comment you must log in.
Revision history for this message
Holger Brunn (Therp) (hbrunn) wrote :

Does this survive a server restart? I'd expect to have to patch BaseModel.__init__ for it to work.

But then on the other hand, have you considered to patch the many2one widget so that we can set an attribute or a context key to suppress quick create? This seems to me to be more useful as I think you more often need to control that behavior on a per form level and not on a per model level.

review: Needs Information
Revision history for this message
Lorenzo Battistini (elbati) wrote :

On 06/24/2013 11:45 AM, Holger Brunn (Therp) wrote:
> Does this survive a server restart? I'd expect to have to patch BaseModel.__init__ for it to work.

In my tests, it does.
Consider that I followed the same way followed by base_action_rule
<http://bazaar.launchpad.net/%7Eopenerp/openobject-addons/7.0/view/9277/base_action_rule/base_action_rule.py#L132>.

> But then on the other hand, have you considered to patch the many2one widget so that we can set an attribute or a context key to suppress quick create? This seems to me to be more useful as I think you more often need to control that behavior on a per form level and not on a per model level.

This use case (form based) should already be covered by web_m2o_enhanced
<https://github.com/0k/web_m2o_enhanced> module.
But we realized that a per model option would often be more useful.

--
Lorenzo Battistini

Revision history for this message
Holger Brunn (Therp) (hbrunn) wrote :

Thanks for your comments, approving now

review: Approve
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

LGTM

review: Approve (code review, no test)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'base_optional_quick_create'
2=== added file 'base_optional_quick_create/AUTHORS.txt'
3--- base_optional_quick_create/AUTHORS.txt 1970-01-01 00:00:00 +0000
4+++ base_optional_quick_create/AUTHORS.txt 2013-06-20 09:50:33 +0000
5@@ -0,0 +1,1 @@
6+Lorenzo Battistini <lorenzo.battistini@agilebg.com>
7
8=== added file 'base_optional_quick_create/__init__.py'
9--- base_optional_quick_create/__init__.py 1970-01-01 00:00:00 +0000
10+++ base_optional_quick_create/__init__.py 2013-06-20 09:50:33 +0000
11@@ -0,0 +1,20 @@
12+# -*- coding: utf-8 -*-
13+##############################################################################
14+#
15+# Copyright (C) 2013 Agile Business Group sagl (<http://www.agilebg.com>)
16+#
17+# This program is free software: you can redistribute it and/or modify
18+# it under the terms of the GNU Affero General Public License as published
19+# by the Free Software Foundation, either version 3 of the License, or
20+# (at your option) any later version.
21+#
22+# This program is distributed in the hope that it will be useful,
23+# but WITHOUT ANY WARRANTY; without even the implied warranty of
24+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25+# GNU Affero General Public License for more details.
26+#
27+# You should have received a copy of the GNU Affero General Public License
28+# along with this program. If not, see <http://www.gnu.org/licenses/>.
29+#
30+##############################################################################
31+import model
32
33=== added file 'base_optional_quick_create/__openerp__.py'
34--- base_optional_quick_create/__openerp__.py 1970-01-01 00:00:00 +0000
35+++ base_optional_quick_create/__openerp__.py 2013-06-20 09:50:33 +0000
36@@ -0,0 +1,43 @@
37+# -*- coding: utf-8 -*-
38+##############################################################################
39+#
40+# Copyright (C) 2013 Agile Business Group sagl (<http://www.agilebg.com>)
41+#
42+# This program is free software: you can redistribute it and/or modify
43+# it under the terms of the GNU Affero General Public License as published
44+# by the Free Software Foundation, either version 3 of the License, or
45+# (at your option) any later version.
46+#
47+# This program is distributed in the hope that it will be useful,
48+# but WITHOUT ANY WARRANTY; without even the implied warranty of
49+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
50+# GNU Affero General Public License for more details.
51+#
52+# You should have received a copy of the GNU Affero General Public License
53+# along with this program. If not, see <http://www.gnu.org/licenses/>.
54+#
55+##############################################################################
56+
57+{
58+ 'name': "Optional quick create",
59+ 'version': '0.1',
60+ 'category': 'Tools',
61+ 'description': """
62+This module allows to avoid to 'quick create' new records, through many2one fields, for a specific model.
63+You can configure which models should allow 'quick create'. When specified, the 'quick create' option will always open the standard create form.
64+
65+Got the idea from https://twitter.com/nbessi/status/337869826028605441
66+""",
67+ 'author': 'Agile Business Group',
68+ 'website': 'http://www.agilebg.com',
69+ 'license': 'AGPL-3',
70+ "depends": ['base'],
71+ "data": [
72+ 'model_view.xml',
73+ ],
74+ "demo": [],
75+ 'test': [
76+ ],
77+ "active": False,
78+ "installable": True
79+}
80
81=== added file 'base_optional_quick_create/model.py'
82--- base_optional_quick_create/model.py 1970-01-01 00:00:00 +0000
83+++ base_optional_quick_create/model.py 2013-06-20 09:50:33 +0000
84@@ -0,0 +1,60 @@
85+# -*- coding: utf-8 -*-
86+##############################################################################
87+#
88+# Copyright (C) 2013 Agile Business Group sagl (<http://www.agilebg.com>)
89+#
90+# This program is free software: you can redistribute it and/or modify
91+# it under the terms of the GNU Affero General Public License as published
92+# by the Free Software Foundation, either version 3 of the License, or
93+# (at your option) any later version.
94+#
95+# This program is distributed in the hope that it will be useful,
96+# but WITHOUT ANY WARRANTY; without even the implied warranty of
97+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
98+# GNU Affero General Public License for more details.
99+#
100+# You should have received a copy of the GNU Affero General Public License
101+# along with this program. If not, see <http://www.gnu.org/licenses/>.
102+#
103+##############################################################################
104+
105+from openerp.osv import orm, fields
106+from openerp import SUPERUSER_ID
107+from openerp.tools.translate import _
108+
109+class ir_model(orm.Model):
110+
111+ _inherit = 'ir.model'
112+
113+ _columns = {
114+ 'avoid_quick_create': fields.boolean('Avoid quick create'),
115+ }
116+
117+ def _wrap_name_create(self, old_create, model):
118+ def wrapper(cr, uid, name, context=None):
119+ raise orm.except_orm(_('Error'), _("Can't create quickly. Opening create form"))
120+ return wrapper
121+
122+ def _register_hook(self, cr, ids=None):
123+ if ids is None:
124+ ids = self.search(cr, SUPERUSER_ID, [])
125+ for model in self.browse(cr, SUPERUSER_ID, ids):
126+ if model.avoid_quick_create:
127+ model_name = model.model
128+ model_obj = self.pool.get(model_name)
129+ if not hasattr(model_obj, 'check_quick_create'):
130+ model_obj.name_create = self._wrap_name_create(model_obj.name_create, model_name)
131+ model_obj.check_quick_create = True
132+ return True
133+
134+ def create(self, cr, uid, vals, context=None):
135+ res_id = super(ir_model, self).create(cr, uid, vals, context=context)
136+ self._register_hook(cr, [res_id])
137+ return res_id
138+
139+ def write(self, cr, uid, ids, vals, context=None):
140+ if isinstance(ids, (int, long)):
141+ ids = [ids]
142+ super(ir_model, self).write(cr, uid, ids, vals, context=context)
143+ self._register_hook(cr, ids)
144+ return True
145
146=== added file 'base_optional_quick_create/model_view.xml'
147--- base_optional_quick_create/model_view.xml 1970-01-01 00:00:00 +0000
148+++ base_optional_quick_create/model_view.xml 2013-06-20 09:50:33 +0000
149@@ -0,0 +1,14 @@
150+<?xml version="1.0" encoding="utf-8"?>
151+<openerp>
152+ <data>
153+ <record id="view_model_form" model="ir.ui.view">
154+ <field name="model">ir.model</field>
155+ <field name="inherit_id" ref="base.view_model_form"></field>
156+ <field name="arch" type="xml">
157+ <field name="osv_memory" position="after">
158+ <field name="avoid_quick_create"></field>
159+ </field>
160+ </field>
161+ </record>
162+ </data>
163+</openerp>