Browse Source

[REF] b_shift : remove state computation for attendance shifts

replacement_worker_id -> replaced_id
pull/143/head
Elouan Le Bars 5 years ago
parent
commit
f6b18e7f2b
  1. 4
      beesdoo_shift/i18n/fr.po
  2. 4
      beesdoo_shift/i18n/fr_BE.po
  3. 4
      beesdoo_shift/i18n/nl_BE.po
  4. 11
      beesdoo_shift/models/__init__.py
  5. 89
      beesdoo_shift/models/attendance_sheet.py
  6. 1
      beesdoo_shift/security/ir.model.access.csv
  7. 14
      beesdoo_shift/tests/test_beesdoo_shift.py
  8. 14
      beesdoo_shift/views/attendance_sheet.xml

4
beesdoo_shift/i18n/fr.po

@ -1692,12 +1692,12 @@ msgid "Replaced id"
msgstr "Id du remplaçant"
#. module: beesdoo_shift
#: model:ir.model.fields,field_description:beesdoo_shift.field_beesdoo_shift_sheet_expected_replacement_worker_id
#: model:ir.model.fields,field_description:beesdoo_shift.field_beesdoo_shift_sheet_expected_replaced_id
msgid "Replacement Worker"
msgstr "Travailleur remplaçant"
#. module: beesdoo_shift
#: model:ir.model.fields,help:beesdoo_shift.field_beesdoo_shift_sheet_expected_replacement_worker_id
#: model:ir.model.fields,help:beesdoo_shift.field_beesdoo_shift_sheet_expected_replaced_id
msgid "Replacement Worker (must be regular)"
msgstr "Travailleur remplaçant (doit être régulier)"

4
beesdoo_shift/i18n/fr_BE.po

@ -1692,12 +1692,12 @@ msgid "Replaced id"
msgstr "Id du remplaçant"
#. module: beesdoo_shift
#: model:ir.model.fields,field_description:beesdoo_shift.field_beesdoo_shift_sheet_expected_replacement_worker_id
#: model:ir.model.fields,field_description:beesdoo_shift.field_beesdoo_shift_sheet_expected_replaced_id
msgid "Replacement Worker"
msgstr "Travailleur remplaçant"
#. module: beesdoo_shift
#: model:ir.model.fields,help:beesdoo_shift.field_beesdoo_shift_sheet_expected_replacement_worker_id
#: model:ir.model.fields,help:beesdoo_shift.field_beesdoo_shift_sheet_expected_replaced_id
msgid "Replacement Worker (must be regular)"
msgstr "Travailleur remplaçant (doit être régulier)"

4
beesdoo_shift/i18n/nl_BE.po

@ -1696,12 +1696,12 @@ msgid "Replaced id"
msgstr "Replaced id"
#. module: beesdoo_shift
#: model:ir.model.fields,field_description:beesdoo_shift.field_beesdoo_shift_sheet_expected_replacement_worker_id
#: model:ir.model.fields,field_description:beesdoo_shift.field_beesdoo_shift_sheet_expected_replaced_id
msgid "Replacement Worker"
msgstr "Vervangingswerker"
#. module: beesdoo_shift
#: model:ir.model.fields,help:beesdoo_shift.field_beesdoo_shift_sheet_expected_replacement_worker_id
#: model:ir.model.fields,help:beesdoo_shift.field_beesdoo_shift_sheet_expected_replaced_id
msgid "Replacement Worker (must be regular)"
msgstr "Vervangingswerker (regelmatig werkregime vereist)"

11
beesdoo_shift/models/__init__.py

@ -1,5 +1,6 @@
from . import attendance_sheet
from . import planning
from . import res_config_settings
from . import task
from . import cooperative_status
# -*- coding: utf-8 -*-
import task
import attendance_sheet
import planning
import res_config
import cooperative_status

89
beesdoo_shift/models/attendance_sheet.py

@ -1,6 +1,4 @@
import unittest
from datetime import date, datetime, timedelta
from lxml import etree
@ -17,7 +15,11 @@ class AttendanceSheetShift(models.AbstractModel):
@api.model
def task_type_default_id(self):
parameters = self.env["ir.config_parameter"].sudo()
id = int(parameters.get_param("beesdoo_shift.task_type_default_id", default=1))
id = int(
parameters.get_param(
"beesdoo_shift.default_task_type_id", default=1
)
)
task_types = self.env["beesdoo.shift.type"]
return task_types.browse(id)
@ -30,7 +32,12 @@ class AttendanceSheetShift(models.AbstractModel):
ondelete="cascade",
)
state = fields.Selection(
[("done", "Present"), ("absent", "Absent"),],
[
("done", "Present"),
("absent_0", "Absent - 0 Compensation"),
("absent_1", "Absent - 1 Compensation"),
("absent_2", "Absent - 2 Compensations"),
],
string="Shift State",
required=True,
)
@ -59,7 +66,7 @@ class AttendanceSheetShift(models.AbstractModel):
class AttendanceSheetShiftExpected(models.Model):
"""
Already existing shifts on sheet creation.
Shifts already expected.
"""
_name = "beesdoo.shift.sheet.expected"
@ -69,10 +76,7 @@ class AttendanceSheetShiftExpected(models.Model):
super_coop_id = fields.Many2one(
related="task_id.super_coop_id", store=True
)
compensation_no = fields.Selection(
[("0", "0"), ("1", "1"), ("2", "2"),], string="Compensations",
)
replacement_worker_id = fields.Many2one(
replaced_id = fields.Many2one(
"res.partner",
string="Replacement Worker",
help="Replacement Worker (must be regular)",
@ -83,29 +87,15 @@ class AttendanceSheetShiftExpected(models.Model):
],
)
@api.onchange("replacement_worker_id")
@api.onchange("replaced_id")
def on_change_replacement_worker(self):
if self.replacement_worker_id:
if self.replaced_id:
self.state = "done"
@api.onchange("state")
def on_change_state(self):
if not self.state or self.state == "done":
self.compensation_no = False
if self.state == "absent":
self.compensation_no = "2"
@api.constrains("state", "compensation_no")
def _constrain_compensation_no(self):
if self.state == "absent":
if not self.compensation_no:
raise UserError(_("A compensation number is required"))
class AttendanceSheetShiftAdded(models.Model):
"""
Not already registered shifts.
Added shifts are necessarily 'Present'
Shifts added during time slot.
"""
_name = "beesdoo.shift.sheet.added"
@ -177,7 +167,11 @@ class AttendanceSheet(models.Model):
readonly=True,
help="Indicative maximum number of workers.",
)
notes = fields.Text("Notes", default="", help="Notes about the attendance for the Members Office")
notes = fields.Text(
"Notes",
default="",
help="Notes about the attendance for the Members Office",
)
is_annotated = fields.Boolean(
compute="_compute_is_annotated",
string="Is annotated",
@ -285,9 +279,9 @@ class AttendanceSheet(models.Model):
added_ids = [s.worker_id.id for s in self.added_shift_ids]
expected_ids = [s.worker_id.id for s in self.expected_shift_ids]
replacement_ids = [
s.replacement_worker_id.id
s.replaced_id.id
for s in self.expected_shift_ids
if s.replacement_worker_id.id
if s.replaced_id.id
]
ids = added_ids + expected_ids + replacement_ids
@ -318,6 +312,7 @@ class AttendanceSheet(models.Model):
)
worker = self.env["res.partner"].search([("barcode", "=", barcode)])
if not len(worker):
raise UserError(
_(
@ -364,11 +359,11 @@ class AttendanceSheet(models.Model):
for id in self.expected_shift_ids.ids:
shift = self.env["beesdoo.shift.sheet.expected"].browse(id)
if (
shift.worker_id == worker and not shift.replacement_worker_id
) or shift.replacement_worker_id == worker:
shift.worker_id == worker and not shift.replaced_id
) or shift.replaced_id == worker:
shift.state = "done"
return
if shift.worker_id == worker and shift.replacement_worker_id:
if shift.worker_id == worker and shift.replaced_id:
raise UserError(
_("%s was expected as replaced.") % worker.name
)
@ -416,10 +411,9 @@ class AttendanceSheet(models.Model):
"attendance_sheet_id": new_sheet.id,
"task_id": task.id,
"worker_id": task.worker_id.id,
"replacement_worker_id": task.replaced_id.id,
"replaced_id": task.replaced_id.id,
"task_type_id": task.task_type_id.id,
"state": "absent",
"compensation_no": "2",
"state": "absent_2",
"working_mode": task.working_mode,
"is_compensation": task.is_compensation,
}
@ -453,19 +447,10 @@ class AttendanceSheet(models.Model):
# Expected shifts status update
for expected_shift in self.expected_shift_ids:
actual_shift = expected_shift.task_id
# Merge state with compensations number to fit Task model
if (
expected_shift.state == "absent"
and expected_shift.compensation_no
):
state_converted = "absent_%s" % expected_shift.compensation_no
else:
state_converted = expected_shift.state
actual_shift.replaced_id = expected_shift.replacement_worker_id
actual_shift.state = state_converted
actual_shift.replaced_id = expected_shift.replaced_id
actual_shift.state = expected_shift.state
if expected_shift.state == "absent":
if expected_shift.state != "done":
mail_template = self.env.ref(
"beesdoo_shift.email_template_non_attendance", False
)
@ -509,10 +494,8 @@ class AttendanceSheet(models.Model):
{
"state": added_shift.state,
"worker_id": added_shift.worker_id.id,
"is_regular": not is_compensation
and is_regular_worker,
"is_compensation": is_compensation
and is_regular_worker,
"is_regular": not is_compensation and is_regular_worker,
"is_compensation": is_compensation and is_regular_worker,
}
)
added_shift.task_id = actual_shift.id
@ -530,7 +513,9 @@ class AttendanceSheet(models.Model):
raise UserError(_("The sheet has already been validated."))
if self.start_time > datetime.now():
raise UserError(
_("Attendance sheet can only be validated once the shifts have started.")
_(
"Attendance sheet can only be validated once the shifts have started."
)
)
# Fields validation

1
beesdoo_shift/security/ir.model.access.csv

@ -2,6 +2,7 @@ id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink
create_beesdoo_shift_shift,create_edit_beesdoo_shift_shift,model_beesdoo_shift_shift,group_shift_attendance_sheet,1,1,1,0
read_beesdoo_shift_sheet_shift,read_beesdoo_shift_sheet_shift,model_beesdoo_shift_sheet_shift,group_shift_attendance_sheet,1,0,0,0
create_beesdoo_shift_sheet_shift,create_beesdoo_shift_sheet_shift,model_beesdoo_shift_sheet_shift,group_shift_attendance_sheet,1,1,1,0
create_beesdoo_shift_sheet_expected,create_beesdoo_shift_sheet_expected,model_beesdoo_shift_sheet_expected,group_shift_attendance_sheet,1,1,1,0
manage_beesdoo_shift_sheet_added,manage_beesdoo_shift_sheet_added,model_beesdoo_shift_sheet_added,group_shift_attendance_sheet,1,1,1,1
create_beesdoo_shift_sheet,create_beesdoo_shift_sheet,model_beesdoo_shift_sheet,group_shift_attendance_sheet,1,1,1,0

14
beesdoo_shift/tests/test_beesdoo_shift.py

@ -223,17 +223,16 @@ class TestBeesdooShift(TransactionCase):
# Test consistency with actual shift for sheet 1
for shift in sheet_1.expected_shift_ids:
self.assertEqual(shift.worker_id, shift.task_id.worker_id)
self.assertEqual(
shift.replacement_worker_id, shift.task_id.replaced_id
self.assertEquals(shift.worker_id, shift.task_id.worker_id)
self.assertEquals(
shift.replaced_id, shift.task_id.replaced_id
)
self.assertEqual(shift.task_type_id, shift.task_id.task_type_id)
self.assertEqual(shift.super_coop_id, shift.task_id.super_coop_id)
self.assertEqual(shift.working_mode, shift.task_id.working_mode)
# Status should be "absent" for all shifts
self.assertEqual(shift.state, "absent")
self.assertEqual(shift.compensation_no, "2")
self.assertEquals(shift.state, "absent_2")
# Empty shift should be considered in max worker number calculation
self.assertEqual(sheet_1.max_worker_no, 4)
@ -330,8 +329,7 @@ class TestBeesdooShift(TransactionCase):
# Expected shifts edition
sheet_1.expected_shift_ids[1].state = "done"
sheet_1.expected_shift_ids[1].compensation_no = False
sheet_1.expected_shift_ids[2].compensation_no = "1"
sheet_1.expected_shift_ids[2].state = "absent_1"
# Added shits addition
sheet_1.added_shift_ids |= sheet_1.added_shift_ids.new(
@ -408,7 +406,7 @@ class TestBeesdooShift(TransactionCase):
)
# sheet_1.expected_shift_ids[0].worker_id
# sheet_1.expected_shift_ids[2].replacement_worker_id
# sheet_1.expected_shift_ids[2].replaced_id
def test_shift_counters(self):
"Test shift counters calculation and cooperative status update"

14
beesdoo_shift/views/attendance_sheet.xml

@ -36,24 +36,18 @@
<field name="name">Expected Shifts List</field>
<field name="model">beesdoo.shift.sheet.expected</field>
<field name="arch" type="xml">
<tree editable="bottom" create="false" delete="false"
decoration-danger="state == 'absent'"
<tree editable="bottom" create="false" delete="false" open="false"
decoration-danger="state in ['absent_0', 'absent_1', 'absent_2'] "
decoration-success="state == 'done'">
<field name="task_type_id" readonly="True" options="{'no_open': True}"/>
<field name="super_coop_id" readonly="True" options="{'no_open': True}"/>
<field name="worker_id" readonly="True" options="{'no_open': True}"/>
<field name="working_mode" />
<field name="replacement_worker_id"
<field name="replaced_id"
attrs="{'readonly':
[('working_mode','=','irregular')]}"
options="{'no_create': True, 'no_create_edit':True}"/>
<field name="state" options="{'no_open': True}" />
<field name="compensation_no"
options="{'horizontal': true}"
attrs="{
'invisible': [('state', 'in', ['done', False])]
}"
/>
</tree>
</field>
</record>
@ -88,7 +82,7 @@
<field name="task_type_id" options="{'no_open': True}" />
<field name="worker_id" options="{'no_open': True}" />
<field name="working_mode" options="{'no_open': True}" />
<field name="replacement_worker_id" options="{'no_open': True}" />
<field name="replaced_id" options="{'no_open': True}" />
<field name="state" options="{'no_open': True}" />
</group>
</form>

Loading…
Cancel
Save