Records have an int method.
Often we have a function that depends on a Many2one relation sent via the context. Think warehouse_id
, cuurency_id
or product_id
. The problem is sometimes this might be sent as an integer, sometimes the record, or even as a string.
This often leads to code like if isinstance(...): convert
. However an alternative and useful way is model.browse(int(context_key))
. This elegantly handles an integer, a record or a string. It also reduces the number branches in our code to consider for testing.