i need some help i am starting in odoo and i have this
@api.depends('clave_factura')
def set_totales(self):
self.env.cr.execute('select sum(total_detalle) as total from caratulas_detalle where factura_id = %s', (self.clave_factura,))
# fetchone() will return the first element found as dictionary
registros = self.env.cr.fetchall()
totaldtotales = registros[0] if registros else 0
for rec in self:
rec.total_kllevo = totaldtotales
rec.total_resto = rec.total_fac - rec.total_kllevo
and these are my fields
total_kllevo = fields.Float('Lo Agregado', readonly=True, help='Total', compute='set_totales', store=True)
total_resto = fields.Float('Lo Restante', readonly=True, help='Total', compute='set_totales', store=True)
and this is the error
File "c:\program files (x86)\odoo 12.0\server\odoo\addons\prossesa_proyectos\models\prossesa_proyectos.py", line 147, in set_totales
rec.total_kllevo = totaldtotales
File "C:\Program Files (x86)\Odoo 12.0\server\odoo\fields.py", line 1003, in __set__
value = self.convert_to_cache(value, record)
File "C:\Program Files (x86)\Odoo 12.0\server\odoo\fields.py", line 1263, in convert_to_cache
value = float(value or 0.0)
TypeError: float() argument must be a string or a number, not 'tuple'
I know that maybe it is something really easy but my mind crash.
You got that error because the first element of registros
is a tuple.
Example:
>>> registros = self.env.cr.fetchall()
>>> registros[0]
(4610.0,)
You can fixt it using the first element of totaldtotales
.