Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
3 Replies
16977 Tampilan

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
Buang
Jawaban Terbai

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
Buang
Penulis

Thank You :)

You are very welcome

Jawaban Terbai

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
Buang
Penulis

Thank You :)

Jawaban Terbai

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
Buang
Post Terkait Replies Tampilan Aktivitas
1
Nov 19
3910
5
Mei 24
25156
0
Agu 22
970
0
Jun 22
2171
2
Jul 15
4365