Merge lp:~camptocamp/openerp-product-attributes/7.0-partner-attributes-lep into lp:~product-core-editors/openerp-product-attributes/7.0

Proposed by Leonardo Pistone
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
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

Description of the change

add module partner_custom_attributes

To post a comment you must log in.
244. By Leonardo Pistone

[del] workaronud for text field size bug on partner_attributes

Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

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

review: Needs Fixing (code review, no test)
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

Revision history for this message
Leonardo Pistone (lepistone) wrote :

Yannick, I made the changes you suggest. Thanks

247. By Alexandre Fayolle - camptocamp

[IMP] fix typos, fix import

Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

fixed a couple of typos

I'm a bit awkward with merging into openerp-product-attributes but I see how it makes sense to have this close to base_custom_attributes (which could have found a nicer home)...

still LGTM

review: Approve (code review, test)
Revision history for this message
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote :

I would add a little explaination on how to use it but LGTM.

review: Approve
Revision history for this message
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-attributes instead.

thanks

Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

Thanks for the changes

LGTM

review: Approve (code review, no test)
Revision history for this message
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.

review: Needs Fixing (test)
248. By Leonardo Pistone

[fix] old reference to lots in partner attributes

Revision history for this message
Leonardo Pistone (lepistone) wrote :

My issue in the view should be fixed now. Thanks

review: Abstain
Revision history for this message
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote :

Well I would like to have the ref on the excpetion before merging.

Revision history for this message
Leonardo Pistone (lepistone) wrote :

@nicolas: attribute fields were not shown because of the error fixed on commit 248

Preview Diff

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

Subscribers

People subscribed via source and target branches