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#66823 [MIG][16.0] account_search_date_range #219

Merged
merged 3 commits into from
Oct 7, 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
1 change: 1 addition & 0 deletions .docker_files/main/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"account_move_unique_reversal",
"account_negative_debit_credit",
"account_payment_cancel_group",
"account_search_date_range",
"account_show_full_features",
"bank_statement_import_csv",
"canada_account_types",
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ COPY account_move_unique_reversal /mnt/extra-addons/account_move_unique_reversal
COPY account_negative_debit_credit /mnt/extra-addons/account_negative_debit_credit
COPY account_payment_cancel_group /mnt/extra-addons/account_payment_cancel_group
COPY account_show_full_features /mnt/extra-addons/account_show_full_features
COPY account_search_date_range /mnt/extra-addons/account_search_date_range
COPY bank_statement_import_csv /mnt/extra-addons/bank_statement_import_csv
COPY canada_account_types /mnt/extra-addons/canada_account_types
COPY canada_mis_report /mnt/extra-addons/canada_mis_report
Expand Down
56 changes: 56 additions & 0 deletions account_search_date_range/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
=============================
Account Search Date Range Account
=============================

This module extends the web_search_date_range module with date ranges related to accounting.

It enables date filters that are bound to the fiscal year of the company.

.. contents:: Table of Contents

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

The module uses the Fiscal Year settings to determine the fiscal year and trimester ranges.

.. image:: static/description/account_onboarding.png

.. image:: static/description/account_onboarding_fiscal_period.png

Usage
-----

To add a filter to the search view of a model:

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

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

* Refresh your page, then go to the list view of the model (i.e. Journal Items)

.. image:: static/description/invoice_list.png

Available Ranges
----------------

For now, the following filters are available.

* Previous Trimester
* Current Trimester
* Next Trimester
* Previous Fiscal Year
* Current Fiscal Year
* Next Fiscal Year

Multi-Company
-------------

The module works with multi-company.

If you have subsidiaries with different account closing dates, the same filters will work for all.
You will not need to recreate your dashboards for each subsidiary.

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

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

from . import models

Check notice on line 4 in account_search_date_range/__init__.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

account_search_date_range/__init__.py#L4

'.models' imported but unused (F401)
16 changes: 16 additions & 0 deletions account_search_date_range/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2023 - today Numigi (tm) 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 account_search_date_range/__manifest__.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

account_search_date_range/__manifest__.py#L4

Statement seems to have no effect
"name": "Account Date Range Account",
"version": "16.0.1.0.0",
"author": "Numigi",
"maintainer": "Numigi",
"website": "https://bit.ly/numigi-com",
"license": "LGPL-3",
"category": "Project",
"summary": "Add accounting date range filters.",
"depends": ["web_search_date_range", "account"],
"data": ["data/search_date_range.xml"],
"installable": True,
}
64 changes: 64 additions & 0 deletions account_search_date_range/data/search_date_range.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>

<record id="range_previous_trimester" model="search.date.range">
<field name="label">Previous Fiscal Trimester</field>
<field name="domain">[
'&amp;',
(field, '&gt;=', (trimester_start - relativedelta(months=3)).strftime('%Y-%m-%d')),
(field, '&lt;', trimester_start.strftime('%Y-%m-%d')),
]</field>
<field name="sequence" eval="20" />
</record>

<record id="range_current_trimester" model="search.date.range">
<field name="label">Current Fiscal Trimester</field>
<field name="domain">[
'&amp;',
(field, '&gt;=', trimester_start.strftime('%Y-%m-%d')),
(field, '&lt;', (trimester_start + relativedelta(months=3)).strftime('%Y-%m-%d')),
]</field>
<field name="sequence" eval="21" />
</record>

<record id="range_next_trimester" model="search.date.range">
<field name="label">Next Fiscal Trimester</field>
<field name="domain">[
'&amp;',
(field, '&gt;=', (trimester_start + relativedelta(months=3)).strftime('%Y-%m-%d')),
(field, '&lt;', (trimester_start + relativedelta(months=6)).strftime('%Y-%m-%d')),
]</field>
<field name="sequence" eval="22" />
</record>

<record id="range_previous_fiscal_year" model="search.date.range">
<field name="label">Previous Fiscal Year</field>
<field name="domain">[
'&amp;',
(field, '&gt;=', (fiscal_year_start - relativedelta(years=1)).strftime('%Y-%m-%d')),
(field, '&lt;', fiscal_year_start.strftime('%Y-%m-%d')),
]</field>
<field name="sequence" eval="30" />
</record>

<record id="range_current_fiscal_year" model="search.date.range">
<field name="label">Current Fiscal Year</field>
<field name="domain">[
'&amp;',
(field, '&gt;=', fiscal_year_start.strftime('%Y-%m-%d')),
(field, '&lt;', (fiscal_year_start + relativedelta(years=1)).strftime('%Y-%m-%d')),
]</field>
<field name="sequence" eval="31" />
</record>

<record id="range_next_fiscal_year" model="search.date.range">
<field name="label">Next Fiscal Year</field>
<field name="domain">[
'&amp;',
(field, '&gt;=', (fiscal_year_start + relativedelta(years=1)).strftime('%Y-%m-%d')),
(field, '&lt;', (fiscal_year_start + relativedelta(years=2)).strftime('%Y-%m-%d')),
]</field>
<field name="sequence" eval="32" />
</record>

</odoo>
48 changes: 48 additions & 0 deletions account_search_date_range/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_search_date_range
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 11.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2018-10-18 21:11+0000\n"
"PO-Revision-Date: 2018-10-18 17:11-0400\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"Language: fr\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: \n"
"X-Generator: Poedit 2.0.6\n"

#. module: account_search_date_range
#: model:search.date.range,label:account_search_date_range.range_current_trimester
msgid "Current Fiscal Trimester"
msgstr "Trimestre fiscal courant"

#. module: account_search_date_range
#: model:search.date.range,label:account_search_date_range.range_current_fiscal_year
msgid "Current Fiscal Year"
msgstr "Année fiscale courante"

#. module: account_search_date_range
#: model:search.date.range,label:account_search_date_range.range_next_trimester
msgid "Next Fiscal Trimester"
msgstr "Trimestre fiscal suivant"

#. module: account_search_date_range
#: model:search.date.range,label:account_search_date_range.range_next_fiscal_year
msgid "Next Fiscal Year"
msgstr "Année fiscale suivante"

#. module: account_search_date_range
#: model:search.date.range,label:account_search_date_range.range_previous_trimester
msgid "Previous Fiscal Trimester"
msgstr "Trimestre fiscal précédent"

#. module: account_search_date_range
#: model:search.date.range,label:account_search_date_range.range_previous_fiscal_year
msgid "Previous Fiscal Year"
msgstr "Année fiscale précédente"
4 changes: 4 additions & 0 deletions account_search_date_range/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2023 - today Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from . import search_date_range

Check notice on line 4 in account_search_date_range/models/__init__.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

account_search_date_range/models/__init__.py#L4

'.search_date_range' imported but unused (F401)
37 changes: 37 additions & 0 deletions account_search_date_range/models/search_date_range.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright 2023 - today Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta
from odoo import api, fields, models


class SearchDateRange(models.AbstractModel):

_inherit = "search.date.range"

@api.model
def _get_domain_context(self, field):
res = super()._get_domain_context(field)
fiscal_year_start = self._get_fiscal_year_first_date()
trimester_start = self._get_trimester_start(fiscal_year_start)
res.update(
fiscal_year_start=fiscal_year_start,
trimester_start=trimester_start,
)
return res

def _get_trimester_start(self, fiscal_year_start):
months_passed = relativedelta(datetime.now(), fiscal_year_start).months
return fiscal_year_start + relativedelta(months=3 * (months_passed // 3))

def _get_fiscal_year_first_date(self):
today = fields.Date.context_today(self)
last_month = int(self.env.user.company_id.fiscalyear_last_month)
return (
today
+ relativedelta(
years=-1 if last_month >= today.month else 0, month=last_month, day=31
)
+ timedelta(1)
)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions account_search_date_range/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2023 - today Numigi (tm) and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

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

from ddt import data, ddt, unpack
from freezegun import freeze_time
from odoo.tests import common


@ddt
class TestSearchDateRange(common.SavepointCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.model = cls.env.ref("base.model_res_partner")
cls.field = cls.env.ref("base.field_res_partner__create_date")
cls.env.user.company_id.write(
{"fiscalyear_last_month": "3", "fiscalyear_last_day": "31"}
)

def _eval_filter_domain(self, range_ref):
date_range = self.env.ref(f"account_search_date_range.{range_ref}")
return date_range.generate_domain(self.field.name)

@data(
("2018-03-31", "2016-04-01", "2017-04-01"),
("2018-04-01", "2017-04-01", "2018-04-01"),
)
@unpack
def test_range_previous_fiscal_year(self, today, date_from, date_to):
with freeze_time(today):
domain = self._eval_filter_domain("range_previous_fiscal_year")

self.assertEqual(
domain,
[
"&",
("create_date", ">=", date_from),
("create_date", "<", date_to),
],
)

@data(
("2018-03-31", "2017-04-01", "2018-04-01"),
("2018-04-01", "2018-04-01", "2019-04-01"),
)
@unpack
def test_range_current_fiscal_year(self, today, date_from, date_to):
with freeze_time(today):
domain = self._eval_filter_domain("range_current_fiscal_year")

self.assertEqual(
domain,
[
"&",
("create_date", ">=", date_from),
("create_date", "<", date_to),
],
)

@data(
("2018-03-31", "2018-04-01", "2019-04-01"),
("2018-04-01", "2019-04-01", "2020-04-01"),
)
@unpack
def test_range_next_fiscal_year(self, today, date_from, date_to):
with freeze_time(today):
domain = self._eval_filter_domain("range_next_fiscal_year")

self.assertEqual(
domain,
[
"&",
("create_date", ">=", date_from),
("create_date", "<", date_to),
],
)

@data(
("2018-03-31", "2017-10-01", "2018-01-01"),
("2018-04-01", "2018-01-01", "2018-04-01"),
)
@unpack
def test_range_previous_trimester(self, today, date_from, date_to):
with freeze_time(today):
domain = self._eval_filter_domain("range_previous_trimester")

self.assertEqual(
domain,
[
"&",
("create_date", ">=", date_from),
("create_date", "<", date_to),
],
)

@data(
("2018-03-31", "2018-01-01", "2018-04-01"),
("2018-04-01", "2018-04-01", "2018-07-01"),
)
@unpack
def test_range_current_trimester(self, today, date_from, date_to):
with freeze_time(today):
domain = self._eval_filter_domain("range_current_trimester")

self.assertEqual(
domain,
[
"&",
("create_date", ">=", date_from),
("create_date", "<", date_to),
],
)

@data(
("2018-03-31", "2018-04-01", "2018-07-01"),
("2018-04-01", "2018-07-01", "2018-10-01"),
)
@unpack
def test_range_next_trimester(self, today, date_from, date_to):
with freeze_time(today):
domain = self._eval_filter_domain("range_next_trimester")

self.assertEqual(
domain,
[
"&",
("create_date", ">=", date_from),
("create_date", "<", date_to),
],
)
Loading
Loading