[FIX] web: Make datetimepicker configurable in datetime fields

The datetimepicker option was introduced to be able to customize the
datetime picker widget in date/datetime fields. However, due to the way
the _makeDatePicker function was coded, it did not work in datetime
fields.

Thank to Yajo for the initial fix

closes odoo/odoo#27541
This commit is contained in:
svs-odoo
2018-10-09 12:34:23 +00:00
committed by Géry Debongnie
parent b732ab3dc9
commit 078b31dc7f
3 changed files with 45 additions and 11 deletions
+17 -10
View File
@@ -404,6 +404,10 @@ var FieldDate = InputField.extend({
this._super.apply(this, arguments);
// use the session timezone when formatting dates
this.formatOptions.timezone = true;
this.datepickerOptions = _.defaults(
this.nodeOptions.datepicker || {},
{defaultDate: this.value}
);
},
/**
* In edit mode, instantiates a DateWidget datepicker and listen to changes.
@@ -468,13 +472,7 @@ var FieldDate = InputField.extend({
* @private
*/
_makeDatePicker: function () {
return new datepicker.DateWidget(
this,
_.defaults(
this.nodeOptions.datepicker || {},
{defaultDate: this.value}
)
);
return new datepicker.DateWidget(this, this.datepickerOptions);
},
/**
@@ -492,6 +490,17 @@ var FieldDate = InputField.extend({
var FieldDateTime = FieldDate.extend({
supportedFieldTypes: ['datetime'],
/**
* @override
*/
init: function () {
this._super.apply(this, arguments);
if (this.value) {
var offset = this.getSession().getTZOffset(this.value);
var displayedValue = this.value.clone().add(offset, 'minutes');
this.datepickerOptions.defaultDate = displayedValue;
}
},
//--------------------------------------------------------------------------
// Private
//--------------------------------------------------------------------------
@@ -522,10 +531,8 @@ var FieldDateTime = FieldDate.extend({
* @private
*/
_makeDatePicker: function () {
var value = this.value && this.value.clone().add(this.getSession().getTZOffset(this.value), 'minutes');
return new datepicker.DateTimeWidget(this, {defaultDate: value});
return new datepicker.DateTimeWidget(this, this.datepickerOptions);
},
/**
* Set the datepicker to the right value rather than the default one.
*
@@ -2556,6 +2556,33 @@ QUnit.module('basic_fields', {
form.destroy();
});
QUnit.test('datepicker option: daysOfWeekDisabled', function (assert) {
assert.expect(2);
this.data.partner.fields.datetime.default = "2017-08-02 12:00:05";
this.data.partner.fields.datetime.required = true;
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch:'<form string="Partners">' +
'<field name="datetime" ' +
'options=\'{"datepicker": {"daysOfWeekDisabled": [0, 6]}}\'/>' +
'</form>',
res_id: 1,
});
form.$buttons.find('.o_form_button_create').click();
form.$('.o_datepicker_input.o_input').click();
assert.ok($('.day:last-child(),.day:nth-child(2)').hasClass('disabled'),
'first and last days must be disabled');
assert.notOk($('.day:not(:last-child()):not(:nth-child(2))').hasClass('disabled'),
'other days must stay clickable');
form.destroy();
});
QUnit.module('FieldMonetary');
QUnit.test('monetary field in form view', function (assert) {
+1 -1
View File
@@ -1348,7 +1348,7 @@ order.
.. code-block:: xml
<field name="datefield" options='{"datepicker": {"daysOfWeekDisabled": [0, 6]}}'/>
<field name="datetimefield" options='{"datepicker": {"daysOfWeekDisabled": [0, 6]}}'/>
- monetary (FieldMonetary)
This is the default field type for fields of type 'monetary'. It is used to