I've only been learning odoo-14 for 2 weeks. There are three compute functions in my code. But I got the error:
Odoo Server Error
Traceback (most recent call last):
File "/home/joseangel.lopez/DESARROLLO/PycharmProjects/FacturaElectronica/trainingOdoo/odoo-14.0/odoo/addons/base/models/ir_http.py", line 237, in _dispatch
result = request.dispatch()
File "/home/joseangel.lopez/DESARROLLO/PycharmProjects/FacturaElectronica/trainingOdoo/odoo-14.0/odoo/http.py", line 685, in dispatch
result = self._call_function(**self.params)
File "/home/joseangel.lopez/DESARROLLO/PycharmProjects/FacturaElectronica/trainingOdoo/odoo-14.0/odoo/http.py", line 361, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/home/joseangel.lopez/DESARROLLO/PycharmProjects/FacturaElectronica/trainingOdoo/odoo-14.0/odoo/service/model.py", line 94, in wrapper
return f(dbname, *args, **kwargs)
File "/home/joseangel.lopez/DESARROLLO/PycharmProjects/FacturaElectronica/trainingOdoo/odoo-14.0/odoo/http.py", line 349, in checked_call
result = self.endpoint(*a, **kw)
File "/home/joseangel.lopez/DESARROLLO/PycharmProjects/FacturaElectronica/trainingOdoo/odoo-14.0/odoo/http.py", line 914, in __call__
return self.method(*args, **kw)
File "/home/joseangel.lopez/DESARROLLO/PycharmProjects/FacturaElectronica/trainingOdoo/odoo-14.0/odoo/http.py", line 533, in response_wrap
response = f(*args, **kw)
File "/home/joseangel.lopez/DESARROLLO/PycharmProjects/FacturaElectronica/trainingOdoo/odoo-14.0/addons/web/controllers/main.py", line 1394, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/home/joseangel.lopez/DESARROLLO/PycharmProjects/FacturaElectronica/trainingOdoo/odoo-14.0/addons/web/controllers/main.py", line 1386, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/home/joseangel.lopez/DESARROLLO/PycharmProjects/FacturaElectronica/trainingOdoo/odoo-14.0/odoo/api.py", line 399, in call_kw
result = _call_kw_multi(method, model, args, kwargs)
File "/home/joseangel.lopez/DESARROLLO/PycharmProjects/FacturaElectronica/trainingOdoo/odoo-14.0/odoo/api.py", line 386, in _call_kw_multi
result = method(recs, *args, **kwargs)
File "/home/joseangel.lopez/DESARROLLO/PycharmProjects/FacturaElectronica/trainingOdoo/odoo-14.0/odoo/models.py", line 3022, in read
return self._read_format(fnames=fields, load=load)
File "/home/joseangel.lopez/DESARROLLO/PycharmProjects/FacturaElectronica/trainingOdoo/odoo-14.0/odoo/models.py", line 3042, in _read_format
vals[name] = convert(record[name], record, use_name_get)
File "/home/joseangel.lopez/DESARROLLO/PycharmProjects/FacturaElectronica/trainingOdoo/odoo-14.0/odoo/models.py", line 5686, in __getitem__
return self._fields[key].__get__(self, type(self))
File "/home/joseangel.lopez/DESARROLLO/PycharmProjects/FacturaElectronica/trainingOdoo/odoo-14.0/odoo/fields.py", line 3149, in __get__
return super().__get__(records, owner)
File "/home/joseangel.lopez/DESARROLLO/PycharmProjects/FacturaElectronica/trainingOdoo/odoo-14.0/odoo/fields.py", line 2485, in __get__
return super().__get__(records, owner)
File "/home/joseangel.lopez/DESARROLLO/PycharmProjects/FacturaElectronica/trainingOdoo/odoo-14.0/odoo/fields.py", line 1028, in __get__
raise ValueError("Compute method failed to assign %s.%s" % (record, self.name))
Exception
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/joseangel.lopez/DESARROLLO/PycharmProjects/FacturaElectronica/trainingOdoo/odoo-14.0/odoo/http.py", line 641, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/joseangel.lopez/DESARROLLO/PycharmProjects/FacturaElectronica/trainingOdoo/odoo-14.0/odoo/http.py", line 317, in _handle_exception
raise exception.with_traceback(None) from new_cause
ValueError: Compute method failed to assign custom.module.solicitud(11,).historial_ids
#################################My model#########################################
class CustomModuleSolicitud(models.Model):
_name = 'custom.module.solicitud'
_description = "Solicitud"
_order = "create_date desc, id desc"
....
state = fields.Selection([('pendiente', 'Pendiente'), ('actualizado', 'Actualizado')],
string='Estado', default='pendiente', readonly=True, required=True)
agrupacion = fields.Char(string="Agrupación", readonly=True)
historial_ids = fields.One2many(comodel_name='custom.module.solicitud', string="Solicitudes", compute='_compute_historial')
....
@api.depends('agrupacion')
def _compute_historial(self):
for r in self:
if not r.agrupacion:
r.historial_ids = []
else:
r.historial_ids = self.env['custom.module.solicitud'].search([('agrupacion', '=', r.agrupacion),
('id', '!=', r.id),
('state', '=', 'actualizado')])
I think the error is related to the field type one2many. Please help to find why i got this error.
CodePudding user response:
Set the default value of historial_ids
to False
.
To avoid the following error:
psycopg2.errors.InvalidTextRepresentation: invalid input syntax for type integer: "NewId_0x7f7bb5dfceb0"
Use set operations to filter out the current record from the search result
Example:
@api.depends('agrupacion')
def _compute_historial(self):
for r in self:
if not r.agrupacion:
r.historial_ids = False
else:
r.historial_ids = self.env['custom.module.solicitud'].search(
[('agrupacion', '=', r.agrupacion),('state', '=', 'actualizado')]) - r
CodePudding user response:
Finally I solved the problem in the following way:
@api.depends('agrupacion')
def _compute_historial(self):
for r in self:
hids = r.historial_ids
if not r.agrupacion:
hids = []
else:
hids = self.env['etecsa.solicitud'].search([('agrupacion', '=', r.agrupacion),
('id', '!=', hids.id),
('state', '=', 'actualizado')])