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

I wrote the following code to check if stage_id does not have a record, then stage_id.fold = True, where did I go wrong, please help, thanks

@api.onchange('stage_id')
def _onchange_stage_id(self):
res = super(CrmLead, self)._onchange_stage_id()
for r in self.env['crm.stage'].search([]).ids:
if not self.search('stage_id', '=', r.id):
self.r.fold = True
return res
الصورة الرمزية
إهمال
الكاتب

Dương Đường . thank you, but for me it doesn't work, can you sp me me by email? tienentrust@gmail.com

أفضل إجابة

You're looping through IDs list not objects by using:

self.env['crm.stage'].search([]).ids
So this line:
if not self.search([('stage_id', '=', r.id)])
Should be:
if not self.search([('stage_id', '=', r)])
الصورة الرمزية
إهمال
الكاتب أفضل إجابة

thank you, my statement is probably wrong somewhere:

bug: File "d:\odoo-training\code\takara\takara_crm\models\crm_lead.py", line 22, in _onchange_stage_id

    if not self.search([('stage_id', '=', r.id)]):
AttributeError: 'int' object has no attribute 'id'

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

Hello vu van tien,

You write the wrong syntax of a search method when you check if condition.
Please Update this code.

@api.onchange('stage_id')
def _onchange_stage_id(self):
res = super(CrmLead, self)._onchange_stage_id()
for r in self.env['crm.stage'].search([]).ids:
if not self.search([('stage_id', '=', r.id)]):
self.r.fold = True
return res

Hope this could help ...

الصورة الرمزية
إهمال

Thanks for the help, I had to use js to deal with it

المنشورات ذات الصلة الردود أدوات العرض النشاط
2
أغسطس 25
1518
0
مايو 25
771
0
أغسطس 24
1096
2
مارس 24
1355
1
يوليو 22
2685