İçereği Atla
Menü
Bu soru işaretlendi
3 Cevaplar
17035 Görünümler

Hi;

i have a selection field called receiving_type with 3 options: cash, credit card and check

and another Many2one field called journal_id that shows the journals

the journal has 3 Boolean fields: check, credit_card, cash

i want to change the domain of journal_id depending on the value of the receiving type

for example:

journal x is cash journal, journal y is not

when i choose cash as receive type, i should see journal x only :)

Thanx!

Avatar
Vazgeç
En İyi Yanıt

Hi Bro, 

This is your solution :

@api.onchange('receiving_type')
def onchange_receiving_type(self):
     b={}
     if self.receiving_type=='cash':
         b ={'domain': {'journal_id': [('cash', '=', 1)]}}
     if self.receiving_type==''credit_card':
         b ={'domain': {'journal_id': [('credit_card', '=', 1)]}}
     if self.receiving_type=='check':
         b ={'domain': {'journal_id': [('check', '=', 1)]}}
     return b

Dont forget to vote positif :). 

Avatar
Vazgeç
Üretici

Thank You :)

You are very welcome

En İyi Yanıt

Hi,

See this sample, in this we have two fields one is partner_id and other is order_id , then if you choose a partner in partner_id field, then domain is given for the other field based on this.


partner_id = fields.Many2one('res.partner', string="Customer")
order_id = fields.Many2one('sale.order', string="Sale Order")

@api.onchange('partner_id')
def onchange_partner_id(self):
for rec in self:
return {'domain': {'order_id': [('partner_id', '=', rec.partner_id.id)]}}

See this:- How To Give Domain For A Field Based On Another Field

Thanks

Avatar
Vazgeç
Üretici

Thank You :)

En İyi Yanıt

This has been several years..

Just for some update for someone searched out this solution like me.

This feature is not supported now. see

Deprecate returning domains from onchange by xmo-odoo · Pull Request #41918 · odoo/odoo (github.com) 

the correct way is to add a domain field and compute it...

Avatar
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
1
Kas 19
3945
5
May 24
25181
0
Ağu 22
970
0
Haz 22
2197
2
Tem 15
4381