changeset f71d57b75ee9 in sao:default
details: https://hg.tryton.org/sao?cmd=changeset&node=f71d57b75ee9
description:
        Remove extra operator when simplifying nested domains

        issue11406
        review390621002
diffstat:

 src/common.js |  15 +++++++++++----
 tests/sao.js  |   3 +++
 2 files changed, 14 insertions(+), 4 deletions(-)

diffs (40 lines):

diff -r ad6e506af3ac -r f71d57b75ee9 src/common.js
--- a/src/common.js     Wed Apr 13 19:07:40 2022 +0200
+++ b/src/common.js     Thu Apr 14 10:21:53 2022 +0200
@@ -2574,12 +2574,19 @@
                 return this.simplify_nested(domain[0]);
             } else {
                 var simplified = [];
-                var domain_op = this._bool_operator(domain);
                 for (var branch of domain) {
                     var simplified_branch = this.simplify_nested(branch);
-                    if ((this._bool_operator(branch) == domain_op) ||
-                        (simplified_branch.length == 1)) {
-                        simplified.push(...simplified_branch);
+                    if ((this._bool_operator(simplified_branch) ==
+                                this._bool_operator(simplified)) ||
+                            (simplified_branch.length == 1)) {
+                        if ((simplified.length > 0) &&
+                            (simplified_branch.length > 0) &&
+                            ((simplified_branch[0] == 'AND') ||
+                                (simplified_branch[0] == 'OR'))) {
+                            simplified.push(...simplified_branch.slice(1));
+                        } else {
+                            simplified.push(...simplified_branch);
+                        }
                     } else {
                         simplified.push(simplified_branch);
                     }
diff -r ad6e506af3ac -r f71d57b75ee9 tests/sao.js
--- a/tests/sao.js      Wed Apr 13 19:07:40 2022 +0200
+++ b/tests/sao.js      Thu Apr 14 10:21:53 2022 +0200
@@ -2612,6 +2612,9 @@
             [
                 ['OR', ['x', '=', 3], ['AND', ['y', '=', 5]]],
                 ['OR', ['x', '=', 3], ['y', '=', 5]]],
+            [
+                ['OR', ['x', '=', 1], ['OR', ['x', '=', 2], ['x', '=', 3]]],
+                ['OR', ['x', '=', 1], ['x', '=', 2], ['x', '=', 3]]],
             [[['x', '=', 3], ['OR']], [['x', '=', 3]]],
             [['OR', ['x', '=', 3], []], []],
             [['OR', ['x', '=', 3], ['OR']], []],

Reply via email to