• Tek Siong, Hock

Odoo ORM common method - update records

This Odoo technical development blog is my way to contribute back to the Odoo Community, for all the selfless and great sharing by the community members.


ORM update records methods are commonly used and yet under-documented.


You may find the Odoo ORM documentation here, which, as usual, is very hard to understand.

(0, 0, values) adds a new record created from the provided value dict.
(1, id, values)updates an existing record of id id with the values in values. Can not be used in create().
(2, id, 0) removes the record of id id from the set, then deletes it (from the database). Can not be used in create().
(3, id, 0) removes the record of id from the set, but does not delete it. Can not be used in create().
(4, id, 0) adds an existing record of id id to the set.
(5, 0, 0) removes all records from the set, equivalent to using the command 3 on every record explicitly. Can not be used in create().
(6, 0, ids) replaces all existing records in the set by the ids list, equivalent to using the command 5 followed by a command 4 for each id.

Below is the example on how to update unit price in an existing invoice line.


Click "Like" at the bottom of this blog, to motivate us to continue sharing more Odoo tips.

invoices = self.env['account.invoice'].browse(self.env.context.get('vendor_bill_id'))
invoice_lines = self.env['account.invoice.line'].browse(self.env.context.get('invoice_line_id'))
# the fields to update 
inv_value = {
    'price_unit': xxxx,
}
invoice[0].write({
    'invoice_line_ids': [
        (1, invoice_line[0].id, inv_value),
    ]
})
    


3 views

©2019 by Excelroot Technology Sdn Bhd.