Browse Source

[FIX] b_shift : attendance sheet scanning methods

pull/143/head
Elouan Le Bars 4 years ago
parent
commit
d97b1ab170
  1. 43
      beesdoo_shift/models/attendance_sheet.py
  2. 37
      beesdoo_shift/views/attendance_sheet.xml
  3. 20
      beesdoo_shift/wizard/validate_attendance_sheet.py
  4. 26
      beesdoo_shift/wizard/validate_attendance_sheet.xml

43
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
})

37
beesdoo_shift/views/attendance_sheet.xml

@ -63,7 +63,7 @@
<field name="model">beesdoo.shift.sheet</field>
<field name="arch" type="xml">
<form create="false" delete="false">
<field name="_barcode_scanned" widget="barcode_handler"/>
<header>
<field name="state" widget="statusbar" readonly="True" />
<button type="object"
@ -92,25 +92,26 @@
<group>
<field name="max_worker_nb" />
</group>
<h2> Expected workers </h2>
<group>
<field name="expected_worker_nb" />
<group col="1" string="Expected workers">
<group>
<field name="expected_worker_nb" />
</group>
<field name="expected_shift_ids"/>
</group>
<field name="expected_shift_ids"/>
<h2> Added workers </h2>
<group>
<field name="added_worker_nb" />
<group col="1" string="Added workers">
<group>
<field name="added_worker_nb" />
</group>
<field name="added_shift_ids" />
</group>
<field name="added_shift_ids" />
<h4> Additional important informations </h4>
<field name="annotation" barcode_events="true"/>
<h4> General feedback </h4>
<field name="feedback" />
<field name="worker_nb_feedback" >
<field name="_barcode_scanned" widget="barcode_handler"/>
</field>
<group>
<field name="validated_by" readonly="True" />
<group col="1" string="Informations"
groups="beesdoo_shift.group_cooperative_admin">
<field name="annotation" />
<field name="feedback" />
<field name="worker_nb_feedback" />
<group>
<field name="validated_by" readonly="True"/>
</group>
</group>
</sheet>
<div class="oe_chatter">

20
beesdoo_shift/wizard/validate_attendance_sheet.py

@ -9,7 +9,22 @@ class ValidateAttendanceSheet(models.TransientModel):
Useless for users in group_cooperative_admin"""
_inherit = ["barcodes.barcode_events_mixin"]
barcode = fields.Char("Barcode Scanned", required=True)
barcode = fields.Char(string="Barcode", required=True)
annotation = fields.Text(
"Important information requiring permanent member assistance", default=""
)
feedback = fields.Text(
"General feedback"
)
worker_nb_feedback = fields.Selection(
[
("not_enough", "Not enough"),
("enough", "Enough"),
("too_many", "Too many"),
],
string="Number of workers",
required=True
)
@api.multi
def validate_sheet(self):
@ -26,6 +41,9 @@ class ValidateAttendanceSheet(models.TransientModel):
raise UserError(
"Only super-cooperators and administrators can validate attendance sheets."
)
sheet.annotation = self.annotation
sheet.feedback = self.feedback
sheet.worker_nb_feedback = self.worker_nb_feedback
sheet.validated_by = user
sheet.validate()

26
beesdoo_shift/wizard/validate_attendance_sheet.xml

@ -4,13 +4,25 @@
<field name="model">beesdoo.shift.sheet.validate</field>
<field name="arch" type="xml">
<form>
<label string="Beware : a validated sheet cannot be edited anymore and you won't be able to add any latecomers.
Emails will be sent to workers who did not attend their shift." />
<field name="_barcode_scanned" widget="barcode_handler"/>
<group>
<field name="barcode" />
</group>
<sheet>
<div class="oe_title">
<h1>Validation</h1>
</div>
<label string="Beware : a validated sheet cannot be edited anymore
and you won't be able to add any latecomers.
Emails will be sent to workers who did not attend their shift." />
<field name="_barcode_scanned" widget="barcode_handler"/>
<group col="1" string="Additionnal informations" >
<field name="annotation" />
<field name="feedback" />
</group>
<group>
<field name="worker_nb_feedback" />
</group>
<group string="Scan your barcode">
<field name="barcode" />
</group>
</sheet>
<footer>
<button type="object" name="validate_sheet"
string="Confirm" class="oe_highlight" />

Loading…
Cancel
Save