我在“ res.parnter”模型中有一个计算字段“ age”,并且我正在尝试根据此计算字段(即partner.age <45)过滤列表。但是,当我应用此“年龄”过滤器时,我收到请求超时!我尝试了很多次,但结果是相同的->请求超时。这是我得到的答复:
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
上搜索的日期。