在 computed_field 上搜索时请求超时
request-timeout when search on computed_field
我在 "res.parnter" 模型中有一个计算字段 "age",我正在尝试根据此计算字段(即 partner.age < 45)过滤列表。但是,当我应用此 "age" 过滤器时,我收到请求超时!。
我尝试了很多次,但结果都是一样的 -> 请求超时。这是我得到的回复:
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 再次使用 age
的搜索方法。我希望你能理解我 ;-)
您必须重新定义搜索方法以改用生日。只需反转您的计算即可获得要在 birthday
而不是 age
.
上搜索的日期
我在 "res.parnter" 模型中有一个计算字段 "age",我正在尝试根据此计算字段(即 partner.age < 45)过滤列表。但是,当我应用此 "age" 过滤器时,我收到请求超时!。 我尝试了很多次,但结果都是一样的 -> 请求超时。这是我得到的回复:
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 再次使用 age
的搜索方法。我希望你能理解我 ;-)
您必须重新定义搜索方法以改用生日。只需反转您的计算即可获得要在 birthday
而不是 age
.