Skip to Content
Menu
This question has been flagged
1 Reply
4344 Views

Hello everyone hope you're doing well, 

i just want to override the name_get function for the contacts in res.partner 

i did as follow : 

@api.multi

    def name_get(self):

         res = super(ResPartner, self).name_get()

        data = []

        for rec in self:

            if (rec.type == 'other'):

                display_value = ''

                display_value += rec.name or ""

                display_value += ' ,'

                display_value += rec.firstname or ""

                display_value += ','

                data.append((rec.id, display_value))

        return data

where type = other is how i can distinguish contacts from companies but it doesn't work i keep getting this error :

UnicodeError: unable to convert <odoo.tools.func.lazy object at 0x7f0629cc41b0>


please help this is driving me crazy

thank you all 


Avatar
Discard
Best Answer

Try to use the following code:

@api.multi

def name_get(self):

    res = []
    for rec in self:
        if (rec.type == 'other'):
            res.append((rec.id, "%s, %s" % (rec.name, rec.firstname or "")))
        else:
            res.append((rec.id, "%s" % rec.name))
    return res

Avatar
Discard