تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
15693 أدوات العرض

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


الصورة الرمزية
إهمال
أفضل إجابة

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
الصورة الرمزية
إهمال

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

أفضل إجابة

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

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
2
سبتمبر 23
8532
1
أبريل 20
10285
1
أبريل 20
4828
5
سبتمبر 19
5230
0
سبتمبر 19
2672