summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Lempereur <nle@odoo.com>2018-09-06 10:29:21 +0200
committerNicolas Lempereur <nle@odoo.com>2018-09-06 13:14:42 +0200
commit72f76caa39ff33bbae6f37ee35ae071570b40877 (patch)
tree2e2431b4a76296c251ce10cedc7f4cd76acab106
parent1d0940d96f3f5de45b38a9ddad9af65087dd04f3 (diff)
[FIX] web: relativedelta>11months work as expected
Since march 2015, using in a domain "relativedelta(months=X)" with X being bigger than 11 or lower than -11 would result in an error. This is because in the refactoring adding modules (e8a00bc50d) the two functions divmod and utils.divmod with different implementation in pyeval.js were replaced by one function divmod in web.utils module. But there was still an usage of the removed implementation. opw-1880766 closes #26816
-rw-r--r--addons/web/static/src/js/framework/pyeval.js10
-rw-r--r--addons/web/static/test/evals.js8
2 files changed, 14 insertions, 4 deletions
diff --git a/addons/web/static/src/js/framework/pyeval.js b/addons/web/static/src/js/framework/pyeval.js
index bcab0b0717f..ea24ac87ecc 100644
--- a/addons/web/static/src/js/framework/pyeval.js
+++ b/addons/web/static/src/js/framework/pyeval.js
@@ -627,13 +627,15 @@ var relativedelta = py.type('relativedelta', null, {
this._fix();
},
_fix: function () {
+ var self = this;
var months = asJS(this.ops.months);
if (Math.abs(months) > 11) {
var s = months > 0 ? 1 : -1;
- var r = utils.divmod(months * s, 12);
- this.ops.months = py.float.fromJSON(r.mod*s);
- this.ops.years = py.float.fromJSON(
- asJS(this.ops.years) + r.div*s);
+ utils.divmod(months * s, 12, function (years, months) {
+ self.ops.months = py.float.fromJSON(months*s);
+ self.ops.years = py.float.fromJSON(
+ asJS(self.ops.years) + years*s);
+ });
}
this._has_time = 0;
},
diff --git a/addons/web/static/test/evals.js b/addons/web/static/test/evals.js
index b6a3b4177e8..1fbf6523bac 100644
--- a/addons/web/static/test/evals.js
+++ b/addons/web/static/test/evals.js
@@ -300,6 +300,14 @@ odoo.define_section('eval.types', ['web.pyeval'], function (test, mock) {
py.eval("(datetime.date(2015,2,5)+relativedelta(days=-6,weekday=0)).strftime('%Y-%m-%d')",
pyeval.context()),
'2015-02-02');
+ strictEqual(
+ py.eval("(datetime.date(2018, 2, 1) + relativedelta(years=7, months=42, days=42)).strftime('%Y-%m-%d')",
+ pyeval.context()),
+ '2028-09-12');
+ strictEqual(
+ py.eval("(datetime.date(2018, 2, 1) + relativedelta(years=-7, months=-42, days=-42)).strftime('%Y-%m-%d')",
+ pyeval.context()),
+ '2007-06-20');
});
test('datetime.tojson', function (assert, pyeval) {