Hello Zakaria,
Singleton error is raised when multiple records or empty records set is got and we update or do any operation without taking for loop or iteration.
self(1,2,3,4,5)
if we access directly from self (multiple records sets) then it will raise an error.
for example like t_state = self.state then it will raise an error
ValueError: Expected singleton: model.name(1,2,3,4,5) we can resolve it by taking for loop or iteration in the method.
but if we want to write something then it works
e.g: self.write({'state': 'draft'})
E.g to prevent error:
@api.multi
def vendre_cap(self)
for rec in self:
rec.state = 'draft'
New API decorator is used to defining method calling pattern whether methods allow only single object or multiple objects to invoke this method.
@api.one
This decorator loops automatically on Records of RecordSet for you. Self is redefined as current record
Note: Caution: the returned value is put in a list. This is not always supported by the web client, e.g. on button action methods. In that case, you should use @api.multi to decorate your method and probably call self.ensure_one() in the method definition.
@api.multi
Self will be the current RecordSet without iteration. It is the default behavior (multiple browsable objects). Methods which return non-premitive type data(list, dictionary, function) must be decorated with @api.multi
Thanks