[IMP] base, web: add not like and not ilike operators for the JS Odoo domain

Currently the `not like` and `not ilike` operators are available for the Odoo domain in Python but not in JS.

This commit adds these two operators in the JS Odoo domain too for better code clarity. For instance:
`[('fiscal_country_codes', 'not like', 'AR')]`
instead of
`['|', ('fiscal_country_codes', 'like', 'AR')]`

Part-of: odoo/odoo#106221
This commit is contained in:
Ricardo Gomes Rodrigues (rigr)
2022-12-09 11:48:42 +01:00
parent 092ca864db
commit 5376b60af0
3 changed files with 30 additions and 2 deletions
+10
View File
@@ -243,6 +243,11 @@ function matchCondition(record, condition) {
return false;
}
return fieldValue.indexOf(value) >= 0;
case "not like":
if (fieldValue === false) {
return false;
}
return fieldValue.indexOf(value) === -1;
case "=like":
if (fieldValue === false) {
return false;
@@ -253,6 +258,11 @@ function matchCondition(record, condition) {
return false;
}
return fieldValue.toLowerCase().indexOf(value.toLowerCase()) >= 0;
case "not ilike":
if (fieldValue === false) {
return false;
}
return fieldValue.toLowerCase().indexOf(value.toLowerCase()) === -1;
case "=ilike":
if (fieldValue === false) {
return false;
+16 -2
View File
@@ -88,8 +88,8 @@ QUnit.module("domain", {}, () => {
assert.ok(new Domain(["!", ["group_method", "=", "count"]]).contains(record));
});
QUnit.test("like, =like, ilike and =ilike", function (assert) {
assert.expect(16);
QUnit.test("like, =like, ilike, =ilike, not like and not ilike", function (assert) {
assert.expect(28);
assert.ok(new Domain([["a", "like", "value"]]).contains({ a: "value" }));
assert.ok(new Domain([["a", "like", "value"]]).contains({ a: "some value" }));
@@ -110,6 +110,20 @@ QUnit.module("domain", {}, () => {
assert.ok(new Domain([["a", "=ilike", "%value"]]).contains({ a: "some value" }));
assert.ok(new Domain([["a", "=ilike", "%value"]]).contains({ a: "Some Value" }));
assert.notOk(new Domain([["a", "=ilike", "%value"]]).contains({ a: false }));
assert.notOk(new Domain([["a", "not like", "value"]]).contains({ a: "value" }));
assert.notOk(new Domain([["a", "not like", "value"]]).contains({ a: "some value" }));
assert.ok(new Domain([["a", "not like", "value"]]).contains({ a: "Some Value" }));
assert.ok(new Domain([["a", "not like", "value"]]).contains({ a: "something" }));
assert.ok(new Domain([["a", "not like", "value"]]).contains({ a: "Something" }));
assert.notOk(new Domain([["a", "not like", "value"]]).contains({ a: false }));
assert.notOk(new Domain([["a", "not ilike", "value"]]).contains({ a: "value" }));
assert.notOk(new Domain([["a", "not ilike", "value"]]).contains({ a: "some value" }));
assert.notOk(new Domain([["a", "not ilike", "value"]]).contains({ a: "Some Value" }));
assert.ok(new Domain([["a", "not ilike", "value"]]).contains({ a: "something" }));
assert.ok(new Domain([["a", "not ilike", "value"]]).contains({ a: "Something" }));
assert.notOk(new Domain([["a", "not ilike", "value"]]).contains({ a: false }));
});
QUnit.test("complex domain", function (assert) {
+4
View File
@@ -2298,6 +2298,10 @@ class Form(object):
'>': operator.gt,
'in': lambda a, b: (a in b) if isinstance(b, (tuple, list)) else (b in a),
'not in': lambda a, b: (a not in b) if isinstance(b, (tuple, list)) else (b not in a),
'like': lambda a, b: a and b and isinstance(a, str) and isinstance(b, str) and a in b,
'ilike': lambda a, b: a and b and isinstance(a, str) and isinstance(b, str) and a.lower() in b.lower(),
'not like': lambda a, b: a and b and isinstance(a, str) and isinstance(b, str) and a not in b,
'not ilike': lambda a, b: a and b and isinstance(a, str) and isinstance(b, str) and a.lower() not in b.lower(),
}
def _get_context(self, field):
c = self._view['contexts'].get(field)