1
# -*- encoding: utf-8 -*-
2
###############################################################################
4
# product_custom_attributes for OpenERP #
5
# Copyright (C) 2011 Akretion Benoît GUILLOT <benoit.guillot@akretion.com> #
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. #
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. #
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/>. #
20
###############################################################################
22
from osv import osv, fields
24
from lxml import etree
25
from tools.translate import _
27
class product_product(osv.osv):
29
_inherit = "product.product"
34
def _build_shop_attributes_notebook(self, cr, uid, shops, context=None):
35
notebook = etree.Element('notebook', name="shop_attributes_notebook", colspan="4")
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
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']")
50
info_page = info_page[0]
51
shop_obj = self.pool.get('sale.shop')
52
shop_ids = shop_obj.search(cr, uid, [], context=context)
54
for shop in shop_obj.browse(cr, uid, shop_ids, context=context):
55
if shop.shop_attribute_ids:
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)