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
Commits
359f94301358
Commit
359f94301358
authored
3 years ago
by
Vincent Hatakeyama
Browse files
Options
Downloads
Patches
Plain Diff
add periods when using populate
parent
b2f548b007a1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!11
✨ add periods when using populate
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitlab-ci.yml
+4
-0
4 additions, 0 deletions
.gitlab-ci.yml
models/account_fiscalyear.py
+40
-13
40 additions, 13 deletions
models/account_fiscalyear.py
models/account_move.py
+38
-2
38 additions, 2 deletions
models/account_move.py
models/account_period.py
+12
-6
12 additions, 6 deletions
models/account_period.py
with
94 additions
and
21 deletions
.gitlab-ci.yml
+
4
−
0
View file @
359f9430
variables
:
ODOO_POPULATE_MODEL
:
account.move
ODOO_POPULATE_PREREQ
:
l10n_us
include
:
-
project
:
xcg/ci-templates
file
:
/odoo/15.0/gitlab-ci.yaml
This diff is collapsed.
Click to expand it.
models/account_fiscalyear.py
+
40
−
13
View file @
359f9430
...
...
@@ -19,6 +19,7 @@
##############################################################################
import
datetime
import
logging
from
typing
import
Optional
from
dateutil.relativedelta
import
relativedelta
...
...
@@ -169,9 +170,11 @@
: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
# handle shorter or longer fiscal year.
# In that case the constraints on fiscalyear_last_day/fiscalyear_last_month
# needs to be changed too, and so does the populate factory.
return
relativedelta
(
months
=
12
,
days
=-
1
)
def
action_realloc_period_am
(
self
):
"""
Call by the
"
Reallocate Periods
"
action.
...
...
@@ -173,10 +176,9 @@
return
relativedelta
(
months
=
12
,
days
=-
1
)
def
action_realloc_period_am
(
self
):
"""
Call by the
"
Reallocate Periods
"
action.
Look up all accounts move where periods is empty and
try to reallocate it.
Look up all accounts move where periods is empty and try to reallocate it.
"""
for
record
in
self
:
# Only administrator can reallocate periods.
...
...
@@ -216,10 +218,13 @@
move
.
write
({
"
period_id
"
:
period
.
id
,
"
transaction_date
"
:
move
.
date
})
def
find
(
self
,
dt
=
None
):
"""
:param dt: date (odoo format so string), if None, use today
def
find
(
self
,
date
:
Optional
[
datetime
.
date
]
=
None
,
create
:
bool
=
False
)
->
models
.
Model
:
"""
Return the fiscal years for the provided date.
:param date: date, if None, use today
:param create: indicate to create the fiscal year if set to True
:return: fiscal years that include the indicated date, using either the
company_id in the context or if not set, the user company_id
"""
...
...
@@ -222,9 +227,13 @@
: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
return
self
.
search
(
if
not
date
:
date
=
fields
.
Date
.
context_today
(
self
)
company
=
(
self
.
env
[
"
res.company
"
].
browse
(
self
.
env
.
context
.
get
(
"
company_id
"
))
if
"
company_id
"
in
self
.
env
.
context
else
self
.
env
.
company
)
result
=
self
.
search
(
[
...
...
@@ -230,6 +239,6 @@
[
(
"
date_start
"
,
"
<=
"
,
d
t
),
(
"
date_stop
"
,
"
>=
"
,
d
t
),
(
"
company_id
"
,
"
=
"
,
company
_
id
),
(
"
date_start
"
,
"
<=
"
,
d
ate
),
(
"
date_stop
"
,
"
>=
"
,
d
ate
),
(
"
company_id
"
,
"
=
"
,
company
.
id
),
]
)
...
...
@@ -234,2 +243,20 @@
]
)
if
not
result
and
create
:
# assume fiscal year duration is one year
month
=
int
(
company
.
fiscalyear_last_month
)
day
=
company
.
fiscalyear_last_day
if
date
<
datetime
.
date
(
date
.
year
,
month
,
day
):
year
=
date
.
year
else
:
year
=
date
.
year
+
1
result
=
self
.
create
(
{
"
name
"
:
str
(
year
),
"
code
"
:
str
(
year
),
"
date_stop
"
:
datetime
.
date
(
year
,
month
,
day
),
"
company_id
"
:
company
.
id
,
}
)
result
.
create_period
()
return
result
This diff is collapsed.
Click to expand it.
models/account_move.py
+
38
−
2
View file @
359f9430
...
...
@@ -17,4 +17,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import
logging
from
math
import
log10
...
...
@@ -20,5 +22,9 @@
from
odoo
import
_
,
api
,
exceptions
,
fields
,
models
from
dateutil.relativedelta
import
relativedelta
from
odoo
import
_
,
api
,
exceptions
,
fields
,
models
,
tools
_logger
=
logging
.
getLogger
(
__name__
)
class
AccountMove
(
models
.
Model
):
...
...
@@ -53,7 +59,6 @@
@api.model_create_multi
def
create
(
self
,
vals_list
):
"""
Override to set a transaction date from invoices.
"""
for
vals
in
vals_list
:
invoice_date
=
vals
.
get
(
"
invoice_date
"
)
if
invoice_date
:
...
...
@@ -130,3 +135,34 @@
accdoc
.
write
(
accdoc_values
)
return
True
def
_populate_factories
(
self
)
->
list
:
"""
Add periods to the generated account.move
"""
today
=
fields
.
Date
.
today
()
def
get_accounting_date
(
values
,
counter
,
random
):
"""
return an accounting date
"""
accounting_date
=
(
values
[
"
date
"
].
date
()
if
values
[
"
date
"
].
date
()
<
today
else
None
)
# make sure target period exists (or action_post will throw an exception)
if
accounting_date
:
# make it random between the date and today
seconds_after
=
(
today
-
accounting_date
).
total_seconds
()
accounting_date
=
accounting_date
+
relativedelta
(
seconds
=
seconds_after
*
-
log10
(
0.001
+
0.999
*
random
.
random
())
/
3
)
# make sure that period exists
self
.
env
[
"
account.period
"
].
with_context
(
company_id
=
values
[
"
company_id
"
]
).
find
(
accounting_date
.
date
(),
True
)
return
accounting_date
result
=
super
().
_populate_factories
()
result
.
append
(
# set some accounting_date so that when posting everything does not end up
# on the current period
(
"
accounting_date
"
,
tools
.
populate
.
compute
(
get_accounting_date
))
)
return
result
This diff is collapsed.
Click to expand it.
models/account_period.py
+
12
−
6
View file @
359f9430
...
...
@@ -17,6 +17,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import
datetime
from
typing
import
Optional
from
odoo
import
_
,
api
,
exceptions
,
fields
,
models
...
...
@@ -105,5 +107,5 @@
)
]
def
find
(
self
,
d
t
=
Non
e
):
def
find
(
self
,
d
ate
:
Optional
[
datetime
.
date
]
=
None
,
create
:
bool
=
Fals
e
):
...
...
@@ -109,7 +111,7 @@
if
not
d
t
:
d
t
=
fields
.
Date
.
context_today
(
self
)
if
not
d
ate
:
d
ate
=
fields
.
Date
.
context_today
(
self
)
company_id
=
self
.
env
.
context
.
get
(
"
company_id
"
)
or
self
.
env
.
company
.
id
result
=
self
.
search
(
[
...
...
@@ -112,12 +114,12 @@
company_id
=
self
.
env
.
context
.
get
(
"
company_id
"
)
or
self
.
env
.
company
.
id
result
=
self
.
search
(
[
(
"
date_start
"
,
"
<=
"
,
d
t
),
(
"
date_stop
"
,
"
>=
"
,
d
t
),
(
"
date_start
"
,
"
<=
"
,
d
ate
),
(
"
date_stop
"
,
"
>=
"
,
d
ate
),
(
"
company_id
"
,
"
=
"
,
company_id
),
]
)
if
not
result
:
...
...
@@ -118,9 +120,13 @@
(
"
company_id
"
,
"
=
"
,
company_id
),
]
)
if
not
result
:
if
create
:
self
.
env
[
"
account.fiscalyear
"
].
find
(
date
,
True
)
return
self
.
find
(
date
,
False
)
action
=
self
.
env
.
ref
(
"
account_period.redirect_warning_account_period_action
"
)
...
...
@@ -129,7 +135,7 @@
"
There is no period defined for this date: %s.
\n
"
"
Please go to Configuration/Periods.
"
)
%
d
t
%
d
ate
)
raise
exceptions
.
RedirectWarning
(
...
...
This diff is collapsed.
Click to expand it.
Vincent Hatakeyama
@vincent.hatakeyama
mentioned in commit
5e50f1d52be7
·
3 years ago
mentioned in commit
5e50f1d52be7
mentioned in commit 5e50f1d52be7d5565e8209bfb65266638b01fcbf
Toggle commit list
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment