Browse Source

Merge pull request #173 from hbrunn/8.0-web_search_datetime_completion

[ADD] web_search_datetime_completion
pull/307/head
Sylvain LE GAL 9 years ago
parent
commit
8648f55d40
  1. 57
      web_search_datetime_completion/README.rst
  2. 20
      web_search_datetime_completion/__init__.py
  3. 41
      web_search_datetime_completion/__openerp__.py
  4. BIN
      web_search_datetime_completion/static/description/icon.png
  5. 83
      web_search_datetime_completion/static/src/js/web_search_datetime_completion.js
  6. 10
      web_search_datetime_completion/views/templates.xml

57
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::
<field name="my_datetime_field" options="{'completion_options': [{'hours': 12, 'minutes': 30, 'seconds': 0}]}" />
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 <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:%20web_search_datetime_completion%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Credits
=======
Contributors
------------
* Holger Brunn <hbrunn@therp.nl>
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.

20
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 <http://therp.nl>.
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################

41
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 <http://therp.nl>.
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
{
"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': [],
},
}

BIN
web_search_datetime_completion/static/description/icon.png

After

Width: 128  |  Height: 128  |  Size: 9.2 KiB

83
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 <http://therp.nl>.
//
// 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 <http://www.gnu.org/licenses/>.
//
//############################################################################
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(
'<em>%s</em>',
_.escape(self.attrs.string)),
value: _.str.sprintf(
'<strong>%s</strong>',
_.escape(date_string)),
}),
facet: {
category: self.attrs.string,
field: self,
values: [{
label: date_string,
value: date,
}],
},
});
});
return options;
});
},
})
}

10
web_search_datetime_completion/views/templates.xml

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<template id="assets_backend" name="web_search_datetime_completion assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/web_search_datetime_completion/static/src/js/web_search_datetime_completion.js"></script>
</xpath>
</template>
</data>
</openerp>
Loading…
Cancel
Save