Skip to Content
Menu
This question has been flagged
2 Replies
3442 Views
class HelpdeskTeam(models.Model):
....
category_ids= fields.Many2many(comodel_name="helpdesk.ticket.category", string="Category")
....

class HelpdeskTicket(models.Model):
....
team_id= fields.Many2one(comodel_name="helpdesk.ticket.team",string="Area")
category_id= fields.Many2one(comodel_name="helpdesk.ticket.category",string="Category")
....

in the form view:
....
...fieldname="category_id"domain="[(category_id, 'in', 'team_id.category_ids')]"...
....


Can I add a conditional field to show specific values in the list?

Avatar
Discard
Best Answer

Hi,
You can add domain for one field based on another field using onchange.


@api.onchange('team_id')
def get_categories(self):
​if self.team_id:
​domain = [('field_name', '=', value)]
​else:
​domain = []
​return {'domain': {'category_id': domain}}


You can read more about dynamic domain from this blog:
https://www.cybrosys.com/blog/how-to-apply-dynamic-domain-for-relational-fields-in-odoo-16


Hope it helps!

Avatar
Discard
Best Answer

Hi,

Using the domain attribute you can filter the value listed in all the fields, the domain expression has to be written in the needed format. Domain can be applied in python level as well as in the view level.


If you look at this video, you will get detailed idea about it and you can map it according to your need:  

https://www.youtube.com/watch?v=dq5Vtj_pwuI


Thanks

Avatar
Discard
Related Posts Replies Views Activity
3
Oct 18
3495
3
Sep 16
5792
0
Mar 15
3212
1
Mar 15
3860
3
May 25
2689