【问题标题】:request-timeout when search on computed_field在计算字段上搜索时的请求超时
【发布时间】:2020-06-09 08:02:50
【问题描述】:

我在“res.parnter”模型中有一个计算字段“age”,我正在尝试根据这个计算字段过滤列表(即 partner.age request-timeout。这是我得到的回复:

XmlHttpRequestError Gateway Time-out
<html>
<head><title>504 Gateway Time-out</title></head>
<body bgcolor="white">
<center><h1>504 Gateway Time-out</h1></center>
<hr><center>nginx/1.10.3 (Ubuntu)</center>
</body>
</html>
..
..

以下是可能与问题相关的代码块。

年龄字段

age = fields.Integer(string="Age", compute='compute_age', search='_search_age')

计算年龄函数

@api.one
    def compute_age(self):
        if self.birthday:
            d1 = datetime.strptime(self.birthday, "%Y-%m-%d").date()
            d2 = date.today()
            self.age = (d2 - d1).days / 365

搜索功能

def _search_age(self, operator, value):
        return [('age', operator, value)]

【问题讨论】:

    标签: odoo odoo-8


    【解决方案1】:

    这看起来像是一个无限循环,因为无法搜索未存储的计算字段,并且如果定义了搜索方法,Odoo 将始终调用它。这会导致您的搜索方法使用非存储计算字段,这将导致 Odoo 再次使用 age 的搜索方法。我希望你能得到我;-)

    您必须重新定义搜索方法以改用生日。只需反转您的计算即可获得在 birthday 而不是 age 上搜索的日期。

    【讨论】:

    • 感谢您的快速回复,我有点明白了为什么它会导致无限循环。我将根据您的建议重新定义搜索方法并在此处反映结果。
    猜你喜欢
    • 2011-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-20
    • 1970-01-01
    • 1970-01-01
    • 2016-04-26
    • 1970-01-01
    相关资源
    最近更新 更多