Hello , In this post we will discuss about the difference between @api.one and @api.multi which often cause confusing among Odoo developers ,we will try to make the difference clear.
@api.multi is used when we want to loop on records in this case self is the recordset , the recordset hold multiple record so we need to loop manually to extract record , below the code showing the synapse to use @api.multi.
note : the code is a edited code from the previous article http://wp.me/p8qqyC-4S
@api.one loop automatically on record hence self will hold be the current record information, so no need to add additional loop.
@api.multi with self.ensure_one():
if we want to verify that the Recordset hold a single record while using @api.multi ,we have to add self.ensure_one(),if Recordset hold more the system will throw and exceptions.
Thank You For reading ,if you have a question or any suggestion you can comment below or contact us from here : http://wp.me/P8qqyC-3