From 26cb9edae5e335310dfdc5d2d62c50f053830080 Mon Sep 17 00:00:00 2001 From: Elouan Le Bars Date: Mon, 25 Nov 2019 19:22:33 +0100 Subject: [PATCH] [FIX] b_shift : attendance sheet scanning methods --- beesdoo_shift/models/attendance_sheet.py | 43 +++++++++++++++++-- beesdoo_shift/views/attendance_sheet.xml | 37 ++++++++-------- .../wizard/validate_attendance_sheet.py | 20 ++++++++- .../wizard/validate_attendance_sheet.xml | 26 ++++++++--- 4 files changed, 96 insertions(+), 30 deletions(-) diff --git a/beesdoo_shift/models/attendance_sheet.py b/beesdoo_shift/models/attendance_sheet.py index 5675cd5..53b579c 100644 --- a/beesdoo_shift/models/attendance_sheet.py +++ b/beesdoo_shift/models/attendance_sheet.py @@ -119,6 +119,7 @@ class AttendanceSheetShiftAdded(models.Model): ) stage = fields.Selection(default="present") + # WARNING: check the code, readonly fields modified by onchange are not inserted on write @api.onchange("working_mode") def on_change_working_mode(self): self.stage = "present" @@ -205,7 +206,7 @@ class AttendanceSheet(models.Model): [ ("not_enough", "Not enough"), ("enough", "Enough"), - ("too much", "Too much"), + ("too_many", "Too many"), ], string="Feedback regarding the number of workers.", track_visibility="onchange", @@ -481,8 +482,42 @@ class AttendanceSheet(models.Model): } def on_barcode_scanned(self, barcode): - import pdb - pdb.set_trace() + if self.state == "validated": + raise UserError( + "You cannot modify a validated attendance sheet." + ) + worker = self.env["res.partner"].search([("barcode", "=", barcode)]) - self.name = barcode + if not len(worker): + raise UserError("Worker not found (invalid barcode or status).") + if len(worker) > 1: + raise UserError("Multiple workers corresponding to barcode.") + + if worker.state in ("unsubscribed", "resigning"): + raise UserError("Worker is %s." % worker.state) + if worker.working_mode not in ("regular", "irregular"): + raise UserError("Worker is %s and should be regular or irregular." % worker.working_mode) + + for id in self.expected_shift_ids.ids: + shift = self.env["beesdoo.shift.sheet.expected"].browse(id) + if shift.worker_id == worker or shift.replacement_worker_id == worker: + shift.stage = "present" + return + + if worker.working_mode == "regular": + regular_task_type = "normal" + else: + regular_task_type = False + + added_ids = map(lambda s: s.worker_id.id, self.added_shift_ids) + if worker.id in added_ids: + raise UserError("Worker is already present.") + + self.added_shift_ids |= self.added_shift_ids.new({ + "task_type_id": self.added_shift_ids._default_task_type_id(), + "stage": "present", + "attendance_sheet_id": self._origin.id, + "worker_id": worker.id, + "regular_task_type": regular_task_type + }) diff --git a/beesdoo_shift/views/attendance_sheet.xml b/beesdoo_shift/views/attendance_sheet.xml index c2ab1b3..882562c 100644 --- a/beesdoo_shift/views/attendance_sheet.xml +++ b/beesdoo_shift/views/attendance_sheet.xml @@ -63,7 +63,7 @@ beesdoo.shift.sheet
- +