This question has been flagged
2 Replies
13174 Views

I've added a custom field called organization_no to the 'res.partner' model. Now I want to search res.partner records with the newly created organization_no, in many2one fields(example the partner_id in sale order form).

I've tried _rec_name = 'organization_name'. But this doesn't seem to work. Is this even possible? Any ideas?


class ResPartner(models.Model):
    _inherit = 'res.partner'
    _rec_name = 'organization_no'

    organization_no = fields.Char(string="Organization No")


Avatar
Discard
Best Answer

Hi Jones,

You can do it using name_search() method.

Ex:

@api.model
def name_search(self, name, args=None, operator='ilike', limit=100):
args = args or []
recs = self.search([('organization_no', operator, name)] + args, limit=limit)
    if not recs.ids:
        return super(ResPartner, self).name_search(name=name, args=args,
operator=operator,
limit=limit)
return recs.name_get()

I hope this will help you.

Sudhir Arya
ERP Harbor Consulting Services
Skype:sudhir@erpharbor.com
Website: http://www.erpharbor.com
Avatar
Discard

This should have been an accepted answer for ages :) Accepted it for you.

Best Answer

Hi, 

You can define a  name_get function for the model res.partner .


See the sample code below,

class ResPartner(models.Model):
_inherit = 'res.partner'

@api.multi
@api.depends('name', 'email')
def name_get(self):
result = []
for rec in self:
name = str(rec.name) + ' ' + str(rec.email)
result.append((rec.id, name))
return result


Thanks

Avatar
Discard