Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TA#66767 [MIG][16.0] web_search_date_range #130

Merged
merged 6 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .docker_files/main/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"resize_observer_error_catcher",
"web_custom_label",
"web_custom_modifier",

"web_search_date_range"
],
"installable": True,
}
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ USER odoo
COPY resize_observer_error_catcher /mnt/extra-addons/resize_observer_error_catcher
COPY web_custom_label /mnt/extra-addons/web_custom_label
COPY web_custom_modifier /mnt/extra-addons/web_custom_modifier
COPY web_search_date_range /mnt/extra-addons/web_search_date_range

COPY .docker_files/main /mnt/extra-addons/main
COPY .docker_files/odoo.conf /etc/odoo
100 changes: 100 additions & 0 deletions web_search_date_range/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
=====================
Web Search Date Range
=====================

.. contents:: Table of Contents

Context
-------
Vanilla Odoo comes with a predefined set of date range filters.

.. image:: static/description/vanilla_odoo_filters.png

There are multiple issues with these filters:

* They can not be customized (at least without extra javascript code).
* They are based on static dates, which is not suitable for dashboards (you don't want to update your dashboard every month).
* Quarters are only relevant for a company with a fiscal exercise from January to December.

Overview
--------
This module allows to easily add contextual date range filters.

Contextual means that the filter does not need to be updated.
It always filters records based on the current date.

You may add one of these filters to your favorites or your dashboard and it will not need to be refreshed.

.. image:: static/description/quotations_list.png

Configuration
-------------

Date Filters
************
To edit the list of filters that appear in the search view of a model:

* Go to: Settings / Technical / User Interface / Date Filters

.. image:: static/description/date_filters.png

After editing the filters, you need to refresh your page for the changes to be applied.

Date Ranges
***********
The module comes with the following predefined date ranges:

* Before Today
* Today
* Next Fifteen Days
* Previous Week
* Current Week
* Next Week
* Previous Month
* Current Month
* Next Month
* Previous Year
* Current Year
* Next Year

To add a custom range type:

* Go to: Settings / Technical / User Interface / Date Ranges

.. image:: static/description/date_range_list.png

* Click on `Create`.

.. image:: static/description/date_range_form.png

* Enter a label for your range type.
* Enter a domain filter for your new range type.

.. image:: static/description/date_range_with_domain.png

The following variables can be used inside the domain:

* field: the technical name of the field being queried
* today: the current date in the timezone of the user
* datetime: the datetime.datetime class
* relativedelta: the dateutil.relativedelta.relativedelta class
* MO, TU, WE, TH, FR, SA, SU: dateutil.relativedelta.weekdays

See the library `relativedelta <https://dateutil.readthedocs.io/en/stable/relativedelta.html>`_ for more info.

Weekly Date Ranges
------------------
Weekly date ranges are implemented from monday to sunday.

If you prefer from sunday to saturday:

* Go to: Settings / Technical / User Interface / Date Range Types.
* For each weekly range type:
1. Adapt the domain.
2. Check the `No Update` checkbox.

.. image:: static/description/demo_date_range.png

Contributors
------------
* Numigi (tm) and all its contributors (https://bit.ly/numigiens)
4 changes: 4 additions & 0 deletions web_search_date_range/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2023-today Numigi and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from . import models
28 changes: 28 additions & 0 deletions web_search_date_range/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2023-today Numigi and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

{

Check warning on line 4 in web_search_date_range/__manifest__.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

web_search_date_range/__manifest__.py#L4

Statement seems to have no effect
"name": "Web Search Date Range",
"version": "16.0.1.0.0",
"author": "Numigi",
"maintainer": "Numigi",
"website": "https://bit.ly/numigi-com",
"license": "LGPL-3",
"category": "Project",
"summary": "Add date range filters to the search filters dropdown menu.",
"depends": [
"web",
],
"data": [
"security/ir.model.access.csv",
"data/search_date_range.xml",
"views/search_date_range_views.xml",
"views/search_date_range_filter_views.xml",
],
"assets": {
"web.assets_backend": [
"/web_search_date_range/static/src/js/*",
],
},
"installable": True,
}
123 changes: 123 additions & 0 deletions web_search_date_range/data/search_date_range.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>

<record id="range_before_today" model="search.date.range">
<field name="label">Before Today</field>
<field name="domain">[
(field, '&lt;', today.strftime('%Y-%m-%d')),
]</field>
<field name="sequence" eval="-1" />
</record>

<record id="range_today" model="search.date.range">
<field name="label">Today</field>
<field name="domain">[
'&amp;',
(field, '&gt;=', today.strftime('%Y-%m-%d')),
(field, '&lt;', (today + relativedelta(days=1)).strftime('%Y-%m-%d')),
]</field>
<field name="sequence" eval="1" />
</record>

<record id="range_next_fifteen_days" model="search.date.range">
<field name="label">Next Fifteen Days</field>
<field name="domain">[
'&amp;',
(field, '&gt;=', today.strftime('%Y-%m-%d')),
(field, '&lt;', (today + relativedelta(days=15)).strftime('%Y-%m-%d')),
]</field>
<field name="sequence" eval="2" />
</record>

<!-- Week ranges are from Monday to Sunday -->
<record id="range_previous_week" model="search.date.range">
<field name="label">Previous Week</field>
<field name="domain">[
'&amp;',
(field, '&gt;=', (today + relativedelta(days=-today.weekday() - 7)).strftime('%Y-%m-%d')),
(field, '&lt;', (today + relativedelta(days=-today.weekday())).strftime('%Y-%m-%d')),
]</field>
<field name="sequence" eval="3" />
</record>

<record id="range_current_week" model="search.date.range">
<field name="label">Current Week</field>
<field name="domain">[
'&amp;',
(field, '&gt;=', (today + relativedelta(days=-today.weekday())).strftime('%Y-%m-%d')),
(field, '&lt;', (today + relativedelta(days=-today.weekday() + 7)).strftime('%Y-%m-%d')),
]</field>
<field name="sequence" eval="4" />
</record>

<record id="range_next_week" model="search.date.range">
<field name="label">Next Week</field>
<field name="domain">[
'&amp;',
(field, '&gt;=', (today + relativedelta(days=-today.weekday() + 7)).strftime('%Y-%m-%d')),
(field, '&lt;', (today + relativedelta(days=-today.weekday() + 14)).strftime('%Y-%m-%d')),
]</field>
<field name="sequence" eval="5" />
</record>

<record id="range_previous_month" model="search.date.range">
<field name="label">Previous Month</field>
<field name="domain">[
'&amp;',
(field, '&gt;=', (today - relativedelta(days=today.day - 1) + relativedelta(months=-1)).strftime('%Y-%m-%d')),
(field, '&lt;', (today - relativedelta(days=today.day - 1)).strftime('%Y-%m-%d')),
]</field>
<field name="sequence" eval="6" />
</record>

<record id="range_current_month" model="search.date.range">
<field name="label">Current Month</field>
<field name="domain">[
'&amp;',
(field, '&gt;=', (today - relativedelta(days=today.day - 1)).strftime('%Y-%m-%d')),
(field, '&lt;', (today - relativedelta(days=today.day - 1) + relativedelta(months=1)).strftime('%Y-%m-%d')),
]</field>
<field name="sequence" eval="7" />
</record>

<record id="range_next_month" model="search.date.range">
<field name="label">Next Month</field>
<field name="domain">[
'&amp;',
(field, '&gt;=', (today - relativedelta(days=today.day - 1) + relativedelta(months=1)).strftime('%Y-%m-%d')),
(field, '&lt;', (today - relativedelta(days=today.day - 1) + relativedelta(months=2)).strftime('%Y-%m-%d')),
]</field>
<field name="sequence" eval="8" />
</record>

<record id="range_previous_year" model="search.date.range">
<field name="label">Previous Year</field>
<field name="domain">[
'&amp;',
(field, '&gt;=', datetime(today.year - 1, 1, 1).strftime('%Y-%m-%d')),
(field, '&lt;', datetime(today.year, 1, 1).strftime('%Y-%m-%d')),
]</field>
<field name="sequence" eval="9" />
</record>

<record id="range_current_year" model="search.date.range">
<field name="label">Current Year</field>
<field name="domain">[
'&amp;',
(field, '&gt;=', datetime(today.year, 1, 1).strftime('%Y-%m-%d')),
(field, '&lt;', datetime(today.year + 1, 1, 1).strftime('%Y-%m-%d')),
]</field>
<field name="sequence" eval="10" />
</record>

<record id="range_next_year" model="search.date.range">
<field name="label">Next Year</field>
<field name="domain">[
'&amp;',
(field, '&gt;=', datetime(today.year + 1, 1, 1).strftime('%Y-%m-%d')),
(field, '&lt;', datetime(today.year + 2, 1, 1).strftime('%Y-%m-%d')),
]</field>
<field name="sequence" eval="11" />
</record>

</odoo>
Loading
Loading