In the Odoo python coding, sometimes the software developer will use the following to update the values.
record.field1 = value1
record.field2 = value2
or
record[field1] = value1
record[field2] = value2
or
record.update({field1: value1, field2: value2})
All of the 3 examples are basically same, and on each line of code, it will trigger the standard write method. As such, the 5 lines of the codes above are triggering 6 times the write method, which is inefficient in the performance and may cause bug in some extreme cases.
The best practise is to use the following write, which will call the write method for once to update all the field values.
record.write({field1: value1, field2: value2})
Comments