diff --git a/web_tree_date_search/README.rst b/web_tree_date_search/README.rst new file mode 100644 index 00000000..4565096c --- /dev/null +++ b/web_tree_date_search/README.rst @@ -0,0 +1,40 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :alt: License + +Tree Date Search +============================== + +This module allow you to easily add dates range search fields on top of List View rows. + +These dates fields can be used in combination with the Search window. + +How to do ? + +Add a new 'dates_filter' key and a list of fields name in the action context: +{'dates_filter': ['start']} +or several dates: +{'dates_filter': ['start','stop',..]} + +.. image:: web_tree_date_search/static/src/img/demo.png +.. image:: web_tree_date_search/static/src/img/demo1.png + +Credits +======= + +Author +------ +* Thomas Fossoul, Noviat + +Maintainer +---------- +.. image:: http://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: http://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 http://odoo-community.org. diff --git a/web_tree_date_search/__init__.py b/web_tree_date_search/__init__.py new file mode 100644 index 00000000..4cace334 --- /dev/null +++ b/web_tree_date_search/__init__.py @@ -0,0 +1,18 @@ +############################################################################## +# +# Copyright (c) 2015 Noviat nv/sa (www.noviat.com) +# +# 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_tree_date_search/__openerp__.py b/web_tree_date_search/__openerp__.py new file mode 100644 index 00000000..1d31645f --- /dev/null +++ b/web_tree_date_search/__openerp__.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Copyright (c) 2015 Noviat nv/sa (www.noviat.com) +# +# 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': 'Tree dates search', + 'version': '8.0.3.0.1', + 'author': 'Noviat, Odoo Community Association (OCA)', + 'website': 'http://www.noviat.com', + 'license': 'AGPL-3', + 'category': 'Web', + 'depends': [ + 'web', + ], + 'data': [ + 'views/assets_backend.xml', + ], + 'qweb': [ + 'static/src/xml/*.xml', + ], + 'demo': [ + 'demo/demo.xml', + ], + 'installable': True, +} diff --git a/web_tree_date_search/demo/demo.xml b/web_tree_date_search/demo/demo.xml new file mode 100644 index 00000000..ca8a540a --- /dev/null +++ b/web_tree_date_search/demo/demo.xml @@ -0,0 +1,11 @@ + + + + + + res.users + {'dates_filter' : ['login_date']} + + + + diff --git a/web_tree_date_search/i18n/fr.po b/web_tree_date_search/i18n/fr.po new file mode 100644 index 00000000..da12ee98 --- /dev/null +++ b/web_tree_date_search/i18n/fr.po @@ -0,0 +1,31 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * tree_date_search_extension +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0-20150601\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-06-16 15:10+0000\n" +"PO-Revision-Date: 2015-06-16 15:10+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: tree_date_search_extension +#. openerp-web +#: code:addons/tree_date_search_extension/static/src/js/search_extension.js:72 +#, python-format +msgid "From" +msgstr "De" + +#. module: tree_date_search_extension +#. openerp-web +#: code:addons/tree_date_search_extension/static/src/js/search_extension.js:74 +#, python-format +msgid "To" +msgstr "à" + diff --git a/web_tree_date_search/i18n/nl.po b/web_tree_date_search/i18n/nl.po new file mode 100644 index 00000000..5dd113b2 --- /dev/null +++ b/web_tree_date_search/i18n/nl.po @@ -0,0 +1,31 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * tree_date_search_extension +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0-20150601\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2015-06-16 15:10+0000\n" +"PO-Revision-Date: 2015-06-16 15:10+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: tree_date_search_extension +#. openerp-web +#: code:addons/tree_date_search_extension/static/src/js/search_extension.js:72 +#, python-format +msgid "From" +msgstr "Van" + +#. module: tree_date_search_extension +#. openerp-web +#: code:addons/tree_date_search_extension/static/src/js/search_extension.js:74 +#, python-format +msgid "To" +msgstr "Tot" + diff --git a/web_tree_date_search/static/src/img/demo.png b/web_tree_date_search/static/src/img/demo.png new file mode 100755 index 00000000..d4014765 Binary files /dev/null and b/web_tree_date_search/static/src/img/demo.png differ diff --git a/web_tree_date_search/static/src/img/demo1.png b/web_tree_date_search/static/src/img/demo1.png new file mode 100644 index 00000000..5ab2e402 Binary files /dev/null and b/web_tree_date_search/static/src/img/demo1.png differ diff --git a/web_tree_date_search/static/src/js/search.js b/web_tree_date_search/static/src/js/search.js new file mode 100644 index 00000000..55157905 --- /dev/null +++ b/web_tree_date_search/static/src/js/search.js @@ -0,0 +1,178 @@ +// @@@ web_tree_date_search custom JS @@@ +// ############################################################################# +// +// Copyright (c) 2015 Noviat nv/sa (www.noviat.com) +// +// 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_tree_date_search = function(instance) { + var _t = instance.web._t, + _lt = instance.web._lt; + var QWeb = instance.web.qweb; + + instance.web.ListView.include({ + init: function(parent, dataset, view_id, options) { + this._super.apply(this, arguments); + if ("dates_filter" in dataset.context){ + this.dates_filter = dataset.context["dates_filter"]; + this.current_date_from = []; + this.current_date_to = []; + } + this.tree_date_search_loaded = false; + }, + do_load_state: function(state, warm) { + var ui_toolbar_loc = $('.ui-toolbar:last'); + if (this.dates_filter && this.dates_filter.length > 0){ + ui_toolbar_loc.show(); + } + else{ + if (ui_toolbar_loc.children().length == 0) + ui_toolbar_loc.hide(); + } + return this._super.apply(this, arguments); + }, + load_list: function(data) { + var self = this; + var tmp = this._super.apply(this, arguments); + if (!this.tree_date_search_loaded){ + this.date_field_data = []; + for (i in this.dates_filter){ + var date_field = this.dates_filter[i]; + for (col in this.columns){ + if (this.columns[col].name == date_field){ + this.date_field_data[date_field] = [] + this.date_field_data[date_field][0] = this.columns[col].string; + this.date_field_data[date_field][1] = this.columns[col].type; + break; + } + } + } + if (this.dates_filter && this.dates_filter.length > 0){ + this.$el.parent().prepend(QWeb.render('TreeDateSearch', {widget: this})); + var ui_toolbar_loc = $('.ui-toolbar:last'); + ui_toolbar_loc.show(); + for (i in this.dates_filter){ + var date_field = this.dates_filter[i]; + var date_string = this.date_field_data[date_field][0] + var date_type = this.date_field_data[date_field][1] + + self.columns + var date_div = QWeb.render('TreeDateSearchField', {'field_name': date_string}); + var toolbar_height = ui_toolbar_loc.height(); + + ui_toolbar_loc.append(date_div); + $('div.oe_form_dropdown_section:last span:eq(0)').addClass('oe_date_filter_from_' + date_field); + $('div.oe_form_dropdown_section:last span:eq(1)').addClass('oe_date_filter_to_' + date_field); + + this.value = new (instance.web.search.custom_filters.get_object(date_type)) + (this, {"selectable":true, + "name":"oe_date_filter_from_" + date_field, + "type": date_type, + "string":date_string}); + var value_loc = $('.oe_date_filter_from_' + date_field + ':last').show().empty(); + this.value.appendTo(value_loc); + + this.value = new (instance.web.search.custom_filters.get_object(date_type)) + (this, {"selectable":true, + "name":"oe_date_filter_to_" + date_field, + "type": date_type, + "string":date_string}); + var value_loc = $('.oe_date_filter_to_' + date_field + ':last').show().empty(); + this.value.appendTo(value_loc); + + var oe_date_filter_from = $('.oe_date_filter_from_' + date_field + ':last .oe_datepicker_master'); + var oe_date_filter_to = $('.oe_date_filter_to_' + date_field + ':last .oe_datepicker_master'); + if (date_type == 'date'){ + oe_date_filter_from.css("width", "105px"); + oe_date_filter_to.css("width", "105px"); + } + oe_date_filter_from.css("height", "23px"); + oe_date_filter_to.css("height", "23px"); + // In 2 line to fit with account move line tree view + if (toolbar_height < 40){ + var $elem1 = oe_date_filter_from.parent().parent().parent().parent().parent(); + var $elem = $elem1.find("h4"); + $elem.css("display", "inline"); + } + oe_date_filter_from.attr("placeholder", _t("From")); + oe_date_filter_to.attr("placeholder", _t("To")); + + // on_change + oe_date_filter_from.change(function() { + var elem = this.parentElement.parentElement.parentElement.className; + var res = elem.split("oe_date_filter_from_"); + self.current_date_from[res[1]] = this.value === '' ? null : this.value; + if (self.current_date_from[res[1]]){ + self.current_date_from[res[1]] = instance.web.parse_value( + self.current_date_from[res[1]], {"widget": date_type}); + } + self.do_search(self.last_domain, self.last_context, self.last_group_by); + }); + oe_date_filter_to.change(function() { + var elem = this.parentElement.parentElement.parentElement.className; + var res = elem.split("oe_date_filter_to_"); + self.current_date_to[res[1]] = this.value === '' ? null : this.value; + if (self.current_date_to[res[1]]){ + self.current_date_to[res[1]] = instance.web.parse_value( + self.current_date_to[res[1]], {"widget": date_type}); + } + self.do_search(self.last_domain, self.last_context, self.last_group_by); + }); + this.on('edit:after', this, function () { + oe_date_filter_from.attr('disabled', 'disabled'); + oe_date_filter_to.attr('disabled', 'disabled'); + }); + this.on('save:after cancel:after', this, function () { + oe_date_filter_from.removeAttr('disabled'); + oe_date_filter_to.removeAttr('disabled'); + }); + } + } + else{ + // Only hide current if it's empty + // Work from tree view to tree view with or withouth date_filters + // Work from tree view to wizard with or withouth date_filters + var ui_toolbar_loc = $('.ui-toolbar:last'); + if (ui_toolbar_loc.children().length == 0) + ui_toolbar_loc.hide(); + } + this.tree_date_search_loaded = true; + } + return tmp; + }, + do_search: function(domain, context, group_by) { + this.last_domain = domain; + this.last_context = context; + this.last_group_by = group_by; + domain = this.get_dates_filter_domain(domain); + return this._super(domain, context, group_by); + }, + get_dates_filter_domain: function(last_domain) { + var domain = []; + for (from in this.current_date_from){ + if (this.current_date_from[from]) + domain.push([from, '>=', this.current_date_from[from]]); + } + for (to in this.current_date_to){ + if (this.current_date_to[to]) + domain.push([to, '<=', this.current_date_to[to]]); + } + return new instance.web.CompoundDomain(last_domain, domain); + }, + }); + +}; diff --git a/web_tree_date_search/static/src/xml/search.xml b/web_tree_date_search/static/src/xml/search.xml new file mode 100644 index 00000000..6a34ebb3 --- /dev/null +++ b/web_tree_date_search/static/src/xml/search.xml @@ -0,0 +1,19 @@ + + + +
+
+
+ + +
+

:

+
+ +
+
+ +
+
+
+
diff --git a/web_tree_date_search/views/assets_backend.xml b/web_tree_date_search/views/assets_backend.xml new file mode 100644 index 00000000..c562953b --- /dev/null +++ b/web_tree_date_search/views/assets_backend.xml @@ -0,0 +1,10 @@ + + + + + +