DEV Community

Cover image for Odoo : Command syntax
Jeevachaithanyan Sivanandan
Jeevachaithanyan Sivanandan

Posted on

2

Odoo : Command syntax

If you are an Odoo developer, you might have used code like

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

There is another approach to do same using commands. We can import the command as below

from odoo import api, fields, models, _, Command
Enter fullscreen mode Exit fullscreen mode

then we shall do

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

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

we can also use in the XML as below

<field name="partner_ids" eval="[Command.set(ref('base.main_partner'))]" />
Enter fullscreen mode Exit fullscreen mode
Numeric syntax Command syntax
(0, 0, {...}) Command.create({...})
(1, id, {...}) Command.update(id, {...})
(2, id) Command.delete(id)
(3, id) Command.unlink(id)
(4, id) Command.link(id)
(5, 0, 0) Command.clear()
(6, 0, ids) Command.set(ids)

for more : https://github.com/orgs/OCA/discussions/157
https://www.odoo.com/documentation/17.0/developer/reference/backend/orm.html#odoo.fields.Command

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay