When a domain field value is edited via the debug textarea, no search_count is done for performance reasons. A single exception is done when saving the record. Then we check the validity of the domain created in the debug textarea in order to avoid to save an invalid domain in db (and get tracebacks,..). The problem is that a search_count can take a very long time to be executed if the domain is valid. Here we introduce a route /web/domain/validate in order to quickly check the validity of a domain and use it in domain field in order to fix the above mentionned performance issue. Note that the search_count is still done if it useful but does not have to be waited anymore. X-original-commit: 40288221c39ff8fba41cd6ac231ab33600dc0cd4 Part-of: odoo/odoo#128913 Co-authored-by: Oliver Dony <odo@odoo.com> Co-authored-by: Mathieu Duckerts-Antoine <dam@odoo.com>
43 lines
1.5 KiB
Python
43 lines
1.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
import json
|
|
|
|
from odoo.tests import HttpCase, tagged
|
|
from odoo.tools import mute_logger
|
|
|
|
@tagged('post_install', '-at_install')
|
|
class DomainTest(HttpCase):
|
|
|
|
def test_domain_validate(self):
|
|
self.authenticate("demo", "demo")
|
|
|
|
with mute_logger('odoo.http'):
|
|
resp = self.url_open(
|
|
'/web/domain/validate',
|
|
headers={'Content-Type': 'application/json'},
|
|
data=json.dumps({'params': {'model':'i', 'domain':[]}}),
|
|
)
|
|
self.assertEqual(resp.json()['error']['data']['message'], "Invalid model: i")
|
|
|
|
resp = self.url_open(
|
|
'/web/domain/validate',
|
|
headers={'Content-Type': 'application/json'},
|
|
data=json.dumps({'params': {'model':'res.users', 'domain':[]}}),
|
|
)
|
|
self.assertEqual(resp.json()['result'], True)
|
|
|
|
resp = self.url_open(
|
|
'/web/domain/validate',
|
|
headers={'Content-Type': 'application/json'},
|
|
data=json.dumps({'params': {'model':'res.users', 'domain':[('name', 'ilike', 'ad')]}}),
|
|
)
|
|
self.assertEqual(resp.json()['result'], True)
|
|
|
|
resp = self.url_open(
|
|
'/web/domain/validate',
|
|
headers={'Content-Type': 'application/json'},
|
|
data=json.dumps({'params': {'model':'res.users', 'domain':[('hop')]}}),
|
|
)
|
|
self.assertEqual(resp.json()['result'], False)
|