Odoo Help

Welcome!

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.

0

show supplier name in product tree view

By
fdim
on 5/31/13, 9:50 AM 1,462 views

I try to show supplier name in product tree view so i create this function :

class product_product(osv.osv):

    _inherit = 'product.product'

    def get_supplier_name(self, cr, uid, *args):
        cr.execute("select pt.name from res_partner pt  join product_supplierinfo fr on (fr.name=pt.id)  where fr.sequence = 1")
        res = cr.fetchone()
        return res

    _columns = {
      'supplier_name': fields.function(get_supplier_name, method=True,string="Supplier name",type="many2one", store = True),
      }


product_product()

But I have this error :

    Traceback (most recent call last): File "netsvc.pyo", line 489, in dispatch File "service\web_services.pyo", line 599, in dispatch File "osv\osv.pyo", line 122, in wrapper File "osv\osv.pyo", line 176, in execute File "osv\osv.pyo", line 167, in execute_cr File "osv\orm.pyo", line 2940, in read File "osv\orm.pyo", line 3060, in _read_flat File "osv\fields.pyo", line 799, 
in get AttributeError: 'tuple' object has no attribute 'values'

What can I do?

I rectify the type of the field "supplier_name" to char and I've thie error : TypeError: int argument required

fdim
on 5/31/13, 11:26 AM
0

Andreas Brueckl

--Andreas Brueckl--
5056
| 7 8 7
Vienna, Austria
--Andreas Brueckl--
OpenERP Consulting and Development
Andreas Brueckl
On 5/31/13, 11:42 AM

Try this method (assuming, that the type of the function field is many2one):

def get_supplier_name(self, cursor, user, ids, name, arg, context=None):
    res = {}
    for product in self.browse(cursor, user, ids, context=context):
        if product.seller_ids:
          res[product.id] = product.seller_ids[0].id
        else:
          res[product.id] = False
    return res

I tried your method but : get AttributeError: 'NoneType' object has no attribute 'name_get'

fdim
on 5/31/13, 11:51 AM

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

0 follower(s)

Stats

Asked: 5/31/13, 9:50 AM
Seen: 1462 times
Last updated: 3/16/15, 8:10 AM