I have a computed-field "age" in "res.parnter" model, and I'm trying to filter the list based on this computed-field(i.e partner.age < 45). However, when I apply this "age" filter, I get request-timeout!. I tried many times but the result is the same -> request-timeout. Here is the response I get:
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>
..
..
Here are the code bocks that might be related to the issue.
age field
age = fields.Integer(string="Age", compute='compute_age', search='_search_age')
compute age function
@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
search function
def _search_age(self, operator, value):
return [('age', operator, value)]
That looks like an endless loop, because non-stored computed fields can't be searched and if there is a search method defined Odoo will always call that instead. Which leads to your search method which is using a non-stored computed field, which will Odoo lead to use the search method for age
again. I hope you get me ;-)
You have to redefine your search method to use birthday instead. Just invert your calculation to get a date to search on birthday
instead of age
.