Skip to content
Snippets Groups Projects

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

Open Etienne Ferriere requested to merge topic/16.0/MO16-00581 into branch/16.0
Files
3
@@ -99,7 +99,7 @@
# handle shorter or longer fiscal year
return relativedelta(years=1, days=-1)
def find(self, dt=None, create=False, code="{0:%Y}", name="{0:%Y}"):
def find(self, dt=None, create=False, name="{0:%Y}"):
"""
:param dt: date (odoo format so string), if None, use today
:return: fiscal years that include the indicated date, using either
@@ -111,8 +111,8 @@
company_id = self.env.context.get("company_id") or self.env.company.id
result = self.search(
[
("date_start", "<=", dt),
("date_stop", ">=", dt),
("date_from", "<=", dt),
("date_to", ">=", dt),
("company_id", "=", company_id),
],
limit=1,
@@ -120,10 +120,10 @@
if not result and create:
oldest_fy = self.search(
[("company_id", "=", company_id)],
order="date_start DESC",
order="date_from DESC",
limit=1,
)
# Store date stop for the fiscal year to create
to_create_stop = None
if oldest_fy:
@@ -124,9 +124,9 @@
limit=1,
)
# Store date stop for the fiscal year to create
to_create_stop = None
if oldest_fy:
if dt < oldest_fy.date_start:
if dt < oldest_fy.date_from:
# the fiscal year to create is before any created so far
# backtrack by duration until we find the one to create
@@ -131,10 +131,10 @@
# the fiscal year to create is before any created so far
# backtrack by duration until we find the one to create
to_create_start = oldest_fy.date_start
# to_create_stop = oldest_fy.date_stop
to_create_start = oldest_fy.date_from
# to_create_stop = oldest_fy.date_to
while to_create_start > dt:
to_create_stop = to_create_start + relativedelta(days=-1)
to_create_start = to_create_stop - self._get_duration()
else:
newest_fy = self.search(
[("company_id", "=", company_id)],
@@ -135,9 +135,9 @@
while to_create_start > dt:
to_create_stop = to_create_start + relativedelta(days=-1)
to_create_start = to_create_stop - self._get_duration()
else:
newest_fy = self.search(
[("company_id", "=", company_id)],
order="date_stop ASC",
order="date_to ASC",
limit=1,
)
@@ -142,4 +142,4 @@
limit=1,
)
if dt > newest_fy.date_stop:
if dt > newest_fy.date_to:
# the fiscal year to create is after any created so far
@@ -145,8 +145,8 @@
# the fiscal year to create is after any created so far
to_create_stop = newest_fy.date_stop
to_create_stop = newest_fy.date_to
while to_create_stop < dt:
to_create_start = to_create_stop + relativedelta(days=1)
to_create_stop = to_create_start + self._get_duration()
else:
# the fiscal year to create is between any created so
# far
@@ -147,10 +147,10 @@
while to_create_stop < dt:
to_create_start = to_create_stop + relativedelta(days=1)
to_create_stop = to_create_start + self._get_duration()
else:
# the fiscal year to create is between any created so
# far
to_create_stop = oldest_fy.date_stop
to_create_stop = oldest_fy.date_to
while to_create_stop < dt:
to_create_start = to_create_stop + relativedelta(days=1)
to_create_stop = to_create_start + self._get_duration()
@@ -169,6 +169,7 @@
result = self.create(
[
{
"date_stop": to_create_stop,
"date_from": to_create_stop - self._get_duration(),
"date_to": to_create_stop,
"company_id": company_id,
"name": name.format(to_create_stop),
@@ -173,6 +174,5 @@
"company_id": company_id,
"name": name.format(to_create_stop),
"code": code.format(to_create_stop),
}
]
)
Loading