I have two problems with my code:
- I need get the partner name not just the id
- and its searching all the partners not just the ones on the product I am selecting in product_id
Here is my code:
def get_product_provider(self, cr, uid, ids, field_name, args=None, context=None):
res = {}
for record in self.browse(cr, uid, ids, context=context):
cr.execute('''select id from product_supplierinfo where product_tmpl_id in (select id from product_template) order by RANDOM() limit 1''')
val = cr.fetchone()
if val:
res[record.id] = val[0]
else:
res[record.id] = False
return res
_columns = {
'ServicesID': fields.char('Services ID', size=15),
'product_id': fields.many2one('product.product', 'name', 'Service Name'),
'product_is_random': fields.related('product_id', 'is_random', type='boolean', string='Product is Random', readonly=True),
'AppNum': fields.many2one('itaconloans.e3loan', 'Application Number', select=True),
'provider': fields.many2one('res.partner', 'Provider Name', select=True),
'random_seller_info_id': fields.function(get_product_provider, type='many2one', relation="product.supplierinfo", string="Random Supplier", store=True),
#'random_provider': fields.related('random_seller_info_id', 'name', type='many2one', string='Provider Name', readonly=True),
'DateReq': fields.date('Date Requested'),
'DateComp': fields.date('Date Completed'),
'DateToComp': fields.date('Date To Complete'),
'comments': fields.text('Comments', translate=True),
}