Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
3670 Vistas

Odoo v13.

1) I have 'table0' model. I want to create "form view" where I can choose one record from 'table1'. 

It's easy. I created field Many2one to 'table1' and  I added this field to "Form view". It works :)

I have trouble with this:

2) Now, when record from 'table1' is chosen I want to choose another record from 'table2' which is related with 'table1' by field One2many. I want to make it in one "form view". How to define this field in "table0" model.


For example, let's say that  'table0' model is  "Gift Card" model. 'table1' model is "Group of toys" model. 'table2' model is "Toy" model.  

So, In "Gift Card" model form view we first choose one "group of toys", then we can choose one toy from chosen "group of toys". I don't know how to create field in 'table0' model and show it in form view that it will meet my expectations. 

I hope You understand the idea ;)

Thank You for any help :)

Avatar
Descartar
Mejor respuesta

In the form view you will need to add domain in the field. 

Gift Card - Form View

Add following fields in the Gift Card model

- toy_group_id (Many2one, Model - Group of toys

- toy_id (Many2one, Model - Toy

Add domain like that

<field name="toy_group_id" />
<field name="toy_id" domain="[('group_id', '=', toy_group_id)]" />

By applying this domain you will get filtered toy only who belongs to selected group of toys. 

Here, toy_id field belongs to Tot model in which the group_id field should be Many2one of model Group of Toy because Toy should belongs to only one group. So inverse you will get One2many relation in the Group of toy. 

Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
0
jul 20
4167
1
mar 25
1295
0
ago 24
1255
4
feb 24
6797
3
mar 24
3121