Problem
You want to create both a main record and its linked relation record in one form view, without merging the models.
Your current XML tries to embed a <form> inside a <field>, which isn't valid Odoo syntax.
Correct Approach
Use inline editing with the options attribute on the many2one field. Here’s how:
1. Update Your XML View
xml
<record id="view_main_form" model="ir.ui.view">
<field name="name">main.form.view</field>
<field name="model">main</field>
<field name="arch" type="xml">
<form>
<sheet>
<group>
<field name="name"/>
</group>
<notebook>
<page string="Relation">
<field name="relation_id"
options="{'no_open': True, 'no_create': False}"
context="{'form_view_ref': 'your_module.view_relation_form'}"/>
</page>
</notebook>
</sheet>
</form>
</field>
</record>
2. Create a Separate Form View for relation
Define a simplified form for quick creation:
xml
<record id="view_relation_form" model="ir.ui.view">
<field name="name">relation.popup.form</field>
<field name="model">relation</field>
<field name="arch" type="xml">
<form>
<group>
<field name="name_relation"/>
<field name="second_field"/>
</group>
</form>
</field>
</record>
3. Key Attributes Explained
- options="{'no_open': True}": Prevents opening the full record view.
- no_create: Set to False to allow new record creation.
- context="{'form_view_ref': ...}": Forces the popup to use your custom form.
Alternative: Default Values
If you always want to auto-create a relation when creating a main record:
1. Override create in main model
python
@api.model
def create(self, vals):
if not vals.get('relation_id'):
relation = self.env['relation'].create({
'name_relation': vals.get('name') + " Relation",
'second_field': "Default Value",
})
vals['relation_id'] = relation.id
return super().create(vals)
Result
Now when you:
- Create a new main record,
- Click the relation_id field,
- Select "Create and Edit",
- A popup with your custom relation form appears.
After saving both forms, the records are linked automatically.
Why This Works
- Odoo’s many2one field natively supports inline creation.
- The options and context attributes control the behavior.
- No need for nested <form> tags (which aren’t supported).
🚀 Did This Solve Your
Problem?
If this answer helped you save time, money, or
frustration, consider:
✅ Upvoting (👍)
to help others find it faster
✅ Marking
as "Best Answer" if it resolved your issue
Your feedback keeps the Odoo community strong! 💪
(Need further customization? Drop a comment—I’m happy to
refine the solution!)
Can your nested form node not just simply become a list? I don't really get what you are trying to achieve with this setup, hence also can't tell you what you may do for the moment.
Christoph Farnleitne ,I merge the two table and solve my problem.