Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
1 Відповісти
3679 Переглядів

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

Аватар
Відмінити
Найкраща відповідь

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. 

Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
0
лип. 20
4172
V17 Tree, Form view Вирішено
1
бер. 25
1298
0
серп. 24
1259
4
лют. 24
6800
3
бер. 24
3122