[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
This commit is contained in:
Nicolas Lempereur
2018-09-06 13:14:42 +02:00
parent 1d0940d96f
commit 72f76caa39
2 changed files with 14 additions and 4 deletions
+6 -4
View File
@@ -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;
},
+8
View File
@@ -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) {