forked from beescoop/Obeesdoo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] beesdoo_worker_status_shift_swap
- Loading branch information
Showing
9 changed files
with
214 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Copyright 2020 Coop IT Easy SCRL fs | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
|
||
{ | ||
"name": "Beescoop Worker Status manager for beesdoo_shift_swap", | ||
"summary": """Worker status management specific to shift exchanges.""", | ||
"author": "Coop IT Easy SCRLfs", | ||
"website": "https://github.com/beescoop/Obeesdoo", | ||
"category": "Cooperative management", | ||
"version": "12.0.1.0.0", | ||
"depends": ["beesdoo_shift_swap", "beesdoo_worker_status"], | ||
"license": "AGPL-3", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import solidarity_shift_request | ||
from . import task |
35 changes: 35 additions & 0 deletions
35
beesdoo_worker_status_shift_swap/models/solidarity_shift_request.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from odoo import fields, models | ||
|
||
|
||
class SolidarityShiftRequest(models.Model): | ||
_inherit = "beesdoo.shift.solidarity.request" | ||
|
||
def _get_personal_counter_status(self): | ||
return [ | ||
("not_modified", "Not modified"), | ||
("request_ok", "Request OK"), | ||
("cancel_ok", "Cancel OK"), | ||
] | ||
|
||
personal_counter_status = fields.Selection( | ||
selection=_get_personal_counter_status, default="not_modified" | ||
) | ||
|
||
def update_personal_counter(self): | ||
worker = self.worker_id | ||
if worker: | ||
if worker.working_mode == "irregular": | ||
if ( | ||
self.state == "validated" | ||
and self.personal_counter_status == "not_modified" | ||
): | ||
worker.cooperative_status_ids[0].sr += 1 | ||
self.personal_counter_status = "request_ok" | ||
elif ( | ||
self.state == "cancelled" | ||
and self.personal_counter_status == "request_ok" | ||
): | ||
worker.cooperative_status_ids[0].sr -= 1 | ||
self.personal_counter_status = "cancel_ok" | ||
return True | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# import json | ||
|
||
from odoo import models | ||
|
||
|
||
class Task(models.Model): | ||
_inherit = "beesdoo.shift.shift" | ||
|
||
def _get_counter_date_state_change(self, new_state): | ||
data, status = super(Task, self)._get_counter_date_state_change(new_state) | ||
|
||
if ( | ||
self.worker_id.working_mode == "irregular" | ||
and new_state in ["done", "absent_0"] | ||
and self.solidarity_offer_ids[0] | ||
): | ||
data["sr"] = 0 | ||
# old_data = json.loads(self.revert_info) | ||
# data["irregular_absence_date"] = old_data["data"] | ||
# .get("irregular_absence_date", False) | ||
# data["irregular_absence_counter"] = old_data["data"] | ||
# .get("irregular_absence_counter", 0) | ||
|
||
return data, status |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import test_counters |
131 changes: 131 additions & 0 deletions
131
beesdoo_worker_status_shift_swap/tests/test_counters.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
from datetime import datetime, timedelta | ||
|
||
from odoo.tests.common import TransactionCase | ||
|
||
|
||
class TestBeesdooWorkerStatusShiftSwap(TransactionCase): | ||
def setUp(self): | ||
super(TestBeesdooWorkerStatusShiftSwap, self).setUp() | ||
self.shift_model = self.env["beesdoo.shift.shift"] | ||
self.shift_template_model = self.env["beesdoo.shift.template"] | ||
self.shift_template_dated_model = self.env["beesdoo.shift.template.dated"] | ||
self.shift_solidarity_offer_model = self.env["beesdoo.shift.solidarity.offer"] | ||
self.shift_solidarity_request_model = self.env[ | ||
"beesdoo.shift.solidarity.request" | ||
] | ||
|
||
self.now = datetime.now() | ||
self.user_admin = self.env.ref("base.user_root") | ||
|
||
self.worker_regular_1 = self.env.ref("beesdoo_shift.res_partner_worker_1_demo") | ||
self.worker_irregular_1 = self.env.ref( | ||
"beesdoo_shift.res_partner_worker_2_demo" | ||
) | ||
|
||
self.task_template_1 = self.env.ref("beesdoo_shift_swap.task_template_1_demo") | ||
self.task_template_2 = self.env.ref("beesdoo_shift_swap.task_template_2_demo") | ||
self.task_template_3 = self.env.ref("beesdoo_shift_swap.task_template_3_demo") | ||
|
||
self.task_type_1 = self.env.ref("beesdoo_shift.beesdoo_shift_task_type_1_demo") | ||
|
||
self.exempt_reason_1 = self.env.ref("beesdoo_shift.exempt_reason_1_demo") | ||
|
||
def test_counters_solidarity_request(self): | ||
""" | ||
Test the personal counter updates when requesting a solidarity shift or | ||
cancelling a request | ||
""" | ||
template_dated = self.shift_template_dated_model.create( | ||
{ | ||
"template_id": self.task_template_1.id, | ||
"date": datetime.now() + timedelta(minutes=20), | ||
} | ||
) | ||
|
||
shift_regular = self.shift_model.create( | ||
{ | ||
"task_template_id": self.task_template_1.id, | ||
"task_type_id": self.task_type_1.id, | ||
"worker_id": self.worker_regular_1.id, | ||
"start_time": template_dated.date, | ||
"end_time": template_dated.date + timedelta(minutes=10), | ||
"is_regular": True, | ||
"is_compensation": False, | ||
} | ||
) | ||
|
||
# Initialize counters | ||
self.worker_regular_1.cooperative_status_ids.sr = 0 | ||
self.worker_irregular_1.cooperative_status_ids.sr = 0 | ||
|
||
# Solidarity request creation | ||
solidarity_request_regular = self.shift_solidarity_request_model.create( | ||
{ | ||
"worker_id": self.worker_regular_1.id, | ||
"tmpl_dated_id": template_dated.id, | ||
"reason": "A good reason", | ||
} | ||
) | ||
|
||
self.assertEqual(solidarity_request_regular.state, "validated") | ||
self.assertFalse(shift_regular.worker_id) | ||
self.assertFalse(shift_regular.is_regular) | ||
self.assertEqual(self.worker_regular_1.cooperative_status_ids.sr, 0) | ||
|
||
solidarity_request_irregular = self.shift_solidarity_request_model.create( | ||
{ | ||
"worker_id": self.worker_irregular_1.id, | ||
"tmpl_dated_id": False, | ||
"reason": "A good reason", | ||
} | ||
) | ||
|
||
self.assertEqual(solidarity_request_irregular.state, "validated") | ||
self.assertEqual(self.worker_irregular_1.cooperative_status_ids.sr, 1) | ||
|
||
# Solidarity request cancellation | ||
self.assertTrue(solidarity_request_regular.cancel_solidarity_request()) | ||
self.assertEqual(shift_regular.worker_id.id, self.worker_regular_1.id) | ||
self.assertTrue(shift_regular.is_regular) | ||
self.assertEqual(self.worker_regular_1.cooperative_status_ids.sr, 0) | ||
|
||
self.assertTrue(solidarity_request_irregular.cancel_solidarity_request()) | ||
self.assertEqual(self.worker_irregular_1.cooperative_status_ids.sr, 0) | ||
|
||
def test_counters_solidarity_offer(self): | ||
""" | ||
Verify that the personal counter of an irregular worker is not | ||
incremented when doing a solidarity shift | ||
""" | ||
template_dated = self.shift_template_dated_model.create( | ||
{ | ||
"template_id": self.task_template_1.id, | ||
"date": datetime.now() - timedelta(minutes=30), | ||
} | ||
) | ||
|
||
# Solidarity offer creation | ||
solidarity_offer = self.shift_solidarity_offer_model.create( | ||
{ | ||
"worker_id": self.worker_irregular_1.id, | ||
"tmpl_dated_id": template_dated.id, | ||
} | ||
) | ||
|
||
# Shift creation | ||
shift = self.shift_model.create( | ||
{ | ||
"task_template_id": self.task_template_1.id, | ||
"task_type_id": self.task_type_1.id, | ||
"worker_id": self.worker_irregular_1.id, | ||
"start_time": template_dated.date, | ||
"end_time": template_dated.date + timedelta(minutes=10), | ||
"is_regular": True, | ||
"is_compensation": False, | ||
"solidarity_offer_ids": [(6, 0, solidarity_offer.ids)], | ||
} | ||
) | ||
|
||
self.worker_irregular_1.cooperative_status_ids.sr = 0 | ||
shift.state = "done" | ||
self.assertEqual(self.worker_irregular_1.cooperative_status_ids.sr, 0) |
1 change: 1 addition & 0 deletions
1
setup/beesdoo_worker_status_shift_swap/odoo/addons/beesdoo_worker_status_shift_swap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../beesdoo_worker_status_shift_swap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |