Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
3638 Vistas
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
Descartar
Mejor respuesta

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

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
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
3
oct 18
3699
3
sept 16
5915
0
mar 15
3355
1
mar 15
3951
3
may 25
3190