
Understanding fields.Command in Odoo.
fields.Command is used to manage One2many and Many2many relationships in a structured way. It replaces old tuple commands like (0, 0, vals).
Common Commands from odoo import fields
Create a new record
fields.Command.create({'name': 'Line 1'})
Update existing record
fields.Command.update(line_id, {'qty': 5})
Remove link
fields.Command.unlink(line_id)
Clear all records
fields.Command.clear()
✅ Example Usage
order.order_line = [
fields.Command.create({'product_id': 1, 'product_uom_qty': 2}),
fields.Command.create({'product_id': 2, 'product_uom_qty': 1}),
]
✅ Cleaner
✅ More readable
✅ Recommended in newer Odoo versions