İçereği Atla
Menü
Bu soru işaretlendi
3051 Görünümler

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
Vazgeç
İlgili Gönderiler Cevaplar Görünümler Aktivite
0
Şub 17
5277
1
Kas 24
1663
0
Nis 24
44
1
Nis 23
12184
1
Eyl 21
9438