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

Hello,

I have Many2one field with domain function,

port_chargement_id = fields.Many2one('res.port', string='POL', domain=lambda self: self._get_port_chargement_domain())
def _get_port_chargement_domain(self):    
    domain = [('desservi', '=', True)]
    if self.sens_fret_id.id == 1:
        domain.append(('pays_id.code', 'not ilike', 'dz'))
    if self.sens_fret_id.id == 2:
        domain.append(('pays_id.code', 'ilike', 'dz'))
    return domain

From the function I tried to get the current item field with the self.sens_fret , but the self.xxxxx  doesn't work and it returns always False, i even tried  with self.name

อวตาร
ละทิ้ง

Hey salah! if you want to do these kind of stuff in on_change method than have a look it will help you: http://learnopenerp.blogspot.com/2016/10/onchange-many2one-filed-in-odoo.html

ผู้เขียน

Thanks! but in my case, the sens_fret_id field will be readonly in the next stage, so the port_chargement_id will always depend on the value selected previoulsly. so the onchange function will not be usefull.

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

Hi,

try this in an onchange function.

@api.onchange('sens_fret_id')
def onchange_sens_fret_id(self):
    domain = [('desservi', '=', True)]
    if self.sens_fret_id.id == 1:
        domain.append(('pays_id.code', 'not ilike', 'dz'))
    if self.sens_fret_id.id == 2:
        domain.append(('pays_id.code', 'ilike', 'dz'))
    return {'domain': {'port_chargement_id': domain}}

Thank you

อวตาร
ละทิ้ง
ผู้เขียน

Thanks! but in my case, the sens_fret_id field will be readonly in the next stage, so the port_chargement_id will always depend on the value selected previoulsly. so the onchange function will not be usefull.

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

I had solved the problem. Please see my blog: Odoo14, Pass variable from master to detail by context and using domain function

The article is posted on Facebook Odoo Developers.

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
2
พ.ค. 24
7779
using function in domain filter แก้ไขแล้ว
4
พ.ค. 20
73971
dynamic domain in one2many แก้ไขแล้ว
2
พ.ค. 24
9196
1
ม.ค. 22
11972
Dynamic Domain in Windows Action แก้ไขแล้ว
1
ก.ค. 20
16021