Hello everyone
I've created a custom selection field called payment_status which is not stored. I want to create filter for this without storing it. for this I've added the search function. my code is:
payment_status = fields.Selection( [ ("not_paid", "Not Paid"), ("partially_paid", "Partially Paid"), ("fully_paid", "Fully Paid"), ], compute="_computepaid", search="_search_payment_status" )
def _search_payment_status(self,operator, value):
if value not in ['not_paid', 'partially_paid', 'fully_paid']:
return [('id', 'in', [])]
search_domain = [('payment_status', '=', value)]
for rec in self:
orders = rec.env['purchase.order'].search(search_domain)
return [('id', 'in', orders.ids)]
but this is generating the following error:
Odoo Server Error
Traceback (most recent call last): File "/usr/lib/python3/dist-packages/odoo/http.py", line 624, in _handle_exception return super(JsonRequest, self)._handle_exception(exception) File "/usr/lib/python3/dist-packages/odoo/http.py", line 310, in _handle_exception raise pycompat.reraise(type(exception), exception, sys.exc_info()[2]) File "/usr/lib/python3/dist-packages/odoo/tools/pycompat.py", line 14, in reraise raise value File "/usr/lib/python3/dist-packages/odoo/http.py", line 669, in dispatch result = self._call_function(**self.params) File "/usr/lib/python3/dist-packages/odoo/http.py", line 350, in _call_function return checked_call(self.db, *args, **kwargs) File "/usr/lib/python3/dist-packages/odoo/service/model.py", line 94, in wrapper return f(dbname, *args, **kwargs) File "/usr/lib/python3/dist-packages/odoo/http.py", line 339, in checked_call result = self.endpoint(*a, **kw) File "/usr/lib/python3/dist-packages/odoo/http.py", line 915, in __call__ return self.method(*args, **kw) File "/usr/lib/python3/dist-packages/odoo/http.py", line 515, in response_wrap response = f(*args, **kw) File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 1300, in search_read return self.do_search_read(model, fields, offset, limit, domain, sort) File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 1319, in do_search_read return Model.web_search_read(domain, fields, offset=offset, limit=limit, order=sort) File "/usr/lib/python3/dist-packages/odoo/addons/web/models/models.py", line 48, in web_search_read records = self.search_read(domain, fields, offset=offset, limit=limit, order=order) File "/usr/lib/python3/dist-packages/odoo/models.py", line 4964, in search_read records = self.search(domain or [], offset=offset, limit=limit, order=order) File "/usr/lib/python3/dist-packages/odoo/models.py", line 1655, in search res = self._search(args, offset=offset, limit=limit, order=order, count=count) File "/usr/lib/python3/dist-packages/odoo/models.py", line 4506, in _search query = self._where_calc(args) File "/usr/lib/python3/dist-packages/odoo/models.py", line 4226, in _where_calc e = expression.expression(domain, self) File "/usr/lib/python3/dist-packages/odoo/osv/expression.py", line 681, in __init__ self.parse() File "/usr/lib/python3/dist-packages/odoo/osv/expression.py", line 948, in parse model._flush_search(domain, order='id') File "/usr/lib/python3/dist-packages/odoo/models.py", line 4422, in _flush_search domain = list(domain) + (self.env['ir.rule']._compute_domain(self._name, 'read') or []) TypeError: 'NoneType' object is not iterable
I even tried to add conditions for None records but it doesn't work.
Can anyone please help me on this?
share the code of _computepaid function along with the post