Skip to Content
Menú
This question has been flagged
3 Respostes
16995 Vistes

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
Descartar
Best Answer

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
Descartar
Autor

Thank You :)

You are very welcome

Best Answer

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
Descartar
Autor

Thank You :)

Best Answer

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
Descartar
Related Posts Respostes Vistes Activitat
1
de nov. 19
3922
5
de maig 24
25163
0
d’ag. 22
970
0
de juny 22
2185
2
de jul. 15
4369