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
=== added directory 'partner_custom_attributes'
=== added file 'partner_custom_attributes/__init__.py'
--- partner_custom_attributes/__init__.py 1970-01-01 00:00:00 +0000
+++ partner_custom_attributes/__init__.py 2014-05-16 10:38:28 +0000
@@ -0,0 +1,25 @@
1# -*- coding: utf-8 -*-
2###############################################################################
3# #
4# Author: Leonardo Pistone <leonardo.pistone@camptocamp.com> #
5# Copyright 2014 Camptocamp SA #
6# #
7# Inspired by the module product_custom_attributes #
8# by Benoît GUILLOT <benoit.guillot@akretion.com>, Akretion #
9# #
10# This program is free software: you can redistribute it and/or modify #
11# it under the terms of the GNU Affero General Public License as #
12# published by the Free Software Foundation, either version 3 of the #
13# License, or (at your option) any later version. #
14# #
15# This program is distributed in the hope that it will be useful, #
16# but WITHOUT ANY WARRANTY; without even the implied warranty of #
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
18# GNU Affero General Public License for more details. #
19# #
20# You should have received a copy of the GNU Affero General Public License #
21# along with this program. If not, see <http://www.gnu.org/licenses/>. #
22# #
23###############################################################################
24from . import partner # noqa
25from . import wizard # noqa
026
=== added file 'partner_custom_attributes/__openerp__.py'
--- partner_custom_attributes/__openerp__.py 1970-01-01 00:00:00 +0000
+++ partner_custom_attributes/__openerp__.py 2014-05-16 10:38:28 +0000
@@ -0,0 +1,52 @@
1# -*- coding: utf-8 -*-
2###############################################################################
3# #
4# Author: Leonardo Pistone <leonardo.pistone@camptocamp.com> #
5# Copyright 2014 Camptocamp SA #
6# #
7# Inspired by the module product_custom_attributes #
8# by Benoît GUILLOT <benoit.guillot@akretion.com>, Akretion #
9# #
10# This program is free software: you can redistribute it and/or modify #
11# it under the terms of the GNU Affero General Public License as #
12# published by the Free Software Foundation, either version 3 of the #
13# License, or (at your option) any later version. #
14# #
15# This program is distributed in the hope that it will be useful, #
16# but WITHOUT ANY WARRANTY; without even the implied warranty of #
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
18# GNU Affero General Public License for more details. #
19# #
20# You should have received a copy of the GNU Affero General Public License #
21# along with this program. If not, see <http://www.gnu.org/licenses/>. #
22# #
23###############################################################################
24
25{'name': 'Partner Custom Attributes',
26 'version': '0.1.0',
27 'category': 'Generic Modules/Others',
28 'license': 'AGPL-3',
29 'description': """
30Partner custom attributes
31=========================
32
33This module adds the possibility to easily create custom fields on Partners.
34Each partner can be linked to an attribute set. Each attribute has custom
35fields.
36
37This module is inspired by the module product_custom_attributes by Benoît
38GUILLOT, Akretion
39
40""",
41 'complexity': 'normal',
42 'author': 'Camptocamp',
43 'website': 'http://www.camptocamp.com/',
44 'depends': ['base_custom_attributes'],
45 'data': ['partner_view.xml',
46 'custom_attributes_view.xml',
47 'wizard/open_partner_by_attribute_set.xml'
48 ],
49 'test': ['test/partner_attribute_test.yml'],
50 'installable': True,
51 'active': False,
52 }
053
=== added file 'partner_custom_attributes/custom_attributes_view.xml'
--- partner_custom_attributes/custom_attributes_view.xml 1970-01-01 00:00:00 +0000
+++ partner_custom_attributes/custom_attributes_view.xml 2014-05-16 10:38:28 +0000
@@ -0,0 +1,50 @@
1<?xml version="1.0" encoding="utf-8"?>
2
3<openerp>
4 <data>
5
6 <menuitem id="menu_attribute_in_config_partner" name="Attributes"
7 parent="base.menu_config_address_book" sequence="20"/>
8
9 <record id="attribute_set_form_action" model="ir.actions.act_window">
10 <field name="name">Partner Attribute Sets</field>
11 <field name="res_model">attribute.set</field>
12 <field name="view_type">form</field>
13 <field name="view_mode">tree,form</field>
14 <field name="search_view_id" ref="base_custom_attributes.view_attribute_set_search"/>
15 <field name="context">{"force_model": 'res.partner'}</field>
16 <field name="help"></field>
17 </record>
18
19 <record id="attribute_group_form_action" model="ir.actions.act_window">
20 <field name="name">Attribute Groups</field>
21 <field name="res_model">attribute.group</field>
22 <field name="view_type">form</field>
23 <field name="view_mode">tree,form</field>
24 <field name="search_view_id" ref="base_custom_attributes.view_attribute_attribute_search"/>
25 <field name="context">{"force_model": 'res.partner'}</field>
26 <field name="help"></field>
27 </record>
28
29 <record id="attribute_attribute_form_action" model="ir.actions.act_window">
30 <field name="name">Partner Attribute</field>
31 <field name="res_model">attribute.attribute</field>
32 <field name="view_type">form</field>
33 <field name="view_mode">tree,form</field>
34 <field name="search_view_id" ref="base_custom_attributes.view_attribute_attribute_search"/>
35 <field name="context">{"force_model": 'res.partner'}</field>
36 <field name="help"></field>
37 </record>
38
39 <menuitem
40 action="attribute_set_form_action" id="menu_attribute_set_action"
41 parent="partner_custom_attributes.menu_attribute_in_config_partner" sequence="1"/>
42 <menuitem
43 action="attribute_group_form_action" id="menu_attribute_group_action"
44 parent="partner_custom_attributes.menu_attribute_in_config_partner" sequence="2"/>
45 <menuitem
46 action="attribute_attribute_form_action" id="menu_attribute_attribute_action"
47 parent="partner_custom_attributes.menu_attribute_in_config_partner" sequence="4"/>
48
49 </data>
50</openerp>
051
=== added file 'partner_custom_attributes/partner.py'
--- partner_custom_attributes/partner.py 1970-01-01 00:00:00 +0000
+++ partner_custom_attributes/partner.py 2014-05-16 10:38:28 +0000
@@ -0,0 +1,148 @@
1# -*- coding: utf-8 -*-
2###############################################################################
3# #
4# Author: Leonardo Pistone <leonardo.pistone@camptocamp.com> #
5# Copyright 2014 Camptocamp SA #
6# #
7# Inspired by the module product_custom_attributes #
8# by Benoît GUILLOT <benoit.guillot@akretion.com>, Akretion #
9# #
10# This program is free software: you can redistribute it and/or modify #
11# it under the terms of the GNU Affero General Public License as #
12# published by the Free Software Foundation, either version 3 of the #
13# License, or (at your option) any later version. #
14# #
15# This program is distributed in the hope that it will be useful, #
16# but WITHOUT ANY WARRANTY; without even the implied warranty of #
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
18# GNU Affero General Public License for more details. #
19# #
20# You should have received a copy of the GNU Affero General Public License #
21# along with this program. If not, see <http://www.gnu.org/licenses/>. #
22# #
23###############################################################################
24"""Partner customization: custom attributes."""
25
26from openerp.osv import fields, osv
27from openerp.tools.translate import translate
28from lxml import etree
29
30
31class ResPartner(osv.Model):
32 _inherit = "res.partner"
33
34 _columns = {
35 'attribute_set_id': fields.many2one('attribute.set', 'Attribute Set'),
36 'attribute_group_ids': fields.related(
37 'attribute_set_id',
38 'attribute_group_ids',
39 type='many2many',
40 relation='attribute.group'
41 ),
42 }
43
44 def open_attributes(self, cr, uid, ids, context=None):
45 """Open the attributes of an object. Return action.
46
47 This method is called when the user presses the Open Attributes button
48 in the form view of the object. It opens a dynamically-built form view.
49
50 :param ids: this is normally a singleton. If a longer list is passed,
51 we consider only the first item.
52
53 """
54
55 model_data_pool = self.pool['ir.model.data']
56
57 for partner in self.browse(cr, uid, ids, context=context):
58 view_id = model_data_pool.get_object_reference(
59 cr, uid,
60 'partner_custom_attributes',
61 'partner_attributes_form_view')[1]
62 ctx = {
63 'open_attributes': True,
64 'attribute_group_ids': [
65 group.id for group in partner.attribute_group_ids
66 ]
67 }
68
69 return {
70 'name': 'Partner Attributes',
71 'view_type': 'form',
72 'view_mode': 'form',
73 'view_id': [view_id],
74 'res_model': self._name,
75 'context': ctx,
76 'type': 'ir.actions.act_window',
77 'nodestroy': True,
78 'target': 'new',
79 'res_id': partner.id,
80 }
81
82 def save_and_close_partner_attributes(self, cr, uid, ids, context=None):
83 """Button to save and close. Return action."""
84 return {'type': 'ir.actions.act_window_close'}
85
86 def fields_view_get(self, cr, uid, view_id=None, view_type='form',
87 context=None, toolbar=False, submenu=False):
88 """Dynamically add attributes to the view. Return field_view_get.
89
90 Modifies dynamically the view to show the attributes. If the users
91 presses the Open Attributes button, the attributes are shown in a
92 new form field. Otherwise, if the attribute set is known beforehand,
93 attributes are added to a new tab in the main form view.
94
95 """
96 if context is None:
97 context = {}
98
99 def translate_view(source):
100 """Return a translation of type view of source."""
101 return translate(
102 cr, None, 'view', context.get('lang'), source
103 ) or source
104
105 attr_pool = self.pool['attribute.attribute']
106
107 result = super(ResPartner, self).fields_view_get(
108 cr, uid, view_id, view_type, context, toolbar=toolbar,
109 submenu=submenu
110 )
111 if view_type == 'form' and context.get('attribute_group_ids'):
112 eview = etree.fromstring(result['arch'])
113 # hide button under the name
114 button = eview.xpath("//button[@name='open_attributes']")
115 if button:
116 button = button[0]
117 button.getparent().remove(button)
118 attributes_notebook, toupdate_fields = (
119 attr_pool._build_attributes_notebook(
120 cr, uid, context['attribute_group_ids'], context=context
121 )
122 )
123 result['fields'].update(
124 self.fields_get(cr, uid, toupdate_fields, context)
125 )
126 if context.get('open_attributes'):
127
128 # i.e. the user pressed the open attributes button on the
129 # form view. We put the attributes in a separate form view
130 placeholder = eview.xpath(
131 "//separator[@string='attributes_placeholder']"
132 )[0]
133 placeholder.getparent().replace(
134 placeholder, attributes_notebook
135 )
136 elif context.get('open_partner_by_attribute_set'):
137 # in this case, we know the attribute set beforehand, and we
138 # add the attributes to the current view
139 main_page = etree.Element(
140 'page', string=translate_view('Custom Attributes')
141 )
142 main_page.append(attributes_notebook)
143 info_page = eview.xpath(
144 "//page[@string='%s']" % (translate_view('Stock Moves'),)
145 )[0]
146 info_page.addnext(main_page)
147 result['arch'] = etree.tostring(eview, pretty_print=True)
148 return result
0149
=== added file 'partner_custom_attributes/partner_view.xml'
--- partner_custom_attributes/partner_view.xml 1970-01-01 00:00:00 +0000
+++ partner_custom_attributes/partner_view.xml 2014-05-16 10:38:28 +0000
@@ -0,0 +1,42 @@
1<?xml version="1.0" encoding="utf-8"?>
2
3<openerp>
4 <data>
5
6 <record model="ir.ui.view" id="res_partner_form_view_set_button">
7 <field name="name">attributes.partner.normal.form</field>
8 <field name="model">res.partner</field>
9 <field name="inherit_id" ref="base.view_partner_form" />
10 <field name="arch" type="xml">
11 <notebook position="inside">
12 <page string="Attributes">
13 <group name="attribute_fields">
14 <field name="attribute_set_id" />
15 <button name="open_attributes" string="Open Attributes" type="object" icon="gtk-ok" attrs="{'invisible':[('attribute_set_id', '=', False)]}"/>
16 </group>
17 </page>
18 </notebook>
19 </field>
20 </record>
21
22 <record model="ir.ui.view" id="partner_attributes_form_view">
23 <field name="name">partner.attributes.normal.wizard</field>
24 <field name="model">res.partner</field>
25 <field name="arch" type="xml">
26 <form string="partner" version="7.0">
27 <group name="name_set">
28 <field name="name"/>
29 <field name="attribute_set_id" />
30 </group>
31 <separator string="attributes_placeholder" colspan="4"/>
32 <footer>
33 <button name="save_and_close_partner_attributes" string="Save and Close" type="object" class="oe_highlight"/>
34 or
35 <button special="cancel" string="Cancel" class="oe_link"/>
36 </footer>
37 </form>
38 </field>
39 </record>
40
41 </data>
42</openerp>
0\ No newline at end of file43\ No newline at end of file
144
=== added directory 'partner_custom_attributes/wizard'
=== added file 'partner_custom_attributes/wizard/__init__.py'
--- partner_custom_attributes/wizard/__init__.py 1970-01-01 00:00:00 +0000
+++ partner_custom_attributes/wizard/__init__.py 2014-05-16 10:38:28 +0000
@@ -0,0 +1,25 @@
1# -*- coding: utf-8 -*-
2###############################################################################
3# #
4# Author: Leonardo Pistone <leonardo.pistone@camptocamp.com> #
5# Copyright 2014 Camptocamp SA #
6# #
7# Inspired by the module product_custom_attributes #
8# by Benoît GUILLOT <benoit.guillot@akretion.com>, Akretion #
9# #
10# This program is free software: you can redistribute it and/or modify #
11# it under the terms of the GNU Affero General Public License as #
12# published by the Free Software Foundation, either version 3 of the #
13# License, or (at your option) any later version. #
14# #
15# This program is distributed in the hope that it will be useful, #
16# but WITHOUT ANY WARRANTY; without even the implied warranty of #
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
18# GNU Affero General Public License for more details. #
19# #
20# You should have received a copy of the GNU Affero General Public License #
21# along with this program. If not, see <http://www.gnu.org/licenses/>. #
22# #
23###############################################################################
24
25from . import open_partner_by_attribute_set # noqa
026
=== added file 'partner_custom_attributes/wizard/open_partner_by_attribute_set.py'
--- partner_custom_attributes/wizard/open_partner_by_attribute_set.py 1970-01-01 00:00:00 +0000
+++ partner_custom_attributes/wizard/open_partner_by_attribute_set.py 2014-05-16 10:38:28 +0000
@@ -0,0 +1,67 @@
1# -*- coding: utf-8 -*-
2###############################################################################
3# #
4# Author: Leonardo Pistone <leonardo.pistone@camptocamp.com> #
5# Copyright 2014 Camptocamp SA #
6# #
7# Inspired by the module product_custom_attributes #
8# by Benoît GUILLOT <benoit.guillot@akretion.com>, Akretion #
9# #
10# This program is free software: you can redistribute it and/or modify #
11# it under the terms of the GNU Affero General Public License as #
12# published by the Free Software Foundation, either version 3 of the #
13# License, or (at your option) any later version. #
14# #
15# This program is distributed in the hope that it will be useful, #
16# but WITHOUT ANY WARRANTY; without even the implied warranty of #
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
18# GNU Affero General Public License for more details. #
19# #
20# You should have received a copy of the GNU Affero General Public License #
21# along with this program. If not, see <http://www.gnu.org/licenses/>. #
22# #
23###############################################################################
24
25from openerp.osv.orm import TransientModel
26from osv import fields
27
28
29class open_partner_by_attribute_set(TransientModel):
30 _name = 'open.partner.by.attribute.set'
31 _description = 'Wizard to open partners by attributes set'
32
33 _columns = {
34 'attribute_set_id': fields.many2one('attribute.set', 'Attribute Set'),
35 }
36
37 def open_partner_by_attribute(self, cr, uid, ids, context=None):
38 """Opens a partner by attributes
39
40 Returns a custom action built modifying the original one.
41 """
42
43 mod_obj = self.pool['ir.model.data']
44 act_obj = self.pool['ir.actions.act_window']
45
46 # we expect one wizard instance at a time
47 for wiz in self.browse(cr, uid, ids, context=context):
48 action_id = mod_obj.get_object_reference(
49 cr, uid, 'base', 'action_partner_form')[1]
50 action = act_obj.read(cr, uid, [action_id], context=context)[0]
51
52 ctx = (
53 "{'open_partner_by_attribute_set': True, "
54 "'attribute_group_ids': %s}"
55 % [
56 group.id
57 for group in wiz.attribute_set_id.attribute_group_ids
58 ]
59 )
60
61 action['context'] = ctx
62 action['domain'] = (
63 "[('attribute_set_id', '=', %s)]"
64 % wiz.attribute_set_id.id
65 )
66 action['name'] = wiz.attribute_set_id.name
67 return action
068
=== added file 'partner_custom_attributes/wizard/open_partner_by_attribute_set.xml'
--- partner_custom_attributes/wizard/open_partner_by_attribute_set.xml 1970-01-01 00:00:00 +0000
+++ partner_custom_attributes/wizard/open_partner_by_attribute_set.xml 2014-05-16 10:38:28 +0000
@@ -0,0 +1,35 @@
1<?xml version="1.0" encoding="utf-8"?>
2
3<openerp>
4 <data>
5
6 <record id="open_partner_by_attribute_set_view" model="ir.ui.view">
7 <field name="name">open.partner.by.attribute.set.view</field>
8 <field name="model">open.partner.by.attribute.set</field>
9 <field name="arch" type="xml">
10 <form string="Open partner by attributes set" version="7.0">
11 <group>
12 <field name="attribute_set_id" />
13 </group>
14 <footer>
15 <button name="open_partner_by_attribute" string="Open Partner By attribute" type="object" class="oe_highlight"/>
16 or
17 <button special="cancel" string="Cancel" class="oe_link"/>
18 </footer>
19 </form>
20 </field>
21 </record>
22
23 <record id="open_partner_by_attribute_set" model="ir.actions.act_window">
24 <field name="name">Open Partner By Attribute Set</field>
25 <field name="res_model">open.partner.by.attribute.set</field>
26 <field name="view_type">form</field>
27 <field name="target">new</field>
28 <field name="view_id" ref="open_partner_by_attribute_set_view"/>
29 <field name="help"/>
30 </record>
31
32 <menuitem action="open_partner_by_attribute_set" id="open_partner_wizard" parent="base.menu_sales"/>
33
34 </data>
35</openerp>
0\ No newline at end of file36\ No newline at end of file

Subscribers

People subscribed via source and target branches