Commit 17c6354c by Renaud Dufour

Enable updating shift start and end times.

parent a5b7181d
......@@ -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,8 +100,39 @@ class UpdateShiftsWizard(models.TransientModel):
if 'shift_ticket_ids' in vals.keys():
special = ['shift_ticket_ids']
del vals['shift_ticket_ids']
shift_obj.browse(shift_ids).with_context(
tracking_disable=True, special=special).write(vals)
# 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 = ""
return True
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment