Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Cédric Le Ninivin
erp5
Commits
2d8aa8d7
Commit
2d8aa8d7
authored
Jan 16, 2018
by
Cédric Le Ninivin
Committed by
Cédric Le Ninivin
May 29, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Periodicity: Add factor on get Next Date to get previous date
parent
0440f12d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
20 deletions
+25
-20
product/ERP5/mixin/periodicity.py
product/ERP5/mixin/periodicity.py
+25
-20
No files found.
product/ERP5/mixin/periodicity.py
View file @
2d8aa8d7
...
...
@@ -128,51 +128,56 @@ class PeriodicityMixin:
def
_getTimezone
(
self
,
date
):
return
date
.
timezone
()
def
_getNextMonth
(
self
,
date
,
timezone
):
def
_getNextMonth
(
self
,
date
,
timezone
,
factor
):
year
=
date
.
year
()
month
=
date
.
month
()
if
month
==
12
:
if
month
==
12
and
factor
==
1
:
year
+=
1
month
=
1
el
se
:
el
if
factor
==
1
:
month
+=
1
elif
month
==
1
:
month
=
12
year
-=
1
else
:
month
-=
1
return
DateTime
(
year
,
month
,
1
,
0
,
0
,
0
,
timezone
)
def
_getNextDay
(
self
,
date
,
timezone
):
def
_getNextDay
(
self
,
date
,
timezone
,
factor
):
if
timezone
is
not
None
:
new_date
=
DateTime
(
date
.
timeTime
()
+
86400.0
,
timezone
)
new_date
=
DateTime
(
date
.
timeTime
()
+
(
86400.0
*
factor
)
,
timezone
)
else
:
new_date
=
DateTime
(
date
.
timeTime
()
+
86400.0
)
new_date
=
DateTime
(
date
.
timeTime
()
+
(
86400.0
*
factor
)
)
# Due to daylight savings, 24 hours later does not always mean that
# it's next day.
while
new_date
.
day
()
==
date
.
day
():
if
timezone
is
not
None
:
new_date
=
DateTime
(
new_date
.
timeTime
()
+
3600.0
,
timezone
)
new_date
=
DateTime
(
new_date
.
timeTime
()
+
(
3600.0
*
factor
)
,
timezone
)
else
:
new_date
=
DateTime
(
new_date
.
timeTime
()
+
3600.0
)
new_date
=
DateTime
(
new_date
.
timeTime
()
+
(
3600.0
*
factor
)
)
return
DateTime
(
new_date
.
year
(),
new_date
.
month
(),
new_date
.
day
(),
0
,
0
,
0
,
timezone
)
def
_getNextHour
(
self
,
date
,
timezone
):
def
_getNextHour
(
self
,
date
,
timezone
,
factor
):
if
timezone
is
not
None
:
new_date
=
DateTime
(
date
.
timeTime
()
+
3600.0
,
timezone
)
new_date
=
DateTime
(
date
.
timeTime
()
+
(
3600.0
*
factor
)
,
timezone
)
else
:
new_date
=
DateTime
(
date
.
timeTime
()
+
3600.0
)
new_date
=
DateTime
(
date
.
timeTime
()
+
(
3600.0
*
factor
)
)
return
DateTime
(
new_date
.
year
(),
new_date
.
month
(),
new_date
.
day
(),
new_date
.
hour
(),
0
,
0
,
timezone
)
def
_getNextMinute
(
self
,
date
,
timezone
):
def
_getNextMinute
(
self
,
date
,
timezone
,
factor
):
if
timezone
is
not
None
:
new_date
=
DateTime
(
date
.
timeTime
()
+
60.0
,
timezone
)
new_date
=
DateTime
(
date
.
timeTime
()
+
(
60.0
*
factor
)
,
timezone
)
else
:
new_date
=
DateTime
(
date
.
timeTime
()
+
60.0
)
new_date
=
DateTime
(
date
.
timeTime
()
+
(
60.0
*
factor
)
)
return
DateTime
(
new_date
.
year
(),
new_date
.
month
(),
new_date
.
day
(),
new_date
.
hour
(),
new_date
.
minute
(),
0
,
timezone
)
security
.
declareProtected
(
Permissions
.
AccessContentsInformation
,
'getNextPeriodicalDate'
)
def
getNextPeriodicalDate
(
self
,
current_date
,
next_start_date
=
None
):
def
getNextPeriodicalDate
(
self
,
current_date
,
next_start_date
=
None
,
factor
=
1
):
"""
Get the next date where this periodic event should start.
...
...
@@ -203,7 +208,7 @@ class PeriodicityMixin:
timezone
=
self
.
_getTimezone
(
next_start_date
)
previous_date
=
next_start_date
next_start_date
=
max
(
self
.
_getNextMinute
(
next_start_date
,
timezone
),
next_start_date
=
max
(
self
.
_getNextMinute
(
next_start_date
,
timezone
,
factor
),
current_date
)
# We'll try every date to check if they validate the periodicity
...
...
@@ -214,14 +219,14 @@ class PeriodicityMixin:
max_date
=
next_start_date
+
(
28
*
366
)
while
next_start_date
<
max_date
:
if
not
self
.
_validateMonth
(
next_start_date
):
next_start_date
=
self
.
_getNextMonth
(
next_start_date
,
timezone
)
next_start_date
=
self
.
_getNextMonth
(
next_start_date
,
timezone
,
factor
)
elif
not
(
self
.
_validateDay
(
next_start_date
)
and
self
.
_validateWeek
(
next_start_date
)):
next_start_date
=
self
.
_getNextDay
(
next_start_date
,
timezone
)
next_start_date
=
self
.
_getNextDay
(
next_start_date
,
timezone
,
factor
)
elif
not
self
.
_validateHour
(
next_start_date
):
next_start_date
=
self
.
_getNextHour
(
next_start_date
,
timezone
)
next_start_date
=
self
.
_getNextHour
(
next_start_date
,
timezone
,
factor
)
elif
not
self
.
_validateMinute
(
next_start_date
,
previous_date
):
next_start_date
=
self
.
_getNextMinute
(
next_start_date
,
timezone
)
next_start_date
=
self
.
_getNextMinute
(
next_start_date
,
timezone
,
factor
)
else
:
parts
=
list
(
next_start_date
.
parts
())
parts
[
5
]
=
previous_date
.
second
()
# XXX keep old behaviour
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment