1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2014 TeMPO Consulting, MSF
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 fields
25
from tools.translate import _
28
class product_supplierinfo(osv.osv):
30
override name_get to display name of the related supplier
32
override create to be able to create a new supplierinfo from sourcing view
34
_name = 'product.supplierinfo'
35
_inherit = 'product.supplierinfo'
37
def _get_false(self, cr, uid, ids, field_name, arg, context=None):
39
return false for each id
41
if isinstance(ids, (long, int)):
49
def _get_product_ids(self, cr, uid, obj, name, args, context=None):
51
from the product.template id returns the corresponding product.product
58
_('Filter not implemented'),
60
# product id of sourcing line
61
productId = args[0][2]
62
# gather product template id for that product
63
templateId = self.pool.get('product.product').browse(cr, uid, productId, context=context).product_tmpl_id.id
64
# search filter on product_id of supplierinfo
65
return [('product_id', '=', templateId)]
68
'product_product_ids': fields.function(
70
fnct_search=_get_product_ids,
73
relation='product.product',
78
def name_get(self, cr, uid, ids, context=None):
81
display the name of the product instead of the id of supplierinfo
87
for supinfo in self.browse(cr, uid, ids, context=context):
88
supplier = supinfo.name
89
result.append((supinfo.id, supplier.name_get(context=context)[0][1]))
93
def create(self, cr, uid, values, context=None):
96
inject product_id in newly created supplierinfo
100
if context and 'sourcing-product_id' in context:
101
productId = context['sourcing-product_id']
102
product = self.pool.get('product.product').browse(cr, uid, productId, context=context)
103
values.update({'product_id': product.product_tmpl_id.id})
105
return super(product_supplierinfo, self).create(cr, uid, values, context)
107
product_supplierinfo()
109
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: