[IMP] web: Add option on 'Datepicker' to warn when setting date in the future

Purpose
=======

There's no generic way to display a warning message if the user tries to set
a date in the future.

Specification
=============

Add this new feature on the datepicker (in web module), and use it account. For
example for the invoice date on the invoice/vendor bills form view.

TaskID: 1868221
This commit is contained in:
Nicolas Bayet
2018-08-13 14:36:36 +02:00
committed by Yannick Tivisse
parent cb1aa9c596
commit c410b7b4e7
4 changed files with 33 additions and 3 deletions
@@ -294,7 +294,7 @@
<group>
<field name="origin" attrs="{'invisible': [('origin', '=', False)]}"/>
<field name="source_email" widget="email" groups="base.group_no_one" attrs="{'invisible': [('source_email', '=', False)]}"/>
<field name="date_invoice" string="Bill Date"/>
<field name="date_invoice" string="Bill Date" options="{'datepicker': {'warn_future': true}}"/>
<field name="date_due" attrs="{'readonly': ['|',('payment_term_id','!=',False), ('state', 'in', ['open', 'paid'])]}" force_save="1"/>
<field name="move_name" invisible="1"/>
<field name="currency_id" options="{'no_create': True, 'no_open': True}" groups="base.group_multi_currency"/>
@@ -442,7 +442,7 @@
<field name="cash_rounding_id" groups="account.group_cash_rounding"/>
</group>
<group>
<field name="date_invoice"/>
<field name="date_invoice" options="{'datepicker': {'warn_future': true}}"/>
<field name="date_due" attrs="{'readonly': ['|',('payment_term_id','!=',False), ('state', 'in', ['open', 'paid'])]}" force_save="1"/>
<field name="move_name" invisible="1"/>
<field name="user_id" groups="base.group_user"/>
+1 -1
View File
@@ -670,7 +670,7 @@
<field name="cashbox_start_id" invisible="1"/>
<field name="cashbox_end_id" invisible="1"/>
<field name="journal_id" domain="[('type', '=', journal_type)]" attrs="{'readonly': [('move_line_count','!=', 0)]}" widget="selection"/>
<field name="date"/>
<field name="date" options="{'datepicker': {'warn_future': true}}" />
<field name="accounting_date" groups="base.group_no_one"/>
<field name='company_id' options="{'no_create': True}" groups="base.group_multi_company" />
<field name="currency_id" invisible="1"/>
@@ -1,10 +1,13 @@
odoo.define('web.datepicker', function (require) {
"use strict";
var core = require('web.core');
var field_utils = require('web.field_utils');
var time = require('web.time');
var Widget = require('web.Widget');
var _t = core._t;
var DateWidget = Widget.extend({
template: "web.datepicker",
type_of_date: "date",
@@ -95,6 +98,9 @@ var DateWidget = Widget.extend({
if (hasChanged) {
// The condition is strangely written; this is because the
// values can be false/undefined
if (this.options.warn_future) {
this._warnFuture(newValue);
}
this.trigger("datetime_changed");
}
}
@@ -138,6 +144,25 @@ var DateWidget = Widget.extend({
// Private
//--------------------------------------------------------------------------
/**
* add a warning to communicate that a date in the future has been set
*
* @private
* @param {Moment} currentDate
*/
_warnFuture: function(currentDate) {
if (!this.$warning) {
this.$warning = $('<span class="fa fa-exclamation-triangle o_tz_warning o_datepicker_warning"/>')
this.$warning.attr('title', _t("This date is on the future. Make sure it is what you expected."))
this.$input.after(this.$warning)
}
if (currentDate.isAfter(moment())) {
this.$warning.show()
} else {
this.$warning.hide()
}
},
/**
* @private
* @param {Moment} v
@@ -25,6 +25,11 @@
@include o-caret-down;
}
}
.o_datepicker_warning {
top: 0;
right: 20px;
}
}