From 7ece3f34ede4b2ec32a6a5e3061c6ee4e5f7aa55 Mon Sep 17 00:00:00 2001 From: Elouan Le Bars Date: Wed, 11 Dec 2019 11:08:24 +0100 Subject: [PATCH] [IMP] b_shift : attendance annotation pre-filled on wizard --- beesdoo_shift/models/attendance_sheet.py | 13 +-------- .../wizard/validate_attendance_sheet.py | 28 ++++++++++++++++++- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/beesdoo_shift/models/attendance_sheet.py b/beesdoo_shift/models/attendance_sheet.py index 48522be..0e7aa99 100644 --- a/beesdoo_shift/models/attendance_sheet.py +++ b/beesdoo_shift/models/attendance_sheet.py @@ -478,18 +478,7 @@ class AttendanceSheet(models.Model): ) is_regular_worker = added_shift.worker_id.working_mode == "regular" is_regular_shift = added_shift.regular_task_type == "normal" - if is_regular_shift and is_regular_worker: - warning_message = ( - _( - "\nWarning : %s attended its shift as a normal one but was not expected." - " Something may be wrong in his/her personnal informations.\n" - ) - % added_shift.worker_id.name - ) - if self.annotation: - self.annotation += warning_message - else: - self.annotation = warning_message + # Edit a non-assigned shift or create one if none non_assigned_shifts = shift.search( [ diff --git a/beesdoo_shift/wizard/validate_attendance_sheet.py b/beesdoo_shift/wizard/validate_attendance_sheet.py index 3bec511..fb1e0b7 100644 --- a/beesdoo_shift/wizard/validate_attendance_sheet.py +++ b/beesdoo_shift/wizard/validate_attendance_sheet.py @@ -9,10 +9,36 @@ class ValidateAttendanceSheet(models.TransientModel): Useless for users in group_cooperative_admin""" _inherit = ["barcodes.barcode_events_mixin"] + @api.multi + def _default_annotation(self): + """ + The annotation is pre-filled with a warning message + if a regular worker is added and should have been expected. + """ + + sheet_id = self._context.get("active_id") + sheet_model = self._context.get("active_model") + sheet = self.env[sheet_model].browse(sheet_id) + warning_message = "" + + for added_shift in sheet.added_shift_ids: + is_regular_worker = added_shift.worker_id.working_mode == "regular" + is_regular_shift = added_shift.regular_task_type == "normal" + + if is_regular_shift and is_regular_worker: + warning_message += ( + _( + "Warning : %s attended its shift as a normal one but was not expected. " + "Something may be wrong in his/her personnal informations.\n\n" + ) + % added_shift.worker_id.name + ) + return warning_message + barcode = fields.Char(string="Barcode", required=True) annotation = fields.Text( "Important information requiring permanent member assistance", - default="", + default=_default_annotation, ) feedback = fields.Text("General feedback") worker_nb_feedback = fields.Selection(