2
# -*- encoding: utf-8 -*-
3
##############################################################################
5
# OpenERP, Open Source Management Solution
6
# Copyright (C) 2011 TeMPO Consulting, MSF.
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU Affero General Public License as
10
# published by the Free Software Foundation, either version 3 of the
11
# License, or (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU Affero General Public License for more details.
18
# You should have received a copy of the GNU Affero General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
##############################################################################
24
from osv import fields
26
class res_partner(osv.osv):
28
_inherit = 'res.partner'
32
def _set_in_product(self, cr, uid, ids, field_name, arg, context={}):
34
Returns according to the context if the partner is in product form
38
product_obj = self.pool.get('product.product')
40
# If we aren't in the context of choose supplier on procurement list
41
if not context.get('product_id', False) or 'choose_supplier' not in context:
45
product = product_obj.browse(cr, uid, context.get('product_id'))
47
# Get all suppliers defined on product form
48
for s in product.seller_ids:
49
seller_ids.append(s.name.id)
50
# Check if the partner is in product form
60
'in_product': fields.function(_set_in_product, string='In product', type="boolean", readonly=True, method=True),
63
def read(self, cr, uid, ids, fields=None, context={}, load='_classic_read'):
65
Sort the supplier according to the context
67
res = super(res_partner, self).read(cr, uid, ids, fields, context=context, load=load)
68
# If we are in the context of choose supplier on procurement list
69
if context.get('product_id', False) and 'choose_supplier' in context:
70
# Add in_product field in read
71
if not 'in_product' in fields:
72
fields.append('in_product')
78
if r.get('in_product', False):
81
not_seller_ids.append(r)
83
result = seller_ids + not_seller_ids
91
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: