Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
11613 มุมมอง

hi,

I am creating a call log module , and i need to automatically get the partner information by the given number ie. the system have to automatically search and fetch the partner and assign it to a field .

Somebody please help me with the python code , my code is :


customer_number = fields.Char(string='Customer Number', track_visiility='onchange', onchange='get_partner()', store=True)
customer_id = fields.Many2one('res.partner', string='Customer', track_visibility='onchange',index=True,
help="Linked partner (optional). Usually created when converting the lead.", store=True)

#--------------------------------------------------
# Api s
#--------------------------------------------------

@api.onchange('customer_number')

def get_partner(self):
if self.customer_number:
partner = self.env['res.partner'].search_read([('self.customer_number', 'ilike', 'self.phone')])
self.customer_id = partner
return self.customer_id
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hello,

You need to remove quotes from self.phone and should use search method to find the Parther.

Ex:

self.customer_id = self.env['res.partner'].search(['|', ('phone', 'ilike', self.customer_number), ('mobile', 'ilike', self.customer_number)], limit=1).id


อวตาร
ละทิ้ง

Also, the 'self.customer_number' in the search has to be changed to 'phone' or 'mobile'

Thanks for drawing the attention. I corrected the code now.

คำตอบที่ดีที่สุด

Hi,

Update the onchange function like this,

@api.onchange('customer_number')
def get_partner(self):
if self.customer_number:
partner = self.env['res.partner'].search([('phone', 'ilike', self.customer_number)], limit=1)
if partner:
self.customer_id = partner.id


Thanks

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
Can't import a model in odoo view แก้ไขแล้ว
7
ก.ค. 19
41730
0
เม.ย. 19
3218
0
ต.ค. 19
4288
0
ส.ค. 18
6922
1
ธ.ค. 17
3535