Browse Source

[FIX] b_shift : attendance sheet compensation_nb onchange issues

The @api.onchange, modifying compensation_nb according to working mode,
led to strange behavior and lack of consistency.

compensation_nb has consequently moved in Shift Stage.
pull/143/head
Elouan Le Bars 4 years ago
parent
commit
21fe68d0f5
  1. 47
      beesdoo_shift/models/attendance_sheet.py
  2. 9
      beesdoo_shift/views/attendance_sheet.xml

47
beesdoo_shift/models/attendance_sheet.py

@ -30,7 +30,13 @@ class AttendanceSheetShift(models.AbstractModel):
ondelete="cascade",
)
stage = fields.Selection(
[("present", "Present"), ("absent", "Absent"), ("cancelled", "Cancelled")],
[
("present", "Present"),
("absent_0", "Absent / 0 Compensation"),
("absent_1", "Absent / 1 Compensation"),
("absent_2", "Absent / 2 Compensations"),
("cancelled", "Cancelled"),
],
string="Shift Stage",
)
@ -64,13 +70,12 @@ class AttendanceSheetShift(models.AbstractModel):
if self.working_mode == "regular":
if self.stage == "present":
return "done"
if self.stage == "absent" and self.compensation_nb:
if self.compensation_nb == "0":
return "excused_necessity"
if self.compensation_nb == "1":
return "excused"
if self.compensation_nb == "2":
return "absent"
if self.stage == "absent_0":
return "excused_necessity"
if self.stage == "absent_1":
return "excused"
if self.stage == "absent_2":
return "absent"
if self.stage == "cancelled":
return "cancel"
if self.working_mode == "irregular":
@ -86,11 +91,6 @@ class AttendanceSheetShiftExpected(models.Model):
_description = "Expected Shift"
_inherit = ["beesdoo.shift.sheet.shift"]
compensation_nb = fields.Selection(
[("0", "0"), ("1", "1"), ("2", "2")],
string="Compensations (if absent)",
)
replacement_worker_id = fields.Many2one(
"res.partner",
string="Replacement Worker",
@ -101,20 +101,6 @@ class AttendanceSheetShiftExpected(models.Model):
],
)
# The webclient has display issues with this method.
@api.onchange("stage")
def on_change_stage(self):
if self.working_mode == "irregular":
if self.stage == "present" or "cancelled":
self.compensation_nb = False
if self.stage == "absent":
self.compensation_nb = "1"
if self.working_mode == "regular":
if self.stage == "present" or "cancelled":
self.compensation_nb = False
if self.stage == "absent":
self.compensation_nb = "2"
class AttendanceSheetShiftAdded(models.Model):
"""The added shifts stage must be Present
@ -330,9 +316,9 @@ class AttendanceSheet(models.Model):
task_templates = set()
for task in tasks:
if task.working_mode == "irregular":
compensation_nb = "1"
stage = "absent_1"
else:
compensation_nb = "2"
stage = "absent_2"
if task.worker_id:
new_expected_shift = expected_shift.create(
{
@ -341,8 +327,7 @@ class AttendanceSheet(models.Model):
"worker_id": task.worker_id.id,
"replacement_worker_id": task.replaced_id.id,
"task_type_id": task.task_type_id.id,
"stage": "absent",
"compensation_nb": compensation_nb,
"stage": stage,
"working_mode": task.working_mode,
}
)

9
beesdoo_shift/views/attendance_sheet.xml

@ -7,7 +7,7 @@
<field name="model">beesdoo.shift.sheet.expected</field>
<field name="arch" type="xml">
<tree editable="bottom" create="false" delete="false" open="false"
decoration-danger="stage == 'absent'"
decoration-danger="stage == 'absent_0' or stage == 'absent_1' or stage == 'absent_2'"
decoration-success="stage == 'present'">
<field name="task_type_id" readonly="True" options="{'no_open': True}"/>
<field name="worker_id" readonly="True" options="{'no_open': True}"/>
@ -16,12 +16,7 @@
attrs="{'readonly':
[('working_mode','=','irregular')]}"
options="{'no_create': True, 'no_create_edit':True}"/>
<field name="stage" />
<field name="compensation_nb"
attrs="{'readonly':
['|',
('working_mode','=','irregular'),
('stage','in',['present','cancelled'])]}"/>
<field name="stage"/>
</tree>
</field>
</record>

Loading…
Cancel
Save