Skip to Content
Menu
This question has been flagged
1 Reply
2876 Views

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
Discard
Best Answer

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
Discard
Related Posts Replies Views Activity
0
Jul 20
3022
0
Aug 24
158
4
Feb 24
4725
3
Mar 24
1663
1
Jul 24
734