Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
15698 Lượt xem

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")


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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
Ảnh đại diện
Huỷ bỏ

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

Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 9 23
8540
1
thg 4 20
10288
1
thg 4 20
4833
5
thg 9 19
5230
0
thg 9 19
2674