mirror of
https://github.com/OCA/web.git
synced 2025-02-22 13:21:25 +02:00
[8.0] [ADD] web_tree_date_search (#1056)
Co-authored-by: fossoult <thomas.fossoul@noviat.com>
This commit is contained in:
62
web_tree_date_search/README.rst
Normal file
62
web_tree_date_search/README.rst
Normal file
@@ -0,0 +1,62 @@
|
||||
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
|
||||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
|
||||
:alt: License: AGPL-3
|
||||
|
||||
=====================
|
||||
Tree View Date Search
|
||||
=====================
|
||||
|
||||
This module allow you to easily add date range search fields to tree views.
|
||||
These date fields can be used in combination with the Search window.
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
Add a new 'dates_filter' key and a list of field names in the action context:
|
||||
|
||||
.. code:: python
|
||||
|
||||
{'dates_filter': ['start']}
|
||||
|
||||
or several dates:
|
||||
|
||||
.. code:: python
|
||||
|
||||
{'dates_filter': ['start','stop',..]}
|
||||
|
||||
Bug Tracker
|
||||
===========
|
||||
|
||||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/web/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 <https://github.com/OCA/web/issues/new?body=module:%20 web_tree_date_search%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`__.
|
||||
|
||||
Credits
|
||||
=======
|
||||
|
||||
Images
|
||||
------
|
||||
|
||||
* PICOL Icon Generator `here <http://picol.org/picol_icon_generator>`__.
|
||||
|
||||
Contributors
|
||||
------------
|
||||
|
||||
* Tom Blauwendraat <tom@sunflowerweb.nl>
|
||||
* Thomas Fossoul, Noviat <thomas.fossoul@noviat.com>
|
||||
|
||||
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 http://odoo-community.org.
|
||||
1
web_tree_date_search/__init__.py
Normal file
1
web_tree_date_search/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
24
web_tree_date_search/__openerp__.py
Normal file
24
web_tree_date_search/__openerp__.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2015 Noviat nv/sa (http://www.noviat.com)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
{
|
||||
'name': 'Tree dates search',
|
||||
'version': '8.0.1.0.0',
|
||||
'author': 'Noviat, Odoo Community Association (OCA)',
|
||||
'website': 'https://github.com/OCA/web',
|
||||
'license': 'AGPL-3',
|
||||
'category': 'Web',
|
||||
'depends': [
|
||||
'web',
|
||||
],
|
||||
'data': [
|
||||
'views/assets_backend.xml',
|
||||
],
|
||||
'qweb': [
|
||||
'static/src/xml/web_tree_date_search.xml',
|
||||
],
|
||||
'demo': [
|
||||
'demo/demo.xml',
|
||||
],
|
||||
'installable': True,
|
||||
}
|
||||
11
web_tree_date_search/demo/demo.xml
Normal file
11
web_tree_date_search/demo/demo.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data noupdate="1">
|
||||
|
||||
<record id="base.action_res_users" model="ir.actions.act_window">
|
||||
<field name="res_model">res.users</field>
|
||||
<field name="context">{'dates_filter' : ['login_date']}</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
31
web_tree_date_search/i18n/fr.po
Normal file
31
web_tree_date_search/i18n/fr.po
Normal file
@@ -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 "à"
|
||||
|
||||
31
web_tree_date_search/i18n/nl.po
Normal file
31
web_tree_date_search/i18n/nl.po
Normal file
@@ -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"
|
||||
|
||||
BIN
web_tree_date_search/static/description/icon.png
Normal file
BIN
web_tree_date_search/static/description/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.9 KiB |
20
web_tree_date_search/static/src/css/web_tree_date_search.css
Normal file
20
web_tree_date_search/static/src/css/web_tree_date_search.css
Normal file
@@ -0,0 +1,20 @@
|
||||
div.web_tree_date_search_toolbar {
|
||||
margin-bottom:0px;
|
||||
}
|
||||
|
||||
div.web_tree_date_search_field {
|
||||
min-width: 208px; margin-left:4px;
|
||||
}
|
||||
|
||||
div.web_tree_date_search_field div.oe_form {
|
||||
margin-right:3px; display: inline;
|
||||
}
|
||||
|
||||
input.web_tree_date_search_input {
|
||||
height: 23px;
|
||||
}
|
||||
|
||||
input.web_tree_date_search_input_date {
|
||||
width: 105px;
|
||||
}
|
||||
|
||||
BIN
web_tree_date_search/static/src/img/demo.png
Executable file
BIN
web_tree_date_search/static/src/img/demo.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 65 KiB |
BIN
web_tree_date_search/static/src/img/demo1.png
Normal file
BIN
web_tree_date_search/static/src/img/demo1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 46 KiB |
196
web_tree_date_search/static/src/js/web_tree_date_search.js
Normal file
196
web_tree_date_search/static/src/js/web_tree_date_search.js
Normal file
@@ -0,0 +1,196 @@
|
||||
// Copyright (c) 2015 Noviat nv/sa (www.noviat.com)
|
||||
|
||||
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 ret = this._super.apply(this, arguments);
|
||||
|
||||
// dont run if already loaded
|
||||
if (this.tree_date_search_loaded)
|
||||
return ret;
|
||||
|
||||
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.columns[col].string,
|
||||
this.columns[col].type
|
||||
]
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var custom_filters = instance.web.search.custom_filters;
|
||||
var INPUT_SELECTOR = ' .oe_datepicker_master';
|
||||
if (this.dates_filter && this.dates_filter.length > 0) {
|
||||
this.$el.parent().prepend(QWeb.render(
|
||||
'web_tree_date_search_toolbar', {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];
|
||||
|
||||
// add search form to toolbar
|
||||
var date_div = QWeb.render('web_tree_date_search_field', {
|
||||
'field_name': date_string
|
||||
});
|
||||
var toolbar_height = ui_toolbar_loc.height();
|
||||
ui_toolbar_loc.append(date_div);
|
||||
|
||||
// assign classes to 'from' and 'to' spans
|
||||
var from_class = 'oe_date_filter_from_' + date_field,
|
||||
to_class = 'oe_date_filter_to_' + date_field,
|
||||
from_selector = '.' + from_class + ':last',
|
||||
to_selector = '.' + to_class + ':last',
|
||||
spans = $('div.oe_form_dropdown_section:last span');
|
||||
spans.eq(0).addClass(from_class);
|
||||
spans.eq(1).addClass(to_class);
|
||||
|
||||
// add date input elements to each
|
||||
function add_input_element(_class, selector) {
|
||||
var value = new (custom_filters.get_object(date_type))(
|
||||
this, {
|
||||
"selectable": true,
|
||||
"name": _class,
|
||||
"type": date_type,
|
||||
"string": date_string
|
||||
}
|
||||
);
|
||||
var value_loc = $(selector).show().empty();
|
||||
value.appendTo(value_loc);
|
||||
return value;
|
||||
}
|
||||
this.value = add_input_element(from_class, from_selector);
|
||||
this.value = add_input_element(to_class, to_selector);
|
||||
|
||||
// sizing of the input elements
|
||||
var input_from = $(from_selector + INPUT_SELECTOR);
|
||||
var input_to = $(to_selector + INPUT_SELECTOR);
|
||||
if (date_type == 'date') {
|
||||
input_from.addClass('web_tree_date_search_input_date');
|
||||
input_to.addClass('web_tree_date_search_input_date');
|
||||
}
|
||||
input_from.addClass('web_tree_date_search_input');
|
||||
input_to.addClass('web_tree_date_search_input');
|
||||
// In 2 line to fit with account move line tree view
|
||||
if (toolbar_height < 40) {
|
||||
var $elem1 = input_from.parent()
|
||||
.parent().parent().parent().parent();
|
||||
var $elem = $elem1.find("h4");
|
||||
$elem.css("display", "inline");
|
||||
}
|
||||
input_from.attr("placeholder", _t("From"));
|
||||
input_to.attr("placeholder", _t("To"));
|
||||
|
||||
// on_change functions
|
||||
input_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
|
||||
);
|
||||
});
|
||||
input_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() {
|
||||
input_from.attr('disabled', 'disabled');
|
||||
input_to.attr('disabled', 'disabled');
|
||||
});
|
||||
this.on('save:after cancel:after', this, function() {
|
||||
input_from.removeAttr('disabled');
|
||||
input_to.removeAttr('disabled');
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Only hide current if it's empty
|
||||
// Work from tree view to tree view with or without date_filters
|
||||
// Work from tree view to wizard with or without 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 ret;
|
||||
},
|
||||
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);
|
||||
},
|
||||
});
|
||||
|
||||
};
|
||||
19
web_tree_date_search/static/src/xml/web_tree_date_search.xml
Normal file
19
web_tree_date_search/static/src/xml/web_tree_date_search.xml
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates id="template" xml:space="preserve">
|
||||
<t t-name="web_tree_date_search_toolbar">
|
||||
<div class="ui-toolbar web_tree_date_search_toolbar" style="margin-bottom:0px;">
|
||||
</div>
|
||||
</t>
|
||||
|
||||
<t t-name="web_tree_date_search_field">
|
||||
<div class="oe_form_dropdown_section web_tree_date_search_field">
|
||||
<h4><t t-esc="field_name"/> :</h4>
|
||||
<div class="oe_form">
|
||||
<span/>
|
||||
</div>
|
||||
<div class="oe_form oe_right">
|
||||
<span/>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
</templates>
|
||||
12
web_tree_date_search/views/assets_backend.xml
Normal file
12
web_tree_date_search/views/assets_backend.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<template id="assets_backend" name="search_assets_backends" inherit_id="web.assets_backend">
|
||||
<xpath expr="." position="inside">
|
||||
<link rel="stylesheet"
|
||||
href="/web_tree_date_search/static/src/css/web_tree_date_search.css"/>
|
||||
<script type="text/javascript" src="/web_tree_date_search/static/src/js/web_tree_date_search.js"></script>
|
||||
</xpath>
|
||||
</template>
|
||||
</data>
|
||||
</openerp>
|
||||
Reference in New Issue
Block a user