← Back to team overview

openerp-community-reviewer team mailing list archive

[Merge] lp:~camptocamp/openerp-product-attributes/7.0-partner-attributes-lep into lp:openerp-product-attributes

 

Leonardo Pistone - camptocamp has proposed merging lp:~camptocamp/openerp-product-attributes/7.0-partner-attributes-lep into lp:openerp-product-attributes.

Requested reviews:
  Product Core Editors (product-core-editors)

For more details, see:
https://code.launchpad.net/~camptocamp/openerp-product-attributes/7.0-partner-attributes-lep/+merge/217234

add module partner_custom_attributes
-- 
https://code.launchpad.net/~camptocamp/openerp-product-attributes/7.0-partner-attributes-lep/+merge/217234
Your team Product Core Editors is requested to review the proposed merge of lp:~camptocamp/openerp-product-attributes/7.0-partner-attributes-lep into lp:openerp-product-attributes.
=== 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-04-25 12:57:27 +0000
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+###############################################################################
+#                                                                             #
+#   Author: Leonardo Pistone <leonardo.pistone@xxxxxxxxxxxxxx>                #
+#   Copyright 2014 Camptocamp SA                                              #
+#                                                                             #
+#   Inspired by the module product_custom_attributes                          #
+#   by Benoît GUILLOT <benoit.guillot@xxxxxxxxxxxx>, Akretion                 #
+#                                                                             #
+#   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 <http://www.gnu.org/licenses/>.     #
+#                                                                             #
+###############################################################################
+from . import partner  # noqa
+from . import wizard  # noqa

=== 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-04-25 12:57:27 +0000
@@ -0,0 +1,52 @@
+# -*- coding: utf-8 -*-
+###############################################################################
+#                                                                             #
+#   Author: Leonardo Pistone <leonardo.pistone@xxxxxxxxxxxxxx>                #
+#   Copyright 2014 Camptocamp SA                                              #
+#                                                                             #
+#   Inspired by the module product_custom_attributes                          #
+#   by Benoît GUILLOT <benoit.guillot@xxxxxxxxxxxx>, Akretion                 #
+#                                                                             #
+#   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 <http://www.gnu.org/licenses/>.     #
+#                                                                             #
+###############################################################################
+
+{'name': 'Partner Custom Attributes',
+ 'version': '0.1.0',
+ 'category': 'Generic Modules/Others',
+ 'license': 'AGPL-3',
+ 'description': """
+Partner custom attributes
+=========================
+
+This module adds the possibility to easily create custom fields on Partners.
+Each partner can be linked to an attribute set.  Each attribute has custom
+fields.
+
+This module is inspired by the module product_custom_attributes by Benoît
+GUILLOT, Akretion
+
+""",
+ 'complexity': 'normal',
+ 'author': 'Camptocamp',
+ 'website': 'http://www.camptocamp.com/',
+ 'depends': ['base_custom_attributes'],
+ 'data': ['partner_view.xml',
+          'custom_attributes_view.xml',
+          'wizard/open_partner_by_attribute_set.xml'
+          ],
+ 'test': ['test/partner_attribute_test.yml'],
+ 'installable': True,
+ 'active': False,
+ }

=== 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-04-25 12:57:27 +0000
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<openerp>
+	<data>
+
+		<menuitem id="menu_attribute_in_config_partner" name="Attributes"
+				parent="base.menu_config_address_book" sequence="20"/>
+
+		<record id="attribute_set_form_action" model="ir.actions.act_window">
+			<field name="name">Partner Attribute Sets</field>
+			<field name="res_model">attribute.set</field>
+			<field name="view_type">form</field>
+			<field name="view_mode">tree,form</field>
+			<field name="search_view_id" ref="base_custom_attributes.view_attribute_set_search"/>
+			<field name="context">{"force_model": 'res.partner'}</field>
+			<field name="help"></field>
+		</record>
+
+		<record id="attribute_group_form_action" model="ir.actions.act_window">
+			<field name="name">Attribute Groups</field>
+			<field name="res_model">attribute.group</field>
+			<field name="view_type">form</field>
+			<field name="view_mode">tree,form</field>
+			<field name="search_view_id" ref="base_custom_attributes.view_attribute_attribute_search"/>
+			<field name="context">{"force_model": 'res.partner'}</field>
+			<field name="help"></field>
+		</record>
+
+		<record id="attribute_attribute_form_action" model="ir.actions.act_window">
+			<field name="name">Partner Attribute</field>
+			<field name="res_model">attribute.attribute</field>
+			<field name="view_type">form</field>
+			<field name="view_mode">tree,form</field>
+			<field name="search_view_id" ref="base_custom_attributes.view_attribute_attribute_search"/>
+			<field name="context">{"force_model": 'res.partner'}</field>
+			<field name="help"></field>
+		</record>
+
+		<menuitem
+			action="attribute_set_form_action" id="menu_attribute_set_action"
+			parent="partner_custom_attributes.menu_attribute_in_config_partner" sequence="1"/>
+		<menuitem
+			action="attribute_group_form_action" id="menu_attribute_group_action"
+			parent="partner_custom_attributes.menu_attribute_in_config_partner" sequence="2"/>
+		<menuitem
+			action="attribute_attribute_form_action" id="menu_attribute_attribute_action"
+			parent="partner_custom_attributes.menu_attribute_in_config_partner" sequence="4"/>
+
+	</data>
+</openerp>

=== 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-04-25 12:57:27 +0000
@@ -0,0 +1,167 @@
+# -*- coding: utf-8 -*-
+###############################################################################
+#                                                                             #
+#   Author: Leonardo Pistone <leonardo.pistone@xxxxxxxxxxxxxx>                #
+#   Copyright 2014 Camptocamp SA                                              #
+#                                                                             #
+#   Inspired by the module product_custom_attributes                          #
+#   by Benoît GUILLOT <benoit.guillot@xxxxxxxxxxxx>, Akretion                 #
+#                                                                             #
+#   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 <http://www.gnu.org/licenses/>.     #
+#                                                                             #
+###############################################################################
+"""Partner customization: custom attributes."""
+
+from openerp.osv import fields, osv
+from tools.translate import translate
+from lxml import etree
+
+
+class ResPartner(osv.Model):
+    _inherit = "res.partner"
+
+    _columns = {
+        'attribute_set_id': fields.many2one('attribute.set', 'Attribute Set'),
+        'attribute_group_ids': fields.related(
+            'attribute_set_id',
+            'attribute_group_ids',
+            type='many2many',
+            relation='attribute.group'
+            ),
+    }
+
+    def _fix_size_bug(self, cr, uid, result, context=None):
+        """Workaround for the size of text fields. Return fixed fields.
+
+        When created a field text dinamically, its size is limited to 64 in
+        the view. The bug is fixed but not merged
+        https://code.launchpad.net/~openerp-dev/openerp-web/6.1-opw-579462-cpa
+        To remove when the fix will be merged
+
+        """
+        for field in result['fields']:
+            if result['fields'][field]['type'] == 'text':
+                if 'size' in result['fields'][field]:
+                    del result['fields'][field]['size']
+        return result
+
+    def open_attributes(self, cr, uid, ids, context=None):
+        """Open the attributes of an object. Return action.
+
+        This method is called when the user presses the Open Attributes button
+        in the form view of the object. It opens a dinamically-built form view.
+
+        :param ids: this is normally a singleton. If a longer list is passed,
+                    we consider only the first item.
+
+        """
+
+        if context is None:
+            context = {}
+
+        model_data_pool = self.pool.get('ir.model.data')
+
+        for partner in self.browse(cr, uid, ids, context=context):
+            view_id = model_data_pool.get_object_reference(
+                cr, uid,
+                'partner_custom_attributes',
+                'partner_attributes_form_view')[1]
+            ctx = {
+                'open_attributes': True,
+                'attribute_group_ids': [
+                    group.id for group in partner.attribute_group_ids
+                ]
+            }
+
+            return {
+                'name': 'Partner Attributes',
+                'view_type': 'form',
+                'view_mode': 'form',
+                'view_id': [view_id],
+                'res_model': self._name,
+                'context': ctx,
+                'type': 'ir.actions.act_window',
+                'nodestroy': True,
+                'target': 'new',
+                'res_id': partner.id,
+            }
+
+    def save_and_close_partner_attributes(self, cr, uid, ids, context=None):
+        """Button to save and close. Return action."""
+        return {'type': 'ir.actions.act_window_close'}
+
+    def fields_view_get(self, cr, uid, view_id=None, view_type='form',
+                        context=None, toolbar=False, submenu=False):
+        """Dinamically add attributes to the view. Return field_view_get.
+
+        Modifies dinamically the view to show the attributes. If the users
+        presses the Open Attributes button, the attributes are shown in a
+        new form field. Otherwise, if the attribute set is known beforehand,
+        attributes are added to a new tab in the main form view.
+
+        """
+        if context is None:
+            context = {}
+
+        def translate_view(source):
+            """Return a translation of type view of source."""
+            return translate(
+                cr, None, 'view', context.get('lang'), source
+            ) or source
+
+        attr_pool = self.pool.get('attribute.attribute')
+
+        result = super(ResPartner, self).fields_view_get(
+            cr, uid, view_id, view_type, context, toolbar=toolbar,
+            submenu=submenu
+        )
+        if view_type == 'form' and context.get('attribute_group_ids'):
+            eview = etree.fromstring(result['arch'])
+            # hide button under the name
+            button = eview.xpath("//button[@name='open_attributes']")
+            if button:
+                button = button[0]
+                button.getparent().remove(button)
+            attributes_notebook, toupdate_fields = (
+                attr_pool._build_attributes_notebook(
+                    cr, uid, context['attribute_group_ids'], context=context
+                )
+            )
+            result['fields'].update(
+                self.fields_get(cr, uid, toupdate_fields, context)
+            )
+            if context.get('open_attributes'):
+
+                # i.e. the user pressed the open attributes button on the
+                # form view. We put the attributes in a separate form view
+                placeholder = eview.xpath(
+                    "//separator[@string='attributes_placeholder']"
+                )[0]
+                placeholder.getparent().replace(
+                    placeholder, attributes_notebook
+                )
+            elif context.get('open_partner_by_attribute_set'):
+                # in this case, we know the attribute set beforehand, and we
+                # add the attributes to the current view
+                main_page = etree.Element(
+                    'page', string=translate_view('Custom Attributes')
+                )
+                main_page.append(attributes_notebook)
+                info_page = eview.xpath(
+                    "//page[@string='%s']" % (translate_view('Stock Moves'),)
+                )[0]
+                info_page.addnext(main_page)
+            result['arch'] = etree.tostring(eview, pretty_print=True)
+            result = self._fix_size_bug(cr, uid, result, context=context)
+        return result

=== 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-04-25 12:57:27 +0000
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<openerp>
+	<data>
+
+		<record model="ir.ui.view" id="res_partner_form_view_set_button">
+			<field name="name">attributes.partner.normal.form</field>
+			<field name="model">res.partner</field>
+			<field name="inherit_id" ref="base.view_partner_form" />
+			<field name="arch" type="xml">
+				<notebook position="inside">
+					<page string="Attributes">
+						<group name="attribute_fields">
+							<field name="attribute_set_id" />
+							<button name="open_attributes" string="Open Attributes" type="object" icon="gtk-ok" attrs="{'invisible':[('attribute_set_id', '=', False)]}"/>
+						</group>
+					</page>
+				</notebook>
+			</field>
+		</record>
+
+		<record model="ir.ui.view" id="partner_attributes_form_view">
+			<field name="name">partner.attributes.normal.wizard</field>
+			<field name="model">res.partner</field>
+			<field name="arch" type="xml">
+				<form string="partner" version="7.0">
+					<group name="name_set">
+						<field name="name"/>
+						<field name="attribute_set_id" />
+					</group>
+					<separator string="attributes_placeholder" colspan="4"/>
+					<footer>
+						<button name="save_and_close_partner_attributes" string="Save and Close" type="object" class="oe_highlight"/>
+						or
+						<button special="cancel" string="Cancel" class="oe_link"/>
+					</footer>
+				</form>
+			</field>
+		</record>
+
+	</data>
+</openerp>
\ No newline at end of file

=== 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-04-25 12:57:27 +0000
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+###############################################################################
+#                                                                             #
+#   Author: Leonardo Pistone <leonardo.pistone@xxxxxxxxxxxxxx>                #
+#   Copyright 2014 Camptocamp SA                                              #
+#                                                                             #
+#   Inspired by the module product_custom_attributes                          #
+#   by Benoît GUILLOT <benoit.guillot@xxxxxxxxxxxx>, Akretion                 #
+#                                                                             #
+#   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 <http://www.gnu.org/licenses/>.     #
+#                                                                             #
+###############################################################################
+
+from . import open_partner_by_attribute_set  # noqa

=== 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-04-25 12:57:27 +0000
@@ -0,0 +1,70 @@
+# -*- coding: utf-8 -*-
+###############################################################################
+#                                                                             #
+#   Author: Leonardo Pistone <leonardo.pistone@xxxxxxxxxxxxxx>                #
+#   Copyright 2014 Camptocamp SA                                              #
+#                                                                             #
+#   Inspired by the module product_custom_attributes                          #
+#   by Benoît GUILLOT <benoit.guillot@xxxxxxxxxxxx>, Akretion                 #
+#                                                                             #
+#   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 <http://www.gnu.org/licenses/>.     #
+#                                                                             #
+###############################################################################
+
+from openerp.osv.orm import TransientModel
+from osv import fields
+
+
+class open_partner_by_attribute_set(TransientModel):
+    _name = 'open.partner.by.attribute.set'
+    _description = 'Wizard to open partners by attributes set'
+
+    _columns = {
+        'attribute_set_id': fields.many2one('attribute.set', 'Attribute Set'),
+    }
+
+    def open_partner_by_attribute(self, cr, uid, ids, context=None):
+        """Opens a partner by attributes
+
+        Returns a custom action built modifying the original one.
+        """
+
+        mod_obj = self.pool.get('ir.model.data')
+        act_obj = self.pool.get('ir.actions.act_window')
+
+        if context is None:
+            context = {}
+
+        # we expect one wizard instance at a time
+        for wiz in self.browse(cr, uid, ids, context=context):
+            action_id = mod_obj.get_object_reference(
+                cr, uid, 'base', 'action_partner_form')[1]
+            action = act_obj.read(cr, uid, [action_id], context=context)[0]
+
+            ctx = (
+                "{'open_lot_by_attribute_set': True, "
+                "'attribute_group_ids': %s}"
+                % [
+                    group.id
+                    for group in wiz.attribute_set_id.attribute_group_ids
+                ]
+            )
+
+            action['context'] = ctx
+            action['domain'] = (
+                "[('attribute_set_id', '=', %s)]"
+                % wiz.attribute_set_id.id
+            )
+            action['name'] = wiz.attribute_set_id.name
+            return action

=== 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-04-25 12:57:27 +0000
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<openerp>
+	<data>
+
+		<record id="open_partner_by_attribute_set_view" model="ir.ui.view">
+			<field name="name">open.partner.by.attribute.set.view</field>
+			<field name="model">open.partner.by.attribute.set</field>
+			<field name="arch" type="xml">
+				<form string="Open partner by attributes set" version="7.0">
+					<group>
+						<field name="attribute_set_id" />
+					</group>
+					<footer>
+						<button name="open_partner_by_attribute" string="Open Partner By attribute" type="object" class="oe_highlight"/>
+						or
+						<button special="cancel" string="Cancel" class="oe_link"/>
+					</footer>
+				</form>
+			</field>
+		</record>
+
+		<record id="open_partner_by_attribute_set" model="ir.actions.act_window">
+			<field name="name">Open Partner By Attribute Set</field>
+			<field name="res_model">open.partner.by.attribute.set</field>
+			<field name="view_type">form</field>
+			<field name="target">new</field>
+			<field name="view_id" ref="open_partner_by_attribute_set_view"/>
+			<field name="help"/>
+		</record>
+
+		<menuitem action="open_partner_by_attribute_set" id="open_partner_wizard" parent="base.menu_sales"/>
+
+	</data>
+</openerp>


References