Browse Source

[CHG] b_shift : checks on attendance sheet before validation

pull/125/head
Elouan Le Bars 5 years ago
parent
commit
ef7701c77f
  1. 86
      beesdoo_shift/models/attendance_sheet.py
  2. 5
      beesdoo_shift/views/attendance_sheet.xml
  3. 2
      beesdoo_shift/wizard/validate_attendance_sheet.py

86
beesdoo_shift/models/attendance_sheet.py

@ -399,50 +399,11 @@ class AttendanceSheet(models.Model):
return self.search_count(domain)
return
def validate(self, user):
def _validate(self, user):
self.ensure_one()
if self.state == "validated":
raise UserError("The sheet has already been validated.")
shift = self.env["beesdoo.shift.shift"]
# Fields validation
for added_shift in self.added_shift_ids:
if not added_shift.worker_id:
raise UserError(
_("Worker must be set for shift %s") % added_shift.id
)
if added_shift.state != "done":
raise UserError(
_("Shift State is missing or wrong for %s")
% added_shift.worker_id.name
)
if not added_shift.task_type_id:
raise UserError(
_("Task Type is missing for %s")
% added_shift.worker_id.name
)
if not added_shift.working_mode:
raise UserError(
_("Working mode is missing for %s")
% added_shift.worker_id.name
)
for expected_shift in self.expected_shift_ids:
if not expected_shift.state:
raise UserError(
_("Shift State is missing for %s")
% expected_shift.worker_id.name
)
if (
expected_shift.state == "absent"
and not expected_shift.compensation_no
):
raise UserError(
_("Compensation number is missing for %s")
% expected_shift.worker_id.name
)
# Expected shifts status update
for expected_shift in self.expected_shift_ids:
actual_shift = expected_shift.task_id
@ -514,10 +475,51 @@ class AttendanceSheet(models.Model):
return
@api.multi
def validate_via_wizard(self):
def validate_with_checks(self):
self.ensure_one()
if self.state == "validated":
raise UserError("The sheet has already been validated.")
# Fields validation
for added_shift in self.added_shift_ids:
if not added_shift.worker_id:
raise UserError(
_("Worker name is missing for an added shift.")
)
if added_shift.state != "done":
raise UserError(
_("Shift State is missing or wrong for %s")
% added_shift.worker_id.name
)
if not added_shift.task_type_id:
raise UserError(
_("Task Type is missing for %s")
% added_shift.worker_id.name
)
if not added_shift.working_mode:
raise UserError(
_("Working mode is missing for %s")
% added_shift.worker_id.name
)
for expected_shift in self.expected_shift_ids:
if not expected_shift.state:
raise UserError(
_("Shift State is missing for %s")
% expected_shift.worker_id.name
)
if (
expected_shift.state == "absent"
and not expected_shift.compensation_no
):
raise UserError(
_("Compensation number is missing for %s")
% expected_shift.worker_id.name
)
# open a validation wizard if not admin
if self.env.user.has_group("beesdoo_shift.group_cooperative_admin"):
self.validate(self.env.user.partner_id)
self._validate(self.env.user.partner_id)
return
return {
"type": "ir.actions.act_window",

5
beesdoo_shift/views/attendance_sheet.xml

@ -134,7 +134,7 @@
<div>
<field name="state" widget="statusbar" readonly="True" class="oe_inline"/>
<button type="object"
name="validate_via_wizard"
name="validate_with_checks"
string="Validate Sheet"
attrs="{'invisible': [('state', '=', 'validated')]}"
/>
@ -164,6 +164,9 @@
<group>
<field name="max_worker_no" />
</group>
<label string="If you encounter any issues, you can add an
annotation during validation to notify permanent members."
/>
<separator string="Added workers" />
<field name="added_shift_ids"/>
<separator string="Expected workers" />

2
beesdoo_shift/wizard/validate_attendance_sheet.py

@ -77,4 +77,4 @@ class ValidateAttendanceSheet(models.TransientModel):
if sheet.feedback:
sheet.feedback += self.feedback
sheet.worker_nb_feedback = self.worker_nb_feedback
sheet.validate(partner or self.env.user.partner_id)
sheet._validate(partner or self.env.user.partner_id)
Loading…
Cancel
Save