ValueError:计算方法未能分配custy.module(11,)。odoo中的Historial_ids 14

发布于 2025-01-24 18:54:48 字数 5134 浏览 4 评论 0原文

我只学习ODOO-14 2周。 我的代码中有三个计算功能。但是我有错误:

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

################################ ################################

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'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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夕嗳→ 2025-01-31 18:54:48

Historial_ids的默认值设置为false

为了避免以下错误:

psycopg2.errors.invalidtextrepersentation:type Integer的无效输入语法:“ newId_0x7f7bb5dfceb0”

使用设置操作来从搜索结果中滤除当前记录

@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

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
蓝海似她心 2025-01-31 18:54:48

最后,我以以下方式解决了问题:


@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')])

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')])

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文