Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3046 มุมมอง

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>
<===

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
0
ก.พ. 17
5277
1
พ.ย. 24
1659
0
เม.ย. 24
44
How to show context in view แก้ไขแล้ว
1
เม.ย. 23
12184
1
ก.ย. 21
9436