Odoo Help


This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Need to get my method to output the partner name not just the id and have it select it only from the suppliers in the product I

Emmanuel Roldan
on 8/14/14, 5:02 PM 432 views

I have two problems with my code:

  1. I need get the partner name not just the id
  2. 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]
                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),


Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)


Asked: 8/14/14, 5:02 PM
Seen: 432 times
Last updated: 3/16/15, 8:10 AM