Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
odoo
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cooperatic-foodcoops
odoo
Commits
17c6354c
Commit
17c6354c
authored
Oct 19, 2021
by
Renaud Dufour
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable updating shift start and end times.
parent
a5b7181d
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
0 deletions
+32
-0
update_shifts_wizard.py
intercoop_addons/coop_shift/wizard/update_shifts_wizard.py
+32
-0
No files found.
intercoop_addons/coop_shift/wizard/update_shifts_wizard.py
View file @
17c6354c
...
...
@@ -20,6 +20,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from
datetime
import
datetime
from
openerp
import
models
,
fields
,
api
...
...
@@ -99,6 +100,37 @@ class UpdateShiftsWizard(models.TransientModel):
if
'shift_ticket_ids'
in
vals
.
keys
():
special
=
[
'shift_ticket_ids'
]
del
vals
[
'shift_ticket_ids'
]
# If the update contains 'start_datetime' or 'end_datetime',
# we need some custom logic to fix the shift start and end times.
# note: we do not touch the shift *dates* as this requires bigger changes in the module.
# See https://redmine.cooperatic.fr/issues/989
if
'start_datetime'
in
vals
or
'end_datetime'
in
vals
:
template_start_tz
=
datetime
.
strptime
(
wizard
.
template_id
.
start_datetime_tz
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
template_end_tz
=
datetime
.
strptime
(
wizard
.
template_id
.
end_datetime_tz
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
for
shift
in
shift_obj
.
browse
(
shift_ids
):
shift_vals
=
vals
.
copy
()
shift_begin_tz
=
datetime
.
strptime
(
shift
.
date_begin_tz
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
shift_end_tz
=
datetime
.
strptime
(
shift
.
date_end_tz
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
new_shift_begin_tz
=
shift_begin_tz
.
replace
(
hour
=
template_start_tz
.
hour
,
minute
=
template_start_tz
.
minute
,
second
=
template_start_tz
.
second
)
new_shift_end_tz
=
shift_end_tz
.
replace
(
hour
=
template_end_tz
.
hour
,
minute
=
template_end_tz
.
minute
,
second
=
template_end_tz
.
second
)
shift_vals
[
'date_begin_tz'
]
=
datetime
.
strftime
(
new_shift_begin_tz
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
shift_vals
[
'date_end_tz'
]
=
datetime
.
strftime
(
new_shift_end_tz
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
shift_vals
.
pop
(
'start_datetime'
,
None
)
shift_vals
.
pop
(
'end_datetime'
,
None
)
# Also update the name because it contains the start time
shift_vals
[
'name'
]
=
wizard
.
template_id
.
name
shift
.
with_context
(
tracking_disable
=
True
,
special
=
special
)
.
write
(
shift_vals
)
else
:
# If no time change, simply do the bulk update as before
shift_obj
.
browse
(
shift_ids
)
.
with_context
(
tracking_disable
=
True
,
special
=
special
)
.
write
(
vals
)
wizard
.
template_id
.
updated_fields
=
""
...
...
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