Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Accounting Periods
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
XCG
Odoo modules
Accounting Periods
Merge requests
!39
Draft: Add find() method on fiscal years needed by other modules.
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Draft: Add find() method on fiscal years needed by other modules.
topic/16.0/MO16-00581
into
branch/16.0
Overview
0
Commits
1
Pipelines
10
Changes
4
Open
Etienne Ferriere
requested to merge
topic/16.0/MO16-00581
into
branch/16.0
1 year ago
Overview
0
Commits
1
Pipelines
10
Changes
3
Expand
MO16-00581
Edited
1 year ago
by
Vincent Hatakeyama
0
0
Merge request reports
Compare
version 5
version 9
dda56d3a
1 year ago
version 8
414a2c09
1 year ago
version 7
02ce3b16
1 year ago
version 6
8c5334b2
1 year ago
version 5
32d7176b
1 year ago
version 4
1e784239
1 year ago
version 3
849ce670
1 year ago
version 2
87177ccf
1 year ago
version 1
6b281e37
1 year ago
branch/16.0 (base)
and
version 9
latest version
b0ee4384
1 commit,
1 year ago
version 9
dda56d3a
2 commits,
1 year ago
version 8
414a2c09
1 commit,
1 year ago
version 7
02ce3b16
1 commit,
1 year ago
version 6
8c5334b2
1 commit,
1 year ago
version 5
32d7176b
1 commit,
1 year ago
version 4
1e784239
1 commit,
1 year ago
version 3
849ce670
1 commit,
1 year ago
version 2
87177ccf
1 commit,
1 year ago
version 1
6b281e37
1 commit,
1 year ago
Show latest version
3 files
+
60
−
122
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
3
Search (e.g. *.vue) (Ctrl+P)
models/account_fiscal_year.py
+
20
−
91
Options
# Copyright 2020 Simone Rubino - Agile Business Group
# 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
@@ -91,90 +87,23 @@
period
.
unlink
()
return
super
().
unlink
()
def
_get_duration
(
self
):
"""
:return: relativedelta of duration of a fiscal year
"""
# This is a method so it can be changed in the case of needing to
# 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}
"
):
"""
:param dt: 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
dt
:
dt
=
fields
.
Date
.
context_today
(
self
)
company_id
=
self
.
env
.
context
.
get
(
"
company_id
"
)
or
self
.
env
.
company
.
id
result
=
self
.
search
(
[
(
"
date_from
"
,
"
<=
"
,
dt
),
(
"
date_to
"
,
"
>=
"
,
dt
),
(
"
company_id
"
,
"
=
"
,
company_id
),
],
limit
=
1
,
)
if
not
result
and
create
:
oldest_fy
=
self
.
search
(
[(
"
company_id
"
,
"
=
"
,
company_id
)],
order
=
"
date_from DESC
"
,
limit
=
1
,
)
# Store date stop for the fiscal year to create
to_create_stop
=
None
if
oldest_fy
:
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
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
)],
order
=
"
date_to ASC
"
,
limit
=
1
,
)
if
dt
>
newest_fy
.
date_to
:
# the fiscal year to create is after any created so far
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
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
()
else
:
# there’s no fy in the system, if the duration is changed,
# this will not work as is
company
=
self
.
env
[
"
res.company
"
].
browse
(
company_id
)
to_create_stop
=
date
(
dt
.
year
,
int
(
company
.
fiscalyear_last_month
),
company
.
fiscalyear_last_day
,
)
if
dt
>
to_create_stop
:
to_create_stop
.
year
+=
1
# create the fiscal year
result
=
self
.
create
(
[
{
"
date_to
"
:
to_create_stop
,
"
company_id
"
:
company_id
,
"
name
"
:
name
.
format
(
to_create_stop
),
"
code
"
:
code
.
format
(
to_create_stop
),
}
]
)
return
result
# 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
Loading