Ir al contenido
Menú
Se marcó esta pregunta
3 Respuestas
17007 Vistas

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
Mejor respuesta

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

Mejor respuesta

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 :)

Mejor respuesta

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
Publicaciones relacionadas Respuestas Vistas Actividad
1
nov 19
3923
5
may 24
25166
0
ago 22
970
0
jun 22
2189
2
jul 15
4377