Skip to content

what is Command in odoo 17? #157

Answered by luisg123v
it12uw asked this question in Q&A
Mar 12, 2024 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Starting from Odoo 15.0, the Command syntax is the preferred way to set values to One2many and Many2many fields when creating or writing to records, instead of using numeric commands.

For instance, instead of:

self.write({"partner_ids": [(6, 0, partners.ids)]})

We would do:

self.write({"partner_ids": [Command.set(partners.ids)]})

Note that this syntax also works in XML, e.g.:

<field name="partner_ids" eval="[Command.set(ref('base.main_partner'))]" />

Here is how to translate from the old syntax to the new one:

Numeric syntax Command syntax
(0, 0, {...}) Command.create({...})
(1, id, {...}) Command.update(id, {...})
(2, id) Command.delete(id)
(3, id) Command.unlink(id)
(4…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@it12uw
Comment options

Answer selected by it12uw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants