Ir al contenido
Menú
Se marcó esta pregunta

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
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
0
feb 17
4934
1
nov 24
1206
0
abr 24
44
1
abr 23
11801
1
sept 21
9070