我只学了两个星期的odoo-14。在我的代码中有三个计算函数。但我发现了一个错误:
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')])我认为这个错误与字段类型one2many有关。请帮忙找出我为什么会犯这个错误。
发布于 2022-04-28 23:37:03
将historial_ids的默认值设置为False。
若要避免以下错误:
psycopg2.errors.InvalidTextRepresentation:整数类型的无效输入语法:"NewId_0x7f7bb5dfceb0“
使用set操作从搜索结果中筛选出当前记录
示例:
@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发布于 2022-04-29 14:30:28
最后,我以以下方式解决了这个问题:
@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')])https://stackoverflow.com/questions/72047310
复制相似问题