Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
3 Odpowiedzi
17059 Widoki

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!

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Autor

Thank You :)

You are very welcome

Najlepsza odpowiedź

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

Awatar
Odrzuć
Autor

Thank You :)

Najlepsza odpowiedź

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...

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
lis 19
3972
5
maj 24
25221
0
sie 22
970
0
cze 22
2230
2
lip 15
4412