This is my code and i get a singleton error. I am trying to build a football database and in this function I try to update teams position based on the result of a match.
@api.multi
@api.depends('gola_home', 'gola_away')
def perditeso_piket(self):
for record in self:
if record.gola_home > record.gola_away:
self.sezonekip_home_id.fitore += 1
self.sezonekip_away_id.humbje += 1
elif record.gola_home == record.gola_away:
self.sezonekip_home_id.barazime += 1
self.sezonekip_away_id.barazime+=1
else:
self.sezonekip_home_id.humbje += 1
self.sezonekip_away_id.fitore+=1
You're using/programming it halfway correct. Looping on self
is the safe way because it could be a multi record recordset. But you missed to use record
later on in your incrementations.
Those incrementations are nothing more then setting a new value to the fields. But if self
is a multi record recordset (not a single record recordset, which is called singleton) Odoo isn't allowing a direct write/update. So just replace self
with record
in your incrementations:
@api.depends('gola_home', 'gola_away')
def perditeso_piket(self):
for record in self:
if record.gola_home > record.gola_away:
record.sezonekip_home_id.fitore += 1
record.sezonekip_away_id.humbje += 1
elif record.gola_home == record.gola_away:
record.sezonekip_home_id.barazime += 1
record.sezonekip_away_id.barazime+=1
else:
record.sezonekip_home_id.humbje += 1
record.sezonekip_away_id.fitore+=1