~camptocamp/e-commerce-addons/7.0-sale_payment_method-incompatible-args

« back to all changes in this revision

Viewing changes to product_custom_attributes_shop/product.py

  • Committer: Benoit Guillot
  • Date: 2012-08-10 12:03:22 UTC
  • Revision ID: benoit.guillot@akretion.com.br-20120810120322-d6cp2tmqc3xhv7u2
[ADD] add module product_custom_attributes_shop to manage the product attribute linked to a shop

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
###############################################################################
 
3
#                                                                             #
 
4
#   product_custom_attributes for OpenERP                                      #
 
5
#   Copyright (C) 2011 Akretion Benoît GUILLOT <benoit.guillot@akretion.com>  #
 
6
#                                                                             #
 
7
#   This program is free software: you can redistribute it and/or modify      #
 
8
#   it under the terms of the GNU Affero General Public License as            #
 
9
#   published by the Free Software Foundation, either version 3 of the        #
 
10
#   License, or (at your option) any later version.                           #
 
11
#                                                                             #
 
12
#   This program is distributed in the hope that it will be useful,           #
 
13
#   but WITHOUT ANY WARRANTY; without even the implied warranty of            #
 
14
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             #
 
15
#   GNU Affero General Public License for more details.                       #
 
16
#                                                                             #
 
17
#   You should have received a copy of the GNU Affero General Public License  #
 
18
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.     #
 
19
#                                                                             #
 
20
###############################################################################
 
21
 
 
22
from osv import osv, fields
 
23
import netsvc
 
24
from lxml import etree
 
25
from tools.translate import _
 
26
 
 
27
class product_product(osv.osv):
 
28
 
 
29
    _inherit = "product.product"
 
30
 
 
31
    _columns = {
 
32
    }
 
33
 
 
34
    def _build_shop_attributes_notebook(self, cr, uid, shops, context=None):
 
35
        notebook = etree.Element('notebook', name="shop_attributes_notebook", colspan="4")
 
36
        toupdate_fields = []
 
37
        for shop in shops:
 
38
            page = etree.SubElement(notebook, 'page', string=shop.name.capitalize())
 
39
            for attribute in shop.shop_attribute_ids:
 
40
                toupdate_fields.append(attribute.name)
 
41
                self._build_attribute_field(cr, uid, page, attribute, context=context)
 
42
        return notebook, toupdate_fields
 
43
 
 
44
    def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
 
45
        result = super(product_product, self).fields_view_get(cr, uid, view_id,view_type,context,toolbar=toolbar, submenu=submenu)
 
46
        if view_type == 'form':
 
47
            eview = etree.fromstring(result['arch'])
 
48
            info_page = eview.xpath("//page[@string='Information']")
 
49
            if info_page:
 
50
                info_page = info_page[0]
 
51
                shop_obj = self.pool.get('sale.shop')
 
52
                shop_ids = shop_obj.search(cr, uid, [], context=context)
 
53
                shops = []
 
54
                for shop in shop_obj.browse(cr, uid, shop_ids, context=context):
 
55
                    if shop.shop_attribute_ids:
 
56
                        shops.append(shop)
 
57
                if shops:
 
58
                    attributes_notebook, toupdate_fields = self._build_shop_attributes_notebook(cr, uid, shops, context=context)
 
59
                    result['fields'].update(self.fields_get(cr, uid, toupdate_fields, context))
 
60
                    main_page = etree.Element('page', string=_('Shop Attributes'))
 
61
                    main_page.append(attributes_notebook)
 
62
                    info_page.addnext(main_page)
 
63
                    result['arch'] = etree.tostring(eview, pretty_print=True)
 
64
        return result