Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
3040 Представления

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
5274
1
нояб. 24
1653
0
апр. 24
44
1
апр. 23
12180
1
сент. 21
9431