mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
Initial commit of web_date_warning for 11.0
This commit is contained in:
21
web_date_warning/README.md
Normal file
21
web_date_warning/README.md
Normal file
@@ -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:
|
||||
|
||||
`<field name="date_invoice" widget="date-warn" options="{'warn_future': 90, 'warn_past': 30}"/>`
|
||||
0
web_date_warning/__init__.py
Normal file
0
web_date_warning/__init__.py
Normal file
41
web_date_warning/__manifest__.py
Normal file
41
web_date_warning/__manifest__.py
Normal file
@@ -0,0 +1,41 @@
|
||||
{
|
||||
'name': 'Web Date Warning',
|
||||
'version': '11.0.1.0.0',
|
||||
'author': 'Hibou Corp. <hello@hibou.io>',
|
||||
'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:
|
||||
|
||||
`<field name="date_invoice" widget="date-warn" options="{'warn_future': 90, 'warn_past': 30}"/>`
|
||||
""",
|
||||
'depends': [
|
||||
'web',
|
||||
],
|
||||
'data': [
|
||||
'views/web_views.xml',
|
||||
],
|
||||
'installable': True,
|
||||
'auto_install': False,
|
||||
'category': 'Hidden',
|
||||
}
|
||||
43
web_date_warning/static/src/js/date_picker_warning.js
Normal file
43
web_date_warning/static/src/js/date_picker_warning.js
Normal file
@@ -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('<p class="o_date_warning text-danger">' + warning + '</p>');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var FieldDateWarn = basicFields.FieldDate.extend({
|
||||
_setValue: _setValue,
|
||||
});
|
||||
|
||||
var FieldDateTimeWarn = basicFields.FieldDateTime.extend({
|
||||
_setValue: _setValue,
|
||||
});
|
||||
|
||||
fieldRegistry.add('date-warn', FieldDateWarn);
|
||||
fieldRegistry.add('datetime-warn', FieldDateTimeWarn);
|
||||
|
||||
});
|
||||
8
web_date_warning/views/web_views.xml
Normal file
8
web_date_warning/views/web_views.xml
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<template id="assets_backend" name="ShipBox Assets and Fields" inherit_id="web.assets_backend" priority='15'>
|
||||
<xpath expr="//script[last()]" position="after">
|
||||
<script type="text/javascript" src="/web_date_warning/static/src/js/date_picker_warning.js"></script>
|
||||
</xpath>
|
||||
</template>
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user