Commit e13b7bec by François C.

Merge branch 'renaud/989-shift-update-bug' into 'dev_cooperatic'

Renaud/989 shift update bug

See merge request !17
parents a5b7181d 7bb16375
......@@ -409,6 +409,13 @@ msgid "Cancelled"
msgstr "Annulé"
#. module: coop_shift
#: code:addons/coop_shift/model/shift_template.py:527
#: code:addons/coop_shift/model/shift_template.py:534
#, python-format
msgid "Cannot change the date of an existing shift template. Delete and create a new template instead."
msgstr "Il n'est pas possible de modifier la date d'un créneau existant. Vous pouvez modifier l'heure uniquement. Veuillez supprimer et créer un nouveau créneau pour modifier les dates."
#. module: coop_shift
#: model:ir.model.fields,field_description:coop_shift.field_shift_shift_event_type_id
#: model:ir.model.fields,field_description:coop_shift.field_shift_shift_shift_type_id
#: model:ir.model.fields,field_description:coop_shift.field_shift_template_shift_type_id
......@@ -1825,7 +1832,7 @@ msgstr "Participant(e)"
#: model:ir.ui.view,arch_db:coop_shift.view_shift_template_registration_line_search
#: model:ir.ui.view,arch_db:coop_shift.view_template_registration_search
msgid "Partner"
msgstr "Coopérateur
msgstr "Coopérateur"
#. module: coop_shift
#: model:ir.model.fields,field_description:coop_shift.field_shift_template_registration_line_is_past
......
......@@ -520,6 +520,20 @@ class ShiftTemplate(models.Model):
if 'updated_fields' not in vals.keys() and len(self.shift_ids):
vals['updated_fields'] = str(vals)
if 'start_datetime' in vals and self.start_datetime is not None:
new_date = datetime.date(datetime.strptime(vals['start_datetime'], "%Y-%m-%d %H:%M:%S"))
current_date = datetime.date(datetime.strptime(self.start_datetime, "%Y-%m-%d %H:%M:%S"))
if new_date != current_date:
raise UserError(_(
"Cannot change the date of an existing shift template. Delete and create a new template instead."))
if 'end_datetime' in vals and self.end_datetime is not None:
new_date = datetime.date(datetime.strptime(vals['end_datetime'], "%Y-%m-%d %H:%M:%S"))
current_date = datetime.date(datetime.strptime(self.end_datetime, "%Y-%m-%d %H:%M:%S"))
if new_date != current_date:
raise UserError(_(
"Cannot change the date of an existing shift template. Delete and create a new template instead."))
if 'user_ids' in vals and 'updated_fields' in vals \
and len(vals.keys()) <= 2:
self.update_shift(vals)
......
......@@ -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