Skip to content
Snippets Groups Projects
Commit b0ee438477fb authored by Etienne Ferriere's avatar Etienne Ferriere
Browse files

Add find() method on fiscal years needed by other modules.

parent 650e2988fef7
No related branches found
No related tags found
1 merge request!39Draft: Add find() method on fiscal years needed by other modules.
Pipeline #71094 passed
This commit is part of merge request !39. Comments created here will be created in the context of that merge request.
......@@ -2,6 +2,11 @@
Changelog
=========
16.0.1.3.0
----------
Add ``find(date)`` method on fiscal years.
16.0.1.2.0
----------
......@@ -5,7 +10,7 @@
16.0.1.2.0
----------
Add ``find(date)`` method
Add ``find(date)`` method on accounting periods.
16.0.1.1.0
----------
......
......@@ -22,7 +22,7 @@
"name": "Accounting Periods",
"license": "AGPL-3",
"summary": "Add period accounting concept",
"version": "16.0.1.2.0",
"version": "16.0.1.3.0",
"category": "Accounting/Accounting",
"author": "XCG Consulting",
"website": "https://orbeet.io/",
......
......@@ -86,3 +86,24 @@
for period in periods:
period.unlink()
return super().unlink()
def find(self, date=None):
"""
:param date: date (odoo format so string), if None, use today
:return: fiscal years that include the indicated date, using either
the company_id in the context or if not set, the user company_id
"""
if not date:
date = fields.Date.context_today(self)
company_id = self.env.context.get("company_id") or self.env.company.id
result = self.search(
[
("date_from", "<=", date),
("date_to", ">=", date),
("company_id", "=", company_id),
],
limit=1,
)
return result
......@@ -17,9 +17,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from datetime import date
from odoo import fields, tests
class Test(tests.TransactionCase):
"""Fiscal year & period creation tests."""
......@@ -20,9 +22,16 @@
from odoo import fields, tests
class Test(tests.TransactionCase):
"""Fiscal year & period creation tests."""
def setUp(self):
super().setUp()
self.long_past = date(1977, 9, 20)
# this should not be in any demo data, so use assert, and not a unit
# assert.
assert not self.env["account.fiscal.year"].find(self.long_past)
def test_create_periods(self):
# Try in 2000 to avoid conflicts with other demo years/periods.
fiscal_year = self.env["account.fiscal.year"].create(
......@@ -42,3 +51,30 @@
fiscal_year.date_from,
min(period.date_start for period in fiscal_year.period_ids),
)
def test_find_fiscal_year(self):
"""Test the find method."""
# clean up all fiscal year for a first branch
self.env["account.fiscal.year"].create(
{
"date_from": date(1977, 1, 1),
"date_to": date(1977, 12, 31),
"name": "1977",
}
)
fiscal_year = self.env["account.fiscal.year"].find(self.long_past)
self.assertEqual(fiscal_year.date_from, date(1977, 1, 1))
self.assertEqual(fiscal_year.date_to, date(1977, 12, 31))
self.assertEqual(fiscal_year.company_id.id, 1)
def test_find_fiscal_year_first_day_of_year(self):
"""Test the find method of the fiscal year, ensuring the lower limit
does not cause trouble."""
self.long_past = date(1977, 1, 1)
self.test_find_fiscal_year()
def test_find_fiscal_year_last_day_of_year(self):
"""Test the find method of the fiscal year, ensuring the upper limit
does not cause trouble."""
self.long_past = date(1977, 12, 31)
self.test_find_fiscal_year()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment