diff --git a/web_search_datetime_completion/README.rst b/web_search_datetime_completion/README.rst new file mode 100644 index 00000000..0e149b1c --- /dev/null +++ b/web_search_datetime_completion/README.rst @@ -0,0 +1,57 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License: AGPL-3 +More completion options for datetime fields +=========================================== + +This module was written to extend the offers shown to the user when starting to fill in a date. In standard odoo, the only offer is the date at 00:00:00 hours, while it can be convenient for the user to have other options, too. When searching for the end of a period, ``23:59:59`` would come to mind, and there also might be domain specific times that make sense. + +Configuration +============= + +If you do nothing, only the time ``23:59:59`` is added to the completion dropdown. + +In your code, you can add an options dictionary with a key ``completion_options`` which contains a list if dictionaries detailing the offsets that should be added to the parsed date, like:: + + + +which would offer to search for the date at half past twelve. Note that when you set ``completion_options``, you have to list all options you want to see, as the standard options will be replaced with your list. + +Usage +===== + +Start filling in your date in a search field and choose one of the additional options offered. + +For further information, please visit: + +* https://www.odoo.com/forum/help-1 + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us smashing it by providing a detailed and welcomed feedback +`here `_. + +Credits +======= + +Contributors +------------ + +* Holger Brunn + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/web_search_datetime_completion/__init__.py b/web_search_datetime_completion/__init__.py new file mode 100644 index 00000000..faef9dac --- /dev/null +++ b/web_search_datetime_completion/__init__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2015 Therp BV . +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## diff --git a/web_search_datetime_completion/__openerp__.py b/web_search_datetime_completion/__openerp__.py new file mode 100644 index 00000000..0782ac86 --- /dev/null +++ b/web_search_datetime_completion/__openerp__.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2015 Therp BV . +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +{ + "name": "More completion options for datetime fields", + "version": "8.0.1.0.0", + "author": "Therp BV,Odoo Community Association (OCA)", + "license": "AGPL-3", + "category": "Usability", + "summary": "Offer more completion options for datetime fields while " + "searching", + "depends": [ + 'web', + ], + "data": [ + 'views/templates.xml', + ], + "auto_install": False, + "installable": True, + "application": False, + "external_dependencies": { + 'python': [], + }, +} diff --git a/web_search_datetime_completion/static/description/icon.png b/web_search_datetime_completion/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/web_search_datetime_completion/static/description/icon.png differ diff --git a/web_search_datetime_completion/static/src/js/web_search_datetime_completion.js b/web_search_datetime_completion/static/src/js/web_search_datetime_completion.js new file mode 100644 index 00000000..9a07bbe3 --- /dev/null +++ b/web_search_datetime_completion/static/src/js/web_search_datetime_completion.js @@ -0,0 +1,83 @@ +//-*- coding: utf-8 -*- +//############################################################################ +// +// OpenERP, Open Source Management Solution +// This module copyright (C) 2015 Therp BV . +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// +//############################################################################ + +openerp.web_search_datetime_completion = function(instance) +{ + instance.web.search.DateTimeField.include({ + init: function(view_section, field, parent) + { + this.options = instance.web.py_eval( + view_section.attrs.options || '{}'); + return this._super.apply(this, arguments); + }, + complete: function(needle) + { + var self = this; + return this._super.apply(this, arguments).then(function(options) + { + if(!options) + { + return options; + } + var parsed_date = options[0].facet.values[0].value, + completion_options = self.options.completion_options || [{ + hours: 23, minutes: 59, seconds: 59, + }]; + if(self.options.completion_options) + { + options = [] + } + _.each(completion_options, function(offset) + { + var date = parsed_date.clone(), + date_string = ''; + date.setHours( + offset.hours || date.getHours(), + offset.minutes || date.getMinutes(), + offset.seconds || date.getSeconds()); + date_string = instance.web.format_value( + date, self.attrs); + options.push({ + label: _.str.sprintf(_.str.escapeHTML( + instance.web._t("Search %(field)s at: %(value)s")), + { + field: _.str.sprintf( + '%s', + _.escape(self.attrs.string)), + value: _.str.sprintf( + '%s', + _.escape(date_string)), + }), + facet: { + category: self.attrs.string, + field: self, + values: [{ + label: date_string, + value: date, + }], + }, + }); + }); + return options; + }); + }, + }) +} diff --git a/web_search_datetime_completion/views/templates.xml b/web_search_datetime_completion/views/templates.xml new file mode 100644 index 00000000..87cff597 --- /dev/null +++ b/web_search_datetime_completion/views/templates.xml @@ -0,0 +1,10 @@ + + + + + +