Merge lp:~camptocamp/openerp-product-attributes/7.0-partner-attributes-lep into lp:~product-core-editors/openerp-product-attributes/7.0
- 7.0-partner-attributes-lep
- Merge into 7.0
Status: | Merged |
---|---|
Merged at revision: | 249 |
Proposed branch: | lp:~camptocamp/openerp-product-attributes/7.0-partner-attributes-lep |
Merge into: | lp:~product-core-editors/openerp-product-attributes/7.0 |
Diff against target: |
487 lines (+444/-0) 8 files modified
partner_custom_attributes/__init__.py (+25/-0) partner_custom_attributes/__openerp__.py (+52/-0) partner_custom_attributes/custom_attributes_view.xml (+50/-0) partner_custom_attributes/partner.py (+148/-0) partner_custom_attributes/partner_view.xml (+42/-0) partner_custom_attributes/wizard/__init__.py (+25/-0) partner_custom_attributes/wizard/open_partner_by_attribute_set.py (+67/-0) partner_custom_attributes/wizard/open_partner_by_attribute_set.xml (+35/-0) |
To merge this branch: | bzr merge lp:~camptocamp/openerp-product-attributes/7.0-partner-attributes-lep |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Leonardo Pistone | Abstain | ||
Yannick Vaucher @ Camptocamp | code review, no test | Approve | |
Nicolas Bessi - Camptocamp (community) | Approve | ||
Alexandre Fayolle - camptocamp | code review, test | Approve | |
Review via email: mp+217234@code.launchpad.net |
Commit message
Description of the change
add module partner_
- 244. By Leonardo Pistone
-
[del] workaronud for text field size bug on partner_attributes
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote : | # |
- 245. By Leonardo Pistone
-
[ref] use self.pool['model'] and del useless context handling
- 246. By Leonardo Pistone
-
[ref] convert xml indentation to 2-space
Leonardo Pistone (lepistone) wrote : | # |
Yannick, I made the changes you suggest. Thanks
- 247. By Alexandre Fayolle - camptocamp
-
[IMP] fix typos, fix import
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote : | # |
fixed a couple of typos
I'm a bit awkward with merging into openerp-
still LGTM
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote : | # |
I would add a little explaination on how to use it but LGTM.
Leonardo Pistone (lepistone) wrote : | # |
@alexandre: 100% agree with your remark on the choice of repo.
@nicolas: agree, but unsure whether some doc should go into base-custom-
thanks
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote : | # |
Thanks for the changes
LGTM
Leonardo Pistone (lepistone) wrote : | # |
Thanks for your reviews.
I found out that the view with the attributes details has some issue. I will fix that and then merge.
- 248. By Leonardo Pistone
-
[fix] old reference to lots in partner attributes
Leonardo Pistone (lepistone) wrote : | # |
My issue in the view should be fixed now. Thanks
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote : | # |
Well I would like to have the ref on the excpetion before merging.
Leonardo Pistone (lepistone) wrote : | # |
@nicolas: attribute fields were not shown because of the error fixed on commit 248
Preview Diff
1 | === added directory 'partner_custom_attributes' | |||
2 | === added file 'partner_custom_attributes/__init__.py' | |||
3 | --- partner_custom_attributes/__init__.py 1970-01-01 00:00:00 +0000 | |||
4 | +++ partner_custom_attributes/__init__.py 2014-05-16 10:38:28 +0000 | |||
5 | @@ -0,0 +1,25 @@ | |||
6 | 1 | # -*- coding: utf-8 -*- | ||
7 | 2 | ############################################################################### | ||
8 | 3 | # # | ||
9 | 4 | # Author: Leonardo Pistone <leonardo.pistone@camptocamp.com> # | ||
10 | 5 | # Copyright 2014 Camptocamp SA # | ||
11 | 6 | # # | ||
12 | 7 | # Inspired by the module product_custom_attributes # | ||
13 | 8 | # by Benoît GUILLOT <benoit.guillot@akretion.com>, Akretion # | ||
14 | 9 | # # | ||
15 | 10 | # This program is free software: you can redistribute it and/or modify # | ||
16 | 11 | # it under the terms of the GNU Affero General Public License as # | ||
17 | 12 | # published by the Free Software Foundation, either version 3 of the # | ||
18 | 13 | # License, or (at your option) any later version. # | ||
19 | 14 | # # | ||
20 | 15 | # This program is distributed in the hope that it will be useful, # | ||
21 | 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | ||
22 | 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | ||
23 | 18 | # GNU Affero General Public License for more details. # | ||
24 | 19 | # # | ||
25 | 20 | # You should have received a copy of the GNU Affero General Public License # | ||
26 | 21 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | ||
27 | 22 | # # | ||
28 | 23 | ############################################################################### | ||
29 | 24 | from . import partner # noqa | ||
30 | 25 | from . import wizard # noqa | ||
31 | 0 | 26 | ||
32 | === added file 'partner_custom_attributes/__openerp__.py' | |||
33 | --- partner_custom_attributes/__openerp__.py 1970-01-01 00:00:00 +0000 | |||
34 | +++ partner_custom_attributes/__openerp__.py 2014-05-16 10:38:28 +0000 | |||
35 | @@ -0,0 +1,52 @@ | |||
36 | 1 | # -*- coding: utf-8 -*- | ||
37 | 2 | ############################################################################### | ||
38 | 3 | # # | ||
39 | 4 | # Author: Leonardo Pistone <leonardo.pistone@camptocamp.com> # | ||
40 | 5 | # Copyright 2014 Camptocamp SA # | ||
41 | 6 | # # | ||
42 | 7 | # Inspired by the module product_custom_attributes # | ||
43 | 8 | # by Benoît GUILLOT <benoit.guillot@akretion.com>, Akretion # | ||
44 | 9 | # # | ||
45 | 10 | # This program is free software: you can redistribute it and/or modify # | ||
46 | 11 | # it under the terms of the GNU Affero General Public License as # | ||
47 | 12 | # published by the Free Software Foundation, either version 3 of the # | ||
48 | 13 | # License, or (at your option) any later version. # | ||
49 | 14 | # # | ||
50 | 15 | # This program is distributed in the hope that it will be useful, # | ||
51 | 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | ||
52 | 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | ||
53 | 18 | # GNU Affero General Public License for more details. # | ||
54 | 19 | # # | ||
55 | 20 | # You should have received a copy of the GNU Affero General Public License # | ||
56 | 21 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | ||
57 | 22 | # # | ||
58 | 23 | ############################################################################### | ||
59 | 24 | |||
60 | 25 | {'name': 'Partner Custom Attributes', | ||
61 | 26 | 'version': '0.1.0', | ||
62 | 27 | 'category': 'Generic Modules/Others', | ||
63 | 28 | 'license': 'AGPL-3', | ||
64 | 29 | 'description': """ | ||
65 | 30 | Partner custom attributes | ||
66 | 31 | ========================= | ||
67 | 32 | |||
68 | 33 | This module adds the possibility to easily create custom fields on Partners. | ||
69 | 34 | Each partner can be linked to an attribute set. Each attribute has custom | ||
70 | 35 | fields. | ||
71 | 36 | |||
72 | 37 | This module is inspired by the module product_custom_attributes by Benoît | ||
73 | 38 | GUILLOT, Akretion | ||
74 | 39 | |||
75 | 40 | """, | ||
76 | 41 | 'complexity': 'normal', | ||
77 | 42 | 'author': 'Camptocamp', | ||
78 | 43 | 'website': 'http://www.camptocamp.com/', | ||
79 | 44 | 'depends': ['base_custom_attributes'], | ||
80 | 45 | 'data': ['partner_view.xml', | ||
81 | 46 | 'custom_attributes_view.xml', | ||
82 | 47 | 'wizard/open_partner_by_attribute_set.xml' | ||
83 | 48 | ], | ||
84 | 49 | 'test': ['test/partner_attribute_test.yml'], | ||
85 | 50 | 'installable': True, | ||
86 | 51 | 'active': False, | ||
87 | 52 | } | ||
88 | 0 | 53 | ||
89 | === added file 'partner_custom_attributes/custom_attributes_view.xml' | |||
90 | --- partner_custom_attributes/custom_attributes_view.xml 1970-01-01 00:00:00 +0000 | |||
91 | +++ partner_custom_attributes/custom_attributes_view.xml 2014-05-16 10:38:28 +0000 | |||
92 | @@ -0,0 +1,50 @@ | |||
93 | 1 | <?xml version="1.0" encoding="utf-8"?> | ||
94 | 2 | |||
95 | 3 | <openerp> | ||
96 | 4 | <data> | ||
97 | 5 | |||
98 | 6 | <menuitem id="menu_attribute_in_config_partner" name="Attributes" | ||
99 | 7 | parent="base.menu_config_address_book" sequence="20"/> | ||
100 | 8 | |||
101 | 9 | <record id="attribute_set_form_action" model="ir.actions.act_window"> | ||
102 | 10 | <field name="name">Partner Attribute Sets</field> | ||
103 | 11 | <field name="res_model">attribute.set</field> | ||
104 | 12 | <field name="view_type">form</field> | ||
105 | 13 | <field name="view_mode">tree,form</field> | ||
106 | 14 | <field name="search_view_id" ref="base_custom_attributes.view_attribute_set_search"/> | ||
107 | 15 | <field name="context">{"force_model": 'res.partner'}</field> | ||
108 | 16 | <field name="help"></field> | ||
109 | 17 | </record> | ||
110 | 18 | |||
111 | 19 | <record id="attribute_group_form_action" model="ir.actions.act_window"> | ||
112 | 20 | <field name="name">Attribute Groups</field> | ||
113 | 21 | <field name="res_model">attribute.group</field> | ||
114 | 22 | <field name="view_type">form</field> | ||
115 | 23 | <field name="view_mode">tree,form</field> | ||
116 | 24 | <field name="search_view_id" ref="base_custom_attributes.view_attribute_attribute_search"/> | ||
117 | 25 | <field name="context">{"force_model": 'res.partner'}</field> | ||
118 | 26 | <field name="help"></field> | ||
119 | 27 | </record> | ||
120 | 28 | |||
121 | 29 | <record id="attribute_attribute_form_action" model="ir.actions.act_window"> | ||
122 | 30 | <field name="name">Partner Attribute</field> | ||
123 | 31 | <field name="res_model">attribute.attribute</field> | ||
124 | 32 | <field name="view_type">form</field> | ||
125 | 33 | <field name="view_mode">tree,form</field> | ||
126 | 34 | <field name="search_view_id" ref="base_custom_attributes.view_attribute_attribute_search"/> | ||
127 | 35 | <field name="context">{"force_model": 'res.partner'}</field> | ||
128 | 36 | <field name="help"></field> | ||
129 | 37 | </record> | ||
130 | 38 | |||
131 | 39 | <menuitem | ||
132 | 40 | action="attribute_set_form_action" id="menu_attribute_set_action" | ||
133 | 41 | parent="partner_custom_attributes.menu_attribute_in_config_partner" sequence="1"/> | ||
134 | 42 | <menuitem | ||
135 | 43 | action="attribute_group_form_action" id="menu_attribute_group_action" | ||
136 | 44 | parent="partner_custom_attributes.menu_attribute_in_config_partner" sequence="2"/> | ||
137 | 45 | <menuitem | ||
138 | 46 | action="attribute_attribute_form_action" id="menu_attribute_attribute_action" | ||
139 | 47 | parent="partner_custom_attributes.menu_attribute_in_config_partner" sequence="4"/> | ||
140 | 48 | |||
141 | 49 | </data> | ||
142 | 50 | </openerp> | ||
143 | 0 | 51 | ||
144 | === added file 'partner_custom_attributes/partner.py' | |||
145 | --- partner_custom_attributes/partner.py 1970-01-01 00:00:00 +0000 | |||
146 | +++ partner_custom_attributes/partner.py 2014-05-16 10:38:28 +0000 | |||
147 | @@ -0,0 +1,148 @@ | |||
148 | 1 | # -*- coding: utf-8 -*- | ||
149 | 2 | ############################################################################### | ||
150 | 3 | # # | ||
151 | 4 | # Author: Leonardo Pistone <leonardo.pistone@camptocamp.com> # | ||
152 | 5 | # Copyright 2014 Camptocamp SA # | ||
153 | 6 | # # | ||
154 | 7 | # Inspired by the module product_custom_attributes # | ||
155 | 8 | # by Benoît GUILLOT <benoit.guillot@akretion.com>, Akretion # | ||
156 | 9 | # # | ||
157 | 10 | # This program is free software: you can redistribute it and/or modify # | ||
158 | 11 | # it under the terms of the GNU Affero General Public License as # | ||
159 | 12 | # published by the Free Software Foundation, either version 3 of the # | ||
160 | 13 | # License, or (at your option) any later version. # | ||
161 | 14 | # # | ||
162 | 15 | # This program is distributed in the hope that it will be useful, # | ||
163 | 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | ||
164 | 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | ||
165 | 18 | # GNU Affero General Public License for more details. # | ||
166 | 19 | # # | ||
167 | 20 | # You should have received a copy of the GNU Affero General Public License # | ||
168 | 21 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | ||
169 | 22 | # # | ||
170 | 23 | ############################################################################### | ||
171 | 24 | """Partner customization: custom attributes.""" | ||
172 | 25 | |||
173 | 26 | from openerp.osv import fields, osv | ||
174 | 27 | from openerp.tools.translate import translate | ||
175 | 28 | from lxml import etree | ||
176 | 29 | |||
177 | 30 | |||
178 | 31 | class ResPartner(osv.Model): | ||
179 | 32 | _inherit = "res.partner" | ||
180 | 33 | |||
181 | 34 | _columns = { | ||
182 | 35 | 'attribute_set_id': fields.many2one('attribute.set', 'Attribute Set'), | ||
183 | 36 | 'attribute_group_ids': fields.related( | ||
184 | 37 | 'attribute_set_id', | ||
185 | 38 | 'attribute_group_ids', | ||
186 | 39 | type='many2many', | ||
187 | 40 | relation='attribute.group' | ||
188 | 41 | ), | ||
189 | 42 | } | ||
190 | 43 | |||
191 | 44 | def open_attributes(self, cr, uid, ids, context=None): | ||
192 | 45 | """Open the attributes of an object. Return action. | ||
193 | 46 | |||
194 | 47 | This method is called when the user presses the Open Attributes button | ||
195 | 48 | in the form view of the object. It opens a dynamically-built form view. | ||
196 | 49 | |||
197 | 50 | :param ids: this is normally a singleton. If a longer list is passed, | ||
198 | 51 | we consider only the first item. | ||
199 | 52 | |||
200 | 53 | """ | ||
201 | 54 | |||
202 | 55 | model_data_pool = self.pool['ir.model.data'] | ||
203 | 56 | |||
204 | 57 | for partner in self.browse(cr, uid, ids, context=context): | ||
205 | 58 | view_id = model_data_pool.get_object_reference( | ||
206 | 59 | cr, uid, | ||
207 | 60 | 'partner_custom_attributes', | ||
208 | 61 | 'partner_attributes_form_view')[1] | ||
209 | 62 | ctx = { | ||
210 | 63 | 'open_attributes': True, | ||
211 | 64 | 'attribute_group_ids': [ | ||
212 | 65 | group.id for group in partner.attribute_group_ids | ||
213 | 66 | ] | ||
214 | 67 | } | ||
215 | 68 | |||
216 | 69 | return { | ||
217 | 70 | 'name': 'Partner Attributes', | ||
218 | 71 | 'view_type': 'form', | ||
219 | 72 | 'view_mode': 'form', | ||
220 | 73 | 'view_id': [view_id], | ||
221 | 74 | 'res_model': self._name, | ||
222 | 75 | 'context': ctx, | ||
223 | 76 | 'type': 'ir.actions.act_window', | ||
224 | 77 | 'nodestroy': True, | ||
225 | 78 | 'target': 'new', | ||
226 | 79 | 'res_id': partner.id, | ||
227 | 80 | } | ||
228 | 81 | |||
229 | 82 | def save_and_close_partner_attributes(self, cr, uid, ids, context=None): | ||
230 | 83 | """Button to save and close. Return action.""" | ||
231 | 84 | return {'type': 'ir.actions.act_window_close'} | ||
232 | 85 | |||
233 | 86 | def fields_view_get(self, cr, uid, view_id=None, view_type='form', | ||
234 | 87 | context=None, toolbar=False, submenu=False): | ||
235 | 88 | """Dynamically add attributes to the view. Return field_view_get. | ||
236 | 89 | |||
237 | 90 | Modifies dynamically the view to show the attributes. If the users | ||
238 | 91 | presses the Open Attributes button, the attributes are shown in a | ||
239 | 92 | new form field. Otherwise, if the attribute set is known beforehand, | ||
240 | 93 | attributes are added to a new tab in the main form view. | ||
241 | 94 | |||
242 | 95 | """ | ||
243 | 96 | if context is None: | ||
244 | 97 | context = {} | ||
245 | 98 | |||
246 | 99 | def translate_view(source): | ||
247 | 100 | """Return a translation of type view of source.""" | ||
248 | 101 | return translate( | ||
249 | 102 | cr, None, 'view', context.get('lang'), source | ||
250 | 103 | ) or source | ||
251 | 104 | |||
252 | 105 | attr_pool = self.pool['attribute.attribute'] | ||
253 | 106 | |||
254 | 107 | result = super(ResPartner, self).fields_view_get( | ||
255 | 108 | cr, uid, view_id, view_type, context, toolbar=toolbar, | ||
256 | 109 | submenu=submenu | ||
257 | 110 | ) | ||
258 | 111 | if view_type == 'form' and context.get('attribute_group_ids'): | ||
259 | 112 | eview = etree.fromstring(result['arch']) | ||
260 | 113 | # hide button under the name | ||
261 | 114 | button = eview.xpath("//button[@name='open_attributes']") | ||
262 | 115 | if button: | ||
263 | 116 | button = button[0] | ||
264 | 117 | button.getparent().remove(button) | ||
265 | 118 | attributes_notebook, toupdate_fields = ( | ||
266 | 119 | attr_pool._build_attributes_notebook( | ||
267 | 120 | cr, uid, context['attribute_group_ids'], context=context | ||
268 | 121 | ) | ||
269 | 122 | ) | ||
270 | 123 | result['fields'].update( | ||
271 | 124 | self.fields_get(cr, uid, toupdate_fields, context) | ||
272 | 125 | ) | ||
273 | 126 | if context.get('open_attributes'): | ||
274 | 127 | |||
275 | 128 | # i.e. the user pressed the open attributes button on the | ||
276 | 129 | # form view. We put the attributes in a separate form view | ||
277 | 130 | placeholder = eview.xpath( | ||
278 | 131 | "//separator[@string='attributes_placeholder']" | ||
279 | 132 | )[0] | ||
280 | 133 | placeholder.getparent().replace( | ||
281 | 134 | placeholder, attributes_notebook | ||
282 | 135 | ) | ||
283 | 136 | elif context.get('open_partner_by_attribute_set'): | ||
284 | 137 | # in this case, we know the attribute set beforehand, and we | ||
285 | 138 | # add the attributes to the current view | ||
286 | 139 | main_page = etree.Element( | ||
287 | 140 | 'page', string=translate_view('Custom Attributes') | ||
288 | 141 | ) | ||
289 | 142 | main_page.append(attributes_notebook) | ||
290 | 143 | info_page = eview.xpath( | ||
291 | 144 | "//page[@string='%s']" % (translate_view('Stock Moves'),) | ||
292 | 145 | )[0] | ||
293 | 146 | info_page.addnext(main_page) | ||
294 | 147 | result['arch'] = etree.tostring(eview, pretty_print=True) | ||
295 | 148 | return result | ||
296 | 0 | 149 | ||
297 | === added file 'partner_custom_attributes/partner_view.xml' | |||
298 | --- partner_custom_attributes/partner_view.xml 1970-01-01 00:00:00 +0000 | |||
299 | +++ partner_custom_attributes/partner_view.xml 2014-05-16 10:38:28 +0000 | |||
300 | @@ -0,0 +1,42 @@ | |||
301 | 1 | <?xml version="1.0" encoding="utf-8"?> | ||
302 | 2 | |||
303 | 3 | <openerp> | ||
304 | 4 | <data> | ||
305 | 5 | |||
306 | 6 | <record model="ir.ui.view" id="res_partner_form_view_set_button"> | ||
307 | 7 | <field name="name">attributes.partner.normal.form</field> | ||
308 | 8 | <field name="model">res.partner</field> | ||
309 | 9 | <field name="inherit_id" ref="base.view_partner_form" /> | ||
310 | 10 | <field name="arch" type="xml"> | ||
311 | 11 | <notebook position="inside"> | ||
312 | 12 | <page string="Attributes"> | ||
313 | 13 | <group name="attribute_fields"> | ||
314 | 14 | <field name="attribute_set_id" /> | ||
315 | 15 | <button name="open_attributes" string="Open Attributes" type="object" icon="gtk-ok" attrs="{'invisible':[('attribute_set_id', '=', False)]}"/> | ||
316 | 16 | </group> | ||
317 | 17 | </page> | ||
318 | 18 | </notebook> | ||
319 | 19 | </field> | ||
320 | 20 | </record> | ||
321 | 21 | |||
322 | 22 | <record model="ir.ui.view" id="partner_attributes_form_view"> | ||
323 | 23 | <field name="name">partner.attributes.normal.wizard</field> | ||
324 | 24 | <field name="model">res.partner</field> | ||
325 | 25 | <field name="arch" type="xml"> | ||
326 | 26 | <form string="partner" version="7.0"> | ||
327 | 27 | <group name="name_set"> | ||
328 | 28 | <field name="name"/> | ||
329 | 29 | <field name="attribute_set_id" /> | ||
330 | 30 | </group> | ||
331 | 31 | <separator string="attributes_placeholder" colspan="4"/> | ||
332 | 32 | <footer> | ||
333 | 33 | <button name="save_and_close_partner_attributes" string="Save and Close" type="object" class="oe_highlight"/> | ||
334 | 34 | or | ||
335 | 35 | <button special="cancel" string="Cancel" class="oe_link"/> | ||
336 | 36 | </footer> | ||
337 | 37 | </form> | ||
338 | 38 | </field> | ||
339 | 39 | </record> | ||
340 | 40 | |||
341 | 41 | </data> | ||
342 | 42 | </openerp> | ||
343 | 0 | \ No newline at end of file | 43 | \ No newline at end of file |
344 | 1 | 44 | ||
345 | === added directory 'partner_custom_attributes/wizard' | |||
346 | === added file 'partner_custom_attributes/wizard/__init__.py' | |||
347 | --- partner_custom_attributes/wizard/__init__.py 1970-01-01 00:00:00 +0000 | |||
348 | +++ partner_custom_attributes/wizard/__init__.py 2014-05-16 10:38:28 +0000 | |||
349 | @@ -0,0 +1,25 @@ | |||
350 | 1 | # -*- coding: utf-8 -*- | ||
351 | 2 | ############################################################################### | ||
352 | 3 | # # | ||
353 | 4 | # Author: Leonardo Pistone <leonardo.pistone@camptocamp.com> # | ||
354 | 5 | # Copyright 2014 Camptocamp SA # | ||
355 | 6 | # # | ||
356 | 7 | # Inspired by the module product_custom_attributes # | ||
357 | 8 | # by Benoît GUILLOT <benoit.guillot@akretion.com>, Akretion # | ||
358 | 9 | # # | ||
359 | 10 | # This program is free software: you can redistribute it and/or modify # | ||
360 | 11 | # it under the terms of the GNU Affero General Public License as # | ||
361 | 12 | # published by the Free Software Foundation, either version 3 of the # | ||
362 | 13 | # License, or (at your option) any later version. # | ||
363 | 14 | # # | ||
364 | 15 | # This program is distributed in the hope that it will be useful, # | ||
365 | 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | ||
366 | 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | ||
367 | 18 | # GNU Affero General Public License for more details. # | ||
368 | 19 | # # | ||
369 | 20 | # You should have received a copy of the GNU Affero General Public License # | ||
370 | 21 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | ||
371 | 22 | # # | ||
372 | 23 | ############################################################################### | ||
373 | 24 | |||
374 | 25 | from . import open_partner_by_attribute_set # noqa | ||
375 | 0 | 26 | ||
376 | === added file 'partner_custom_attributes/wizard/open_partner_by_attribute_set.py' | |||
377 | --- partner_custom_attributes/wizard/open_partner_by_attribute_set.py 1970-01-01 00:00:00 +0000 | |||
378 | +++ partner_custom_attributes/wizard/open_partner_by_attribute_set.py 2014-05-16 10:38:28 +0000 | |||
379 | @@ -0,0 +1,67 @@ | |||
380 | 1 | # -*- coding: utf-8 -*- | ||
381 | 2 | ############################################################################### | ||
382 | 3 | # # | ||
383 | 4 | # Author: Leonardo Pistone <leonardo.pistone@camptocamp.com> # | ||
384 | 5 | # Copyright 2014 Camptocamp SA # | ||
385 | 6 | # # | ||
386 | 7 | # Inspired by the module product_custom_attributes # | ||
387 | 8 | # by Benoît GUILLOT <benoit.guillot@akretion.com>, Akretion # | ||
388 | 9 | # # | ||
389 | 10 | # This program is free software: you can redistribute it and/or modify # | ||
390 | 11 | # it under the terms of the GNU Affero General Public License as # | ||
391 | 12 | # published by the Free Software Foundation, either version 3 of the # | ||
392 | 13 | # License, or (at your option) any later version. # | ||
393 | 14 | # # | ||
394 | 15 | # This program is distributed in the hope that it will be useful, # | ||
395 | 16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | ||
396 | 17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | ||
397 | 18 | # GNU Affero General Public License for more details. # | ||
398 | 19 | # # | ||
399 | 20 | # You should have received a copy of the GNU Affero General Public License # | ||
400 | 21 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | ||
401 | 22 | # # | ||
402 | 23 | ############################################################################### | ||
403 | 24 | |||
404 | 25 | from openerp.osv.orm import TransientModel | ||
405 | 26 | from osv import fields | ||
406 | 27 | |||
407 | 28 | |||
408 | 29 | class open_partner_by_attribute_set(TransientModel): | ||
409 | 30 | _name = 'open.partner.by.attribute.set' | ||
410 | 31 | _description = 'Wizard to open partners by attributes set' | ||
411 | 32 | |||
412 | 33 | _columns = { | ||
413 | 34 | 'attribute_set_id': fields.many2one('attribute.set', 'Attribute Set'), | ||
414 | 35 | } | ||
415 | 36 | |||
416 | 37 | def open_partner_by_attribute(self, cr, uid, ids, context=None): | ||
417 | 38 | """Opens a partner by attributes | ||
418 | 39 | |||
419 | 40 | Returns a custom action built modifying the original one. | ||
420 | 41 | """ | ||
421 | 42 | |||
422 | 43 | mod_obj = self.pool['ir.model.data'] | ||
423 | 44 | act_obj = self.pool['ir.actions.act_window'] | ||
424 | 45 | |||
425 | 46 | # we expect one wizard instance at a time | ||
426 | 47 | for wiz in self.browse(cr, uid, ids, context=context): | ||
427 | 48 | action_id = mod_obj.get_object_reference( | ||
428 | 49 | cr, uid, 'base', 'action_partner_form')[1] | ||
429 | 50 | action = act_obj.read(cr, uid, [action_id], context=context)[0] | ||
430 | 51 | |||
431 | 52 | ctx = ( | ||
432 | 53 | "{'open_partner_by_attribute_set': True, " | ||
433 | 54 | "'attribute_group_ids': %s}" | ||
434 | 55 | % [ | ||
435 | 56 | group.id | ||
436 | 57 | for group in wiz.attribute_set_id.attribute_group_ids | ||
437 | 58 | ] | ||
438 | 59 | ) | ||
439 | 60 | |||
440 | 61 | action['context'] = ctx | ||
441 | 62 | action['domain'] = ( | ||
442 | 63 | "[('attribute_set_id', '=', %s)]" | ||
443 | 64 | % wiz.attribute_set_id.id | ||
444 | 65 | ) | ||
445 | 66 | action['name'] = wiz.attribute_set_id.name | ||
446 | 67 | return action | ||
447 | 0 | 68 | ||
448 | === added file 'partner_custom_attributes/wizard/open_partner_by_attribute_set.xml' | |||
449 | --- partner_custom_attributes/wizard/open_partner_by_attribute_set.xml 1970-01-01 00:00:00 +0000 | |||
450 | +++ partner_custom_attributes/wizard/open_partner_by_attribute_set.xml 2014-05-16 10:38:28 +0000 | |||
451 | @@ -0,0 +1,35 @@ | |||
452 | 1 | <?xml version="1.0" encoding="utf-8"?> | ||
453 | 2 | |||
454 | 3 | <openerp> | ||
455 | 4 | <data> | ||
456 | 5 | |||
457 | 6 | <record id="open_partner_by_attribute_set_view" model="ir.ui.view"> | ||
458 | 7 | <field name="name">open.partner.by.attribute.set.view</field> | ||
459 | 8 | <field name="model">open.partner.by.attribute.set</field> | ||
460 | 9 | <field name="arch" type="xml"> | ||
461 | 10 | <form string="Open partner by attributes set" version="7.0"> | ||
462 | 11 | <group> | ||
463 | 12 | <field name="attribute_set_id" /> | ||
464 | 13 | </group> | ||
465 | 14 | <footer> | ||
466 | 15 | <button name="open_partner_by_attribute" string="Open Partner By attribute" type="object" class="oe_highlight"/> | ||
467 | 16 | or | ||
468 | 17 | <button special="cancel" string="Cancel" class="oe_link"/> | ||
469 | 18 | </footer> | ||
470 | 19 | </form> | ||
471 | 20 | </field> | ||
472 | 21 | </record> | ||
473 | 22 | |||
474 | 23 | <record id="open_partner_by_attribute_set" model="ir.actions.act_window"> | ||
475 | 24 | <field name="name">Open Partner By Attribute Set</field> | ||
476 | 25 | <field name="res_model">open.partner.by.attribute.set</field> | ||
477 | 26 | <field name="view_type">form</field> | ||
478 | 27 | <field name="target">new</field> | ||
479 | 28 | <field name="view_id" ref="open_partner_by_attribute_set_view"/> | ||
480 | 29 | <field name="help"/> | ||
481 | 30 | </record> | ||
482 | 31 | |||
483 | 32 | <menuitem action="open_partner_by_attribute_set" id="open_partner_wizard" parent="base.menu_sales"/> | ||
484 | 33 | |||
485 | 34 | </data> | ||
486 | 35 | </openerp> | ||
487 | 0 | \ No newline at end of file | 36 | \ No newline at end of file |
use self.pool['...'] instead of self.pool['...']
l.202 testing if context is None is not necessary. Unless you want to copy it in ctx
same at l.428
Can you use spaces instead of tabs in xml files, please?
Cheers