Browse Source

[ADD] b_shift : attendance sheet, is_compensation field for expected shifts

pull/125/head
Elouan Le Bars 5 years ago
parent
commit
6c3fd766f9
  1. 43
      beesdoo_shift/models/attendance_sheet.py
  2. 4
      beesdoo_shift/tests/test_attendance_sheet.py
  3. 19
      beesdoo_shift/views/attendance_sheet.xml
  4. 4
      beesdoo_shift/wizard/validate_attendance_sheet.py

43
beesdoo_shift/models/attendance_sheet.py

@ -59,7 +59,11 @@ class AttendanceSheetShift(models.AbstractModel):
working_mode = fields.Selection( working_mode = fields.Selection(
related="worker_id.working_mode", string="Working Mode" related="worker_id.working_mode", string="Working Mode"
) )
# The two exclusive booleans are gathered in a simple one
is_compensation = fields.Boolean(
string="Compensation shift ?",
help="Only for regular workers"
)
def get_actual_stage(self): def get_actual_stage(self):
""" """
Mapping function returning the actual id Mapping function returning the actual id
@ -111,21 +115,12 @@ class AttendanceSheetShiftAdded(models.Model):
_description = "Added Shift" _description = "Added Shift"
_inherit = ["beesdoo.shift.sheet.shift"] _inherit = ["beesdoo.shift.sheet.shift"]
# The two exclusive booleans are gathered in a selection field
regular_task_type = fields.Selection(
[("normal", "Normal"), ("compensation", "Compensation")],
string="Task Mode (if regular)",
help="Shift type for regular workers. ",
)
stage = fields.Selection(default="present") stage = fields.Selection(default="present")
@api.onchange("working_mode") @api.onchange("working_mode")
def on_change_working_mode(self): def on_change_working_mode(self):
self.stage = "present" self.stage = "present"
if self.working_mode == "regular":
self.regular_task_type = "compensation"
if self.working_mode == "irregular":
self.regular_task_type = False
self.is_compensation = self.working_mode == "regular"
class AttendanceSheet(models.Model): class AttendanceSheet(models.Model):
@ -330,10 +325,7 @@ class AttendanceSheet(models.Model):
_("%s was expected as replaced.") % worker.name _("%s was expected as replaced.") % worker.name
) )
if worker.working_mode == "regular":
regular_task_type = "compensation"
else:
regular_task_type = False
is_compensation = (worker.working_mode == "regular")
added_ids = map(lambda s: s.worker_id.id, self.added_shift_ids) added_ids = map(lambda s: s.worker_id.id, self.added_shift_ids)
if worker.id in added_ids: if worker.id in added_ids:
@ -345,7 +337,7 @@ class AttendanceSheet(models.Model):
"stage": "present", "stage": "present",
"attendance_sheet_id": self._origin.id, "attendance_sheet_id": self._origin.id,
"worker_id": worker.id, "worker_id": worker.id,
"regular_task_type": regular_task_type,
"is_compensation": is_compensation,
} }
) )
@ -385,6 +377,7 @@ class AttendanceSheet(models.Model):
"task_type_id": task.task_type_id.id, "task_type_id": task.task_type_id.id,
"stage": stage, "stage": stage,
"working_mode": task.working_mode, "working_mode": task.working_mode,
"is_compensation": task.is_compensation,
} }
) )
# Maximum number of workers calculation (count empty shifts) # Maximum number of workers calculation (count empty shifts)
@ -437,14 +430,6 @@ class AttendanceSheet(models.Model):
_("Working mode is missing for %s") _("Working mode is missing for %s")
% added_shift.worker_id.name % added_shift.worker_id.name
) )
if (
added_shift.worker_id.working_mode == "regular"
and not added_shift.regular_task_type
):
raise UserError(
_("Regular Task Type is missing for %s")
% added_shift.worker_id.name
)
for expected_shift in self.expected_shift_ids: for expected_shift in self.expected_shift_ids:
if not expected_shift.stage: if not expected_shift.stage:
@ -476,7 +461,7 @@ class AttendanceSheet(models.Model):
"beesdoo_shift.%s" % added_shift.get_actual_stage() "beesdoo_shift.%s" % added_shift.get_actual_stage()
) )
is_regular_worker = added_shift.worker_id.working_mode == "regular" is_regular_worker = added_shift.worker_id.working_mode == "regular"
is_regular_shift = added_shift.regular_task_type == "normal"
is_compensation = added_shift.is_compensation
# Edit a non-assigned shift or create one if none # Edit a non-assigned shift or create one if none
non_assigned_shifts = shift.search( non_assigned_shifts = shift.search(
@ -496,8 +481,8 @@ class AttendanceSheet(models.Model):
"stage_id": actual_stage.id, "stage_id": actual_stage.id,
"worker_id": added_shift.worker_id.id, "worker_id": added_shift.worker_id.id,
"stage_id": actual_stage.id, "stage_id": actual_stage.id,
"is_regular": is_regular_shift and is_regular_worker,
"is_compensation": not is_regular_shift
"is_regular": not is_compensation and is_regular_worker,
"is_compensation": is_compensation
and is_regular_worker, and is_regular_worker,
} }
) )
@ -510,8 +495,8 @@ class AttendanceSheet(models.Model):
"start_time": self.start_time, "start_time": self.start_time,
"end_time": self.end_time, "end_time": self.end_time,
"stage_id": actual_stage.id, "stage_id": actual_stage.id,
"is_regular": is_regular_shift and is_regular_worker,
"is_compensation": not is_regular_shift
"is_regular": not is_compensation and is_regular_worker,
"is_compensation": is_compensation
and is_regular_worker, and is_regular_worker,
} }
) )

4
beesdoo_shift/tests/test_attendance_sheet.py

@ -282,9 +282,9 @@ class TestAttendanceSheet(TransactionCase):
self.attendance_sheet_shift_model.default_task_type_id(), self.attendance_sheet_shift_model.default_task_type_id(),
) )
if shift.working_mode == "regular": if shift.working_mode == "regular":
self.assertEquals(shift.regular_task_type, "compensation")
self.assertTrue(shift.is_compensation)
else: else:
self.assertFalse(shift.regular_task_type)
self.assertFalse(shift.is_compensation)
# add a worker that should be replaced # add a worker that should be replaced
with self.assertRaises(UserError) as e: with self.assertRaises(UserError) as e:

19
beesdoo_shift/views/attendance_sheet.xml

@ -40,7 +40,13 @@
attrs="{'readonly': attrs="{'readonly':
[('working_mode','=','irregular')]}" [('working_mode','=','irregular')]}"
options="{'no_create': True, 'no_create_edit':True}"/> options="{'no_create': True, 'no_create_edit':True}"/>
<field name="stage"/>
<field name="state" options="{'no_open': True}" />
<field name="compensation_no"
options="{'horizontal': true}"
attrs="{
'invisible': [('state', 'in', ['done', False])]
}"
/>
</tree> </tree>
</field> </field>
</record> </record>
@ -57,8 +63,8 @@
<field name="worker_id" <field name="worker_id"
options="{'no_open': True, 'no_create': True, 'no_create_edit':True }" /> options="{'no_open': True, 'no_create': True, 'no_create_edit':True }" />
<field name="working_mode" /> <field name="working_mode" />
<field name="regular_task_type"
attrs="{'readonly':
<field name="is_compensation"
attrs="{'invisible':
[('working_mode','=','irregular')]}"/> [('working_mode','=','irregular')]}"/>
<field name="stage" readonly="True" /> <field name="stage" readonly="True" />
</tree> </tree>
@ -92,8 +98,11 @@
<field name="task_type_id" options="{'no_open': True}" /> <field name="task_type_id" options="{'no_open': True}" />
<field name="worker_id" options="{'no_open': True}" /> <field name="worker_id" options="{'no_open': True}" />
<field name="working_mode" options="{'no_open': True}" /> <field name="working_mode" options="{'no_open': True}" />
<field name="regular_task_type" options="{'no_open': True}" />
<field name="stage" options="{'no_open': True}" />
<field name="is_compensation" options="{'no_open': True}"
attrs="{'readonly':
[('working_mode','=','irregular')]}"
/>
<field name="state" options="{'no_open': True}" />
</group> </group>
</form> </form>
</field> </field>

4
beesdoo_shift/wizard/validate_attendance_sheet.py

@ -23,9 +23,9 @@ class ValidateAttendanceSheet(models.TransientModel):
for added_shift in sheet.added_shift_ids: for added_shift in sheet.added_shift_ids:
is_regular_worker = added_shift.worker_id.working_mode == "regular" is_regular_worker = added_shift.worker_id.working_mode == "regular"
is_regular_shift = added_shift.regular_task_type == "normal"
is_compensation = added_shift.is_compensation
if is_regular_shift and is_regular_worker:
if is_regular_worker and not is_compensation:
warning_message += ( warning_message += (
_( _(
"Warning : %s attended its shift as a normal one but was not expected. " "Warning : %s attended its shift as a normal one but was not expected. "

Loading…
Cancel
Save