From f8b3503be8e801d483d6c005ae9d7a5b20b4305f Mon Sep 17 00:00:00 2001 From: Jared Kipe Date: Mon, 15 Apr 2019 09:46:46 -0700 Subject: [PATCH 1/4] Initial commit of `web_date_warning` for 11.0 --- web_date_warning/README.md | 21 +++++++++ web_date_warning/__init__.py | 0 web_date_warning/__manifest__.py | 41 ++++++++++++++++++ .../static/src/js/date_picker_warning.js | 43 +++++++++++++++++++ web_date_warning/views/web_views.xml | 8 ++++ 5 files changed, 113 insertions(+) create mode 100644 web_date_warning/README.md create mode 100644 web_date_warning/__init__.py create mode 100644 web_date_warning/__manifest__.py create mode 100644 web_date_warning/static/src/js/date_picker_warning.js create mode 100644 web_date_warning/views/web_views.xml diff --git a/web_date_warning/README.md b/web_date_warning/README.md new file mode 100644 index 00000000..14d7a2f3 --- /dev/null +++ b/web_date_warning/README.md @@ -0,0 +1,21 @@ +**Web Date Warning** + +Provides warnings for date field entries that fall outside of a user-specified range, with the goal of reducing data entry errors. +- For any date or date/time picker, set the threshold that should trigger the warning +- Allows you to set a threshold for past, future or both +- In addition to displaying warning text, will also display how many days in the past or future the selected date is +On a record with the date or date/time picket you wish to add the warning to, edit the form view and create an inherited view. Target the field name and include the following details: + + +`widget="date-warn"` if the field is a date picker + +`widget="datetime-warn"` if the field is a date/time picker + +`options="{'warn_future': 90}"` to set a threshold for future dates where 90 is the number of days + +And/or `options="{'warn_past': 30}"` to set a threshold for past dates where 30 is the number of days + + +Example: + +`` \ No newline at end of file diff --git a/web_date_warning/__init__.py b/web_date_warning/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/web_date_warning/__manifest__.py b/web_date_warning/__manifest__.py new file mode 100644 index 00000000..009c04e3 --- /dev/null +++ b/web_date_warning/__manifest__.py @@ -0,0 +1,41 @@ +{ + 'name': 'Web Date Warning', + 'version': '11.0.1.0.0', + 'author': 'Hibou Corp. ', + 'website': 'https://hibou.io/', + 'license': 'AGPL-3', + 'category': 'Tools', + 'complexity': 'expert', + 'description': """ +**Web Date Warning** + +Provides warnings for date field entries that fall outside of a user-specified range, with the goal of reducing data entry errors. +- For any date or date/time picker, set the threshold that should trigger the warning +- Allows you to set a threshold for past, future or both +- In addition to displaying warning text, will also display how many days in the past or future the selected date is +On a record with the date or date/time picket you wish to add the warning to, edit the form view and create an inherited view. Target the field name and include the following details: + + +`widget="date-warn"` if the field is a date picker + +`widget="datetime-warn"` if the field is a date/time picker + +`options="{'warn_future': 90}"` to set a threshold for future dates where 90 is the number of days + +And/or `options="{'warn_past': 30}"` to set a threshold for past dates where 30 is the number of days + + +Example: + +`` + """, + 'depends': [ + 'web', + ], + 'data': [ + 'views/web_views.xml', + ], + 'installable': True, + 'auto_install': False, + 'category': 'Hidden', +} diff --git a/web_date_warning/static/src/js/date_picker_warning.js b/web_date_warning/static/src/js/date_picker_warning.js new file mode 100644 index 00000000..71463e0e --- /dev/null +++ b/web_date_warning/static/src/js/date_picker_warning.js @@ -0,0 +1,43 @@ +odoo.define('web.datepicker.warn', function (require) { +"use strict"; + +var basicFields = require('web.basic_fields'); +var fieldRegistry = require('web.field_registry'); + +var _setValue = function(value) { + this._super.apply(this, value); + if (this.attrs.options.warn_future || this.options.warn_past) { + var now = moment(); + var val = moment(value); + var ms_diff = val - now; + var warning = false; + var days = Math.ceil(ms_diff / 1000 / (24 * 3600)); + if (days >= this.attrs.options.warn_future) { + warning = days + ' days in the future!'; + } else if (-days >= this.attrs.options.warn_past) { + warning = -days + ' days in the past!'; + } + if (!warning) { + this.$el.find('.o_date_warning').remove(); + } else { + if (this.$el.find('.o_date_warning').length) { + this.$el.find('.o_date_warning').text(warning); + } else { + this.$el.append('

' + warning + '

'); + } + } + } +} + +var FieldDateWarn = basicFields.FieldDate.extend({ + _setValue: _setValue, +}); + +var FieldDateTimeWarn = basicFields.FieldDateTime.extend({ + _setValue: _setValue, +}); + +fieldRegistry.add('date-warn', FieldDateWarn); +fieldRegistry.add('datetime-warn', FieldDateTimeWarn); + +}); diff --git a/web_date_warning/views/web_views.xml b/web_date_warning/views/web_views.xml new file mode 100644 index 00000000..eda7d563 --- /dev/null +++ b/web_date_warning/views/web_views.xml @@ -0,0 +1,8 @@ + + + + \ No newline at end of file From 4761eb8a60dd3b0427cb4408943afbc1cc9e2092 Mon Sep 17 00:00:00 2001 From: Jared Kipe Date: Mon, 15 Apr 2019 10:08:35 -0700 Subject: [PATCH 2/4] IMP `web_date_warning` README style --- web_date_warning/README.md | 12 +++++++----- web_date_warning/__manifest__.py | 12 +++++++----- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/web_date_warning/README.md b/web_date_warning/README.md index 14d7a2f3..f8878434 100644 --- a/web_date_warning/README.md +++ b/web_date_warning/README.md @@ -1,9 +1,11 @@ -**Web Date Warning** +#Web Date Warning Provides warnings for date field entries that fall outside of a user-specified range, with the goal of reducing data entry errors. -- For any date or date/time picker, set the threshold that should trigger the warning -- Allows you to set a threshold for past, future or both -- In addition to displaying warning text, will also display how many days in the past or future the selected date is + +* For any date or date/time picker, set the threshold that should trigger the warning +* Allows you to set a threshold for past, future or both +* In addition to displaying warning text, will also display how many days in the past or future the selected date is + On a record with the date or date/time picket you wish to add the warning to, edit the form view and create an inherited view. Target the field name and include the following details: @@ -16,6 +18,6 @@ On a record with the date or date/time picket you wish to add the warning to, ed And/or `options="{'warn_past': 30}"` to set a threshold for past dates where 30 is the number of days -Example: +**Example:** `` \ No newline at end of file diff --git a/web_date_warning/__manifest__.py b/web_date_warning/__manifest__.py index 009c04e3..fc16dbd1 100644 --- a/web_date_warning/__manifest__.py +++ b/web_date_warning/__manifest__.py @@ -7,12 +7,14 @@ 'category': 'Tools', 'complexity': 'expert', 'description': """ -**Web Date Warning** +#Web Date Warning Provides warnings for date field entries that fall outside of a user-specified range, with the goal of reducing data entry errors. -- For any date or date/time picker, set the threshold that should trigger the warning -- Allows you to set a threshold for past, future or both -- In addition to displaying warning text, will also display how many days in the past or future the selected date is + +* For any date or date/time picker, set the threshold that should trigger the warning +* Allows you to set a threshold for past, future or both +* In addition to displaying warning text, will also display how many days in the past or future the selected date is + On a record with the date or date/time picket you wish to add the warning to, edit the form view and create an inherited view. Target the field name and include the following details: @@ -25,7 +27,7 @@ On a record with the date or date/time picket you wish to add the warning to, ed And/or `options="{'warn_past': 30}"` to set a threshold for past dates where 30 is the number of days -Example: +**Example:** `` """, From 845e0504fc1bc25859e1bafbe475a2913f634743 Mon Sep 17 00:00:00 2001 From: Kaylie Kipe Date: Mon, 29 Apr 2019 13:21:30 -0700 Subject: [PATCH 3/4] FIX `web_date_warning` Sending value to parent field. --- web_date_warning/static/src/js/date_picker_warning.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web_date_warning/static/src/js/date_picker_warning.js b/web_date_warning/static/src/js/date_picker_warning.js index 71463e0e..7059a1b2 100644 --- a/web_date_warning/static/src/js/date_picker_warning.js +++ b/web_date_warning/static/src/js/date_picker_warning.js @@ -5,8 +5,8 @@ var basicFields = require('web.basic_fields'); var fieldRegistry = require('web.field_registry'); var _setValue = function(value) { - this._super.apply(this, value); - if (this.attrs.options.warn_future || this.options.warn_past) { + this._super(value); + if (this.attrs.options.warn_future || this.attrs.options.warn_past) { var now = moment(); var val = moment(value); var ms_diff = val - now; From 13f2c20a626812418d5df80eb93caaa9dfc61da1 Mon Sep 17 00:00:00 2001 From: Jared Kipe Date: Mon, 20 May 2019 11:49:26 -0700 Subject: [PATCH 4/4] MIG `web_date_warning` to 12.0 --- web_date_warning/__manifest__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web_date_warning/__manifest__.py b/web_date_warning/__manifest__.py index fc16dbd1..88ec8f07 100644 --- a/web_date_warning/__manifest__.py +++ b/web_date_warning/__manifest__.py @@ -1,6 +1,6 @@ { 'name': 'Web Date Warning', - 'version': '11.0.1.0.0', + 'version': '12.0.1.0.0', 'author': 'Hibou Corp. ', 'website': 'https://hibou.io/', 'license': 'AGPL-3',