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
2
@@ -2,6 +2,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from datetime import date
from dateutil.relativedelta import relativedelta
from odoo import fields, models
@@ -110,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,
@@ -119,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:
@@ -123,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
@@ -130,5 +131,5 @@
# 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:
@@ -134,8 +135,6 @@
while to_create_start > dt:
to_create_stop = to_create_start + relativedelta(
days=-1
)
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)],
@@ -138,7 +137,7 @@
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,
)
@@ -143,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
@@ -146,3 +145,3 @@
# 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:
@@ -148,10 +147,6 @@
while to_create_stop < dt:
to_create_start = to_create_stop + relativedelta(
days=1
)
to_create_stop = (
to_create_start + self._get_duration()
)
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
@@ -155,5 +150,5 @@
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:
@@ -159,10 +154,6 @@
while to_create_stop < dt:
to_create_start = to_create_stop + relativedelta(
days=1
)
to_create_stop = (
to_create_start + self._get_duration()
)
to_create_start = to_create_stop + relativedelta(days=1)
to_create_stop = to_create_start + self._get_duration()
else:
# there’s no fy in the system, if the duration is changed,
# this will not work as is
@@ -178,7 +169,7 @@
result = self.create(
[
{
"date_stop": to_create_stop,
"date_to": to_create_stop,
"company_id": company_id,
"name": name.format(to_create_stop),
"code": code.format(to_create_stop),
Loading