Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] beesdoo_worker_status: Try not to apply penalty twice in a row #388

Merged
merged 9 commits into from
Jun 23, 2022
17 changes: 17 additions & 0 deletions beesdoo_worker_status/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ Worker status management specific to beescoop.
.. contents::
:local:

Changelog
=========

12.0.1.1.0 (2022-06-23)
**Features**

- Do not apply a penalty to irregular customers twice in a row. Best explained
through an example.

Imagine the following 'sr' of an irregular worker:

0 -> -2 (cron, penalty) -> -1 (work a shift) -> 0 (work another shift)
-> ??? (cron)

The last step should go to -1 instead of -2. The penalty should not be given
again until sr has reached 1. (`#388 <https://github.com/beescoop/obeesdoo/issues/388>`_)

Bug Tracker
===========

Expand Down
2 changes: 1 addition & 1 deletion beesdoo_worker_status/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"author": "Thibault Francois, Elouan Le Bars, Coop IT Easy SCRLfs",
"website": "https://github.com/beescoop/Obeesdoo",
"category": "Cooperative management",
"version": "12.0.1.0.0",
"version": "12.0.1.1.0",
"depends": ["beesdoo_base", "beesdoo_shift"],
"data": [],
"demo": ["demo/tasks.xml"],
Expand Down
13 changes: 13 additions & 0 deletions beesdoo_worker_status/migrations/12.0.1.1.0/post-migrate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# SPDX-FileCopyrightText: 2022 Coop IT Easy SCRLfs
#
# SPDX-License-Identifier: AGPL-3.0-or-later


def migrate(cr, version):
cr.execute(
"""
UPDATE cooperative_status
SET is_penalised_irregular = TRUE
WHERE sr < 0
"""
)
9 changes: 8 additions & 1 deletion beesdoo_worker_status/models/cooperative_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class CooperativeStatus(models.Model):

future_alert_date = fields.Date(compute="_compute_future_alert_date")
next_countdown_date = fields.Date(compute="_compute_next_countdown_date")
is_penalised_irregular = fields.Boolean(
string="Is Currently Penalised Irregular", default=False
)

@api.depends(
"today",
Expand Down Expand Up @@ -348,11 +351,15 @@ def _get_irregular_worker_domain(self, today):

def _change_irregular_counter(self):
if self.sr > 0:
if self.sr >= 1:
self.is_penalised_irregular = False
self.sr -= 1
elif self.alert_start_time:
elif self.alert_start_time or self.is_penalised_irregular:
self.sr -= 1
else:
self.sr -= 2
# Until sr is 1 or above, don't do another penalty.
self.is_penalised_irregular = True

##################################
# Internal Implementation #
Expand Down
13 changes: 13 additions & 0 deletions beesdoo_worker_status/readme/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
12.0.1.1.0 (2022-06-23)
**Features**

- Do not apply a penalty to irregular customers twice in a row. Best explained
through an example.

Imagine the following 'sr' of an irregular worker:

0 -> -2 (cron, penalty) -> -1 (work a shift) -> 0 (work another shift)
-> ??? (cron)

The last step should go to -1 instead of -2. The penalty should not be given
again until sr has reached 1. (`#388 <https://github.com/beescoop/obeesdoo/issues/388>`_)
36 changes: 26 additions & 10 deletions beesdoo_worker_status/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -372,42 +372,58 @@ <h1 class="title">Beescoop Worker Status manager</h1>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#bug-tracker" id="id1">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="id2">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="id3">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="id4">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="id5">Maintainers</a></li>
<li><a class="reference internal" href="#changelog" id="id2">Changelog</a></li>
<li><a class="reference internal" href="#bug-tracker" id="id3">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="id4">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="id5">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="id6">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="id7">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="changelog">
<h1><a class="toc-backref" href="#id2">Changelog</a></h1>
<p>12.0.1.1.0 (2022-06-23)
<strong>Features</strong></p>
<ul>
<li><p class="first">Do not apply a penalty to irregular customers twice in a row. Best explained
through an example.</p>
<p>Imagine the following ‘sr’ of an irregular worker:</p>
<p>0 -&gt; -2 (cron, penalty) -&gt; -1 (work a shift) -&gt; 0 (work another shift)
-&gt; ??? (cron)</p>
<p>The last step should go to -1 instead of -2. The penalty should not be given
again until sr has reached 1. (<a class="reference external" href="https://github.com/beescoop/obeesdoo/issues/388">#388</a>)</p>
</li>
</ul>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#id1">Bug Tracker</a></h1>
<h1><a class="toc-backref" href="#id3">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/beescoop/obeesdoo/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/beescoop/obeesdoo/issues/new?body=module:%20beesdoo_worker_status%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h1><a class="toc-backref" href="#id2">Credits</a></h1>
<h1><a class="toc-backref" href="#id4">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#id3">Authors</a></h2>
<h2><a class="toc-backref" href="#id5">Authors</a></h2>
<ul class="simple">
<li>Thibault Francois</li>
<li>Elouan Le Bars</li>
<li>Coop IT Easy SCRLfs</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#id4">Contributors</a></h2>
<h2><a class="toc-backref" href="#id6">Contributors</a></h2>
<ul class="simple">
<li>Beescoop - Cellule IT</li>
<li>Coop IT Easy SCRLfs</li>
</ul>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#id5">Maintainers</a></h2>
<h2><a class="toc-backref" href="#id7">Maintainers</a></h2>
<p>This module is part of the <a class="reference external" href="https://github.com/beescoop/obeesdoo/tree/12.0/beesdoo_worker_status">beescoop/obeesdoo</a> project on GitHub.</p>
<p>You are welcome to contribute.</p>
</div>
Expand Down
50 changes: 50 additions & 0 deletions beesdoo_worker_status/tests/test_beesdoo_shift.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,56 @@ def test_shift_counters(self):
shift_irregular.state = "absent_2"
self.assertEqual(status_3.sr, -1)

def test_shift_no_double_penalty(self):
"""Imagine the following 'sr' of an irregular worker:

0 -> -2 (cron, penalty) -> -1 (work a shift) -> 0 (work another shift)
-> ??? (cron)

The last step should go to -1 instead of -2. The penalty should not be
given again until sr has reached 1.
"""
worker = self.worker_irregular_1
worker.cooperative_status_ids.sr = 0
self.assertFalse(worker.cooperative_status_ids.is_penalised_irregular)
worker.cooperative_status_ids._change_irregular_counter()
self.assertEqual(worker.cooperative_status_ids.sr, -2)
self.assertTrue(worker.cooperative_status_ids.is_penalised_irregular)
shift_irregular_1 = self.shift_model.create(
{
"task_template_id": self.task_template_1.id,
"task_type_id": self.task_type_3.id,
"worker_id": worker.id,
"start_time": datetime.now() - timedelta(days=7, minutes=15),
"end_time": datetime.now() - timedelta(days=7, minutes=10),
}
)
shift_irregular_1.state = "done"
self.assertEqual(worker.cooperative_status_ids.sr, -1)
self.assertTrue(worker.cooperative_status_ids.is_penalised_irregular)
shift_irregular_2 = self.shift_model.create(
{
"task_template_id": self.task_template_2.id,
"task_type_id": self.task_type_3.id,
"worker_id": worker.id,
"start_time": datetime.now() - timedelta(days=6, minutes=15),
"end_time": datetime.now() - timedelta(days=6, minutes=10),
}
)
shift_irregular_2.state = "done"
self.assertEqual(worker.cooperative_status_ids.sr, 0)
self.assertTrue(worker.cooperative_status_ids.is_penalised_irregular)
worker.cooperative_status_ids._change_irregular_counter()
self.assertEqual(worker.cooperative_status_ids.sr, -1)
self.assertTrue(worker.cooperative_status_ids.is_penalised_irregular)
worker.cooperative_status_ids.sr = 1
worker.cooperative_status_ids._change_irregular_counter()
self.assertEqual(worker.cooperative_status_ids.sr, 0)
self.assertFalse(worker.cooperative_status_ids.is_penalised_irregular)
worker.cooperative_status_ids._change_irregular_counter()
self.assertEqual(worker.cooperative_status_ids.sr, -2)
self.assertTrue(worker.cooperative_status_ids.is_penalised_irregular)

def test_postponed_alert_start_time_holiday_regular(self):
"""
Check that alert_start_time is correctly postponed when
Expand Down