[FIX] web: can't edit subscription with end date beyond 200 years in the future

-Import a subscription with end date beyond 200 in the future (ex: 2500-01-01).
-Open the subscription and click the Edit button.

Before this commit:

A stacktrace appears indicating that a date is not valid. It's not possible to
edit the subscription.

After this commit:

The maxDate of the date picker has been increased to 31/12/9999, allowing the
user to edit subscriptions whose end date is that far in the future.

A test `toggle datepicker far in the future` for this case has been created.

closes odoo/odoo#38527

Opw: 2079696
X-original-commit: 32b6131c04fef7a542a0ccbdb924d177627bfe38
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
This commit is contained in:
fw-bot
2019-10-11 16:12:34 +00:00
parent 86ae57b479
commit bc4b7c5036
3 changed files with 42 additions and 2 deletions
@@ -31,7 +31,7 @@ var DateWidget = Widget.extend({
locale: moment.locale(),
format : this.type_of_date === 'datetime' ? time.getLangDatetimeFormat() : time.getLangDateFormat(),
minDate: moment({ y: 1900 }),
maxDate: moment().add(200, "y"),
maxDate: moment({ y: 9999, M: 11, d: 31 }),
useCurrent: false,
icons: {
time: 'fa fa-clock-o',
@@ -2996,6 +2996,46 @@ QUnit.module('basic_fields', {
form.destroy();
});
QUnit.test('date field: toggle datepicker far in the future', async function (assert) {
assert.expect(3);
this.data.partner.records = [{
id: 1,
date: "9999-12-30",
foo: "yop",
}]
var form = await createView({
View: FormView,
model: 'partner',
data: this.data,
arch:'<form><field name="foo"/><field name="date"/></form>',
translateParameters: { // Avoid issues due to localization formats
date_format: '%m/%d/%Y',
},
res_id: 1,
viewOptions: {
mode: 'edit',
},
});
assert.strictEqual($('.bootstrap-datetimepicker-widget:visible').length, 0,
"datepicker should be closed initially");
testUtils.openDatepicker(form.$('.o_datepicker'));
assert.strictEqual($('.bootstrap-datetimepicker-widget:visible').length, 1,
"datepicker should be opened");
// focus another field
form.$('.o_field_widget[name=foo]').click().focus();
assert.strictEqual($('.bootstrap-datetimepicker-widget:visible').length, 0,
"datepicker should close itself when the user clicks outside");
form.destroy();
});
QUnit.test('date field is empty if no date is set', async function (assert) {
assert.expect(2);
@@ -33,7 +33,7 @@ odoo.define('website_form.animation', function (require) {
var l10n = _t.database.parameters;
var datepickers_options = {
minDate: moment({ y: 1900 }),
maxDate: moment().add(200, "y"),
maxDate: moment({ y: 9999, M: 11, d: 31 }),
calendarWeeks: true,
icons : {
time: 'fa fa-clock-o',