Skip to content
Open
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
118 changes: 118 additions & 0 deletions search_today_filter/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
=============================
Today filter for search views
=============================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:a37aa61a3e4fe487cc8063d7eb4ebf5bea9b0ac34c1f0e9eb3424212b4c9c2ae
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--ux-lightgray.png?logo=github
:target: https://github.com/OCA/server-ux/tree/17.0/search_today_filter
:alt: OCA/server-ux
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/server-ux-17-0/server-ux-17-0-search_today_filter
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-ux&target_branch=17.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module enhances Odoo's search views by adding "Created Today" and
"Updated Today" filters to models with 'create_date' and 'write_date'
fields, enabling quick filtering by today's creation or update date.

**Table of contents**

.. contents::
:local:

Configuration
=============

This module does not require any specific configuration steps through
Odoo's user interface.

#. Once the module is installed successfully, its functionality becomes
active automatically. #. The "Created Today" and "Updated Today" filters
will be dynamically added to the search views.

Usage
=====

Once the module is installed, the filters will be automatically
available in applicable search views:

#. Navigate to any Odoo list view for a model that has ``create_date``
and/or ``write_date`` fields (e.g., Sales Orders, Contacts, Tasks,
Invoices). #. In the search bar at the top of the list, you will now
find: \* **"Created Today" filter:** Filters records created on the
current day. \* **"Updated Today" filter:** Filters records last updated
on the current day. #. Click on these filters to apply them.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-ux/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/server-ux/issues/new?body=module:%20search_today_filter%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* BizzAppDev Systems

Contributors
------------

- BizzAppDev Systems (https://www.bizzappdev.com):

- Ruchir Shukla ruchir@bizzappdev.com

Other credits
-------------

The development of this module has been financially supported by:

- Pledra

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

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.

.. |maintainer-bizzappdev| image:: https://github.com/bizzappdev.png?size=40px
:target: https://github.com/bizzappdev
:alt: bizzappdev

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-bizzappdev|

This module is part of the `OCA/server-ux <https://github.com/OCA/server-ux/tree/17.0/search_today_filter>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions search_today_filter/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
13 changes: 13 additions & 0 deletions search_today_filter/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "Today filter for search views",
"summary": "Add a 'Today' filter to search views",
"version": "17.0.1.0.0",
"category": "Tools",
"development_status": "Beta",
"website": "https://github.com/OCA/server-ux",
"author": "BizzAppDev Systems, Odoo Community Association (OCA)",
"license": "AGPL-3",
"depends": ["base"],
"maintainers": ["bizzappdev"],
"installable": True,
}
1 change: 1 addition & 0 deletions search_today_filter/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import base
67 changes: 67 additions & 0 deletions search_today_filter/models/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
from lxml import etree

from odoo import api, models


class Base(models.AbstractModel):
_inherit = "base"

_search_today_create_fields = "create_date"
_search_today_update_fields = "write_date"

@api.model
def get_view(self, view_id=None, view_type="form", **options):
# Inherit the get_view method to inject the 'Today' filter
# Inject 'Today' filter in search views.
res = super().get_view(view_id, view_type, **options)
if view_type != "search" or (
(
not self._search_today_create_fields
or self._search_today_create_fields not in self._fields
)
and (
not self._search_today_update_fields
or self._search_today_update_fields not in self._fields
)
):
return res
arch = etree.fromstring(res["arch"])

def _add_filter_date(filtern_name, filter_string, domain):
"""Helper function to add a date filter."""
today_filter = etree.Element(
"filter",
{
"name": filtern_name,
"string": filter_string,
"domain": domain,
},
)
# Add the 'Today' filter to the search view
arch.append(today_filter)

domain = (
"[('{date_field}', '>', "
"(context_today() - datetime.timedelta(days=1)).strftime('%Y-%m-%d'))]"
)
if self._search_today_create_fields:
# Define the 'Today' filter
_add_filter_date(
filtern_name="auto_created_today",
filter_string="Created Today",
domain=domain.format(
date_field=self._search_today_create_fields,
),
)

if self._search_today_update_fields:
# Define the 'Today' filter for updates
_add_filter_date(
filtern_name="auto_updated_today",
filter_string="Updated Today",
domain=domain.format(
date_field=self._search_today_update_fields,
),
)
res["arch"] = etree.tostring(arch, encoding="unicode")
return res
3 changes: 3 additions & 0 deletions search_today_filter/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
4 changes: 4 additions & 0 deletions search_today_filter/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This module does not require any specific configuration steps through Odoo's user interface.

#. Once the module is installed successfully, its functionality becomes active automatically.
#. The "Created Today" and "Updated Today" filters will be dynamically added to the search views.
2 changes: 2 additions & 0 deletions search_today_filter/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* BizzAppDev Systems (<https://www.bizzappdev.com>):
* Ruchir Shukla <ruchir@bizzappdev.com>
3 changes: 3 additions & 0 deletions search_today_filter/readme/CREDITS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The development of this module has been financially supported by:

- Pledra
1 change: 1 addition & 0 deletions search_today_filter/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module enhances Odoo's search views by adding "Created Today" and "Updated Today" filters to models with 'create_date' and 'write_date' fields, enabling quick filtering by today's creation or update date.
7 changes: 7 additions & 0 deletions search_today_filter/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Once the module is installed, the filters will be automatically available in applicable search views:

#. Navigate to any Odoo list view for a model that has `create_date` and/or `write_date` fields (e.g., Sales Orders, Contacts, Tasks, Invoices).
#. In the search bar at the top of the list, you will now find:
* **"Created Today" filter:** Filters records created on the current day.
* **"Updated Today" filter:** Filters records last updated on the current day.
#. Click on these filters to apply them.
Loading