Skip to Content
Menu
This question has been flagged

Here is my problem,
I have a form view(Parent) in which there is a one2many field, so when I click on the "add line" button, it opens the form view(child) of my linked model (child).
Now the thing I would like to do, is to set the default value for the many2one filed in (child) form view.
How could I achieve such behaviour ?


Here is a minimal reproducible example in pseudo code
Here is a github gist link "gist.github.com/lorenuars19/dd8d7a09f01b414ba2a9fdbdb68cb581"

===> parent.py:

class Parent(models.Model):
​_name = "test.parent"
​data = fields.Char("Data")
​child_ids = fields.One2many("test.child","parent_id")

<===
===> child.py:
class Child(models.Model):
​_name = "test.child"
​parent_id = fields.Many2one(comodel="test.parent",string="parent")
<===

next are the xml views

===> views.xml
<odoo> <record model="ir.ui.view" id="view_form_test_parent"> <field name="model">test.parentfield> <field name="arch" type="xml"> <form> <field name="data" />
form> field> record>
<record model="ir.ui.view" id="view_form_test_child"> <field name="model">test.childfield> <field name="arch" type="xml"> <form> <field name="parent_id"/> <field name="data"/> form> field> record>
<===

Avatar
Discard
Related Posts Replies Views Activity
0
Feb 17
4278
1
Nov 24
166
0
Apr 24
44
1
Apr 23
10579
1
Sep 21
8137