Skip to content

Commit

Permalink
Merge PR #537 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by remytms
  • Loading branch information
github-grap-bot committed Dec 23, 2024
2 parents af23665 + a72be56 commit 6ce9884
Show file tree
Hide file tree
Showing 23 changed files with 1,850 additions and 41 deletions.
1 change: 1 addition & 0 deletions setup/shift_worker_status/odoo/addons/shift_worker_status
6 changes: 6 additions & 0 deletions setup/shift_worker_status/setup.py
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,
)
54 changes: 14 additions & 40 deletions shift/models/cooperative_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,22 @@ def _compute_status(self):
.get_param("shift.always_update", False)
)
for rec in self:
previous_status = rec.status
# default value for status
new_status = previous_status
if update or not rec.today:
rec.status = "ok"
continue
if rec.resigning:
rec.status = "resigning"
continue

if rec.working_mode == "regular":
rec.status = rec._get_regular_status()
new_status = "ok"
elif rec.resigning:
new_status = "resigning"
elif rec.working_mode == "regular":
new_status = rec._get_regular_status()
elif rec.working_mode == "irregular":
rec.status = rec._get_irregular_status()
new_status = rec._get_irregular_status()
elif rec.working_mode == "exempt":
rec.status = "ok"
new_status = "ok"
if new_status != previous_status:
rec._state_change(previous_status, new_status)
rec.status = new_status

_sql_constraints = [
(
Expand Down Expand Up @@ -253,35 +256,6 @@ def write(self, vals):
)
return result

def _write(self, vals):
"""
Overwrite write to historize the change of status
and make action on status change
"""
if "status" in vals:
self._cr.execute(
'select id, status, sr, sc from "%s" where id in %%s' % self._table,
(self._ids,),
)
result = self._cr.dictfetchall()
old_status_per_id = {r["id"]: r for r in result}
for rec in self:
if old_status_per_id[rec.id]["status"] != vals["status"]:
data = {
"status_id": rec.id,
"cooperator_id": rec.cooperator_id.id,
"type": "status",
"change": "STATUS: %s -> %s"
% (
old_status_per_id[rec.id]["status"],
vals["status"],
),
"user_id": self.env.context.get("real_uid", self.env.uid),
}
self.env["cooperative.status.history"].sudo().create(data)
rec._state_change(vals["status"])
return super(CooperativeStatus, self)._write(vals)

def _update_shifts_based_on_dates(
self, prev_start_date, prev_end_date, cur_start_date, cur_end_date
):
Expand Down Expand Up @@ -462,7 +436,7 @@ def _get_irregular_status(self):
"""
return "ok"

def _state_change(self, new_state):
def _state_change(self, previous_state, new_state):
"""
Hook to watch change in the state
"""
Expand Down
6 changes: 5 additions & 1 deletion shift/views/task.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@
<field name="arch" type="xml">
<form>
<header>
<field name="state" widget="statusbar" clickable="1" />
<field
name="state"
widget="statusbar"
options="{'clickable': '1'}"
/>
</header>
<sheet>
<div class="oe_title">
Expand Down
95 changes: 95 additions & 0 deletions shift_worker_status/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
=====================
Worker Status manager
=====================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:1264e1a467f997c42caa77a8b8f5428eaed9940ac16bbe707abe2b48ed4c5870
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-beescoop%2FObeesdoo-lightgray.png?logo=github
:target: https://github.com/beescoop/Obeesdoo/tree/16.0/shift_worker_status
:alt: beescoop/Obeesdoo

|badge1| |badge2| |badge3|

Worker status management.


* add "irregular penalty" config in shift settings
* compute next countdown date and future alert date for irregular
workers, taking into account holidays and exemption status
* compute the future alert date for irregular workers, taking into
account holidays and exemption status
* compute regular and irregular statuses according to alert start day,
alert delay, grace delay and time extensions, taking into account
holidays and exemption status
* recompute status and counters when a shift undergoes a state change
* postpone alert start time based on holidays and extension status
* handle is_regular and is_compensation consistency on shifts, on worker
change and by raising a validation error if the fields are not
properly set

**Table of contents**

.. 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
===========

Bugs are tracked on `GitHub Issues <https://github.com/beescoop/Obeesdoo/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/beescoop/Obeesdoo/issues/new?body=module:%20shift_worker_status%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Thibault Francois
* Elouan Le Bars
* Coop IT Easy SC

Contributors
~~~~~~~~~~~~

* BEES coop - Cellule IT
* Coop IT Easy SC

Maintainers
~~~~~~~~~~~

This module is part of the `beescoop/Obeesdoo <https://github.com/beescoop/Obeesdoo/tree/16.0/shift_worker_status>`_ project on GitHub.

You are welcome to contribute.
3 changes: 3 additions & 0 deletions shift_worker_status/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import models
from .rename_beesdoo import rename_beesdoo
from .post_init import post_init
26 changes: 26 additions & 0 deletions shift_worker_status/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2020 Coop IT Easy SCRL fs
# Elouan Le Bars <elouan@coopiteasy.be>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "Worker Status manager",
"summary": """
Worker status management.""",
"author": (
"Thibault Francois, "
"Elouan Le Bars, "
"Coop IT Easy SC, "
"Odoo Community Association (OCA)"
),
"website": "https://github.com/beescoop/Obeesdoo",
"category": "Cooperative management",
"version": "16.0.1.0.0",
"depends": ["shift"],
"data": [
"data/data.xml",
"views/res_config_settings_view.xml",
],
"demo": ["demo/tasks.xml"],
"license": "AGPL-3",
"pre_init_hook": "rename_beesdoo",
"post_init_hook": "post_init",
}
20 changes: 20 additions & 0 deletions shift_worker_status/data/data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" ?>
<odoo noupdate="1">
<!--
when this parameter is set to false, the ir.config_parameter is
deleted, along with its corresponding ir.model.data record. this
normally causes this record to be re-created when updating the
module, even though it is set as noupdate, because it is seen as
new data, effectively resetting the value to true. the forcecreate
property set to false ensures that this record is not recreated on
module update.
-->
<record
id="param_config_irregular_penalty"
model="ir.config_parameter"
forcecreate="false"
>
<field name="key">shift_worker_status.irregular_penalty</field>
<field name="value">True</field>
</record>
</odoo>
55 changes: 55 additions & 0 deletions shift_worker_status/demo/tasks.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2019 Coop IT Easy
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
<odoo>

<record id="shift_task_template_1_demo" model="shift.template">
<field name="name">A_LUN_7:00-9:30</field>
<field name="planning_id" ref="shift.shift_planning_1_demo" />
<field name="day_nb_id" ref="shift.shift_daynumber_1_demo" />
<field name="task_type_id" ref="shift.shift_task_type_3_demo" />
<field name="start_time">7</field>
<field name="end_time">9.5</field>
<field name="duration">2.5</field>
<field name="worker_nb">12</field>
<field
name="worker_ids"
eval="[(6, 0, [ref('shift.res_partner_worker_1_demo')])]"
/>
</record>

<record id="shift_task_template_2_demo" model="shift.template">
<field name="name">A_MAR_12:00-14:30</field>
<field name="planning_id" ref="shift.shift_planning_1_demo" />
<field name="day_nb_id" ref="shift.shift_daynumber_2_demo" />
<field name="task_type_id" ref="shift.shift_task_type_2_demo" />
<field name="start_time">12</field>
<field name="end_time">14.5</field>
<field name="duration">2.5</field>
<field name="worker_nb">9</field>
<!-- WARNING: issue, worker not registered in demo -->
<field
name="worker_ids"
eval="[(6, 0, [ref('shift.res_partner_worker_3_demo')])]"
/>
</record>

<record id="shift_task_template_3_demo" model="shift.template">
<field name="name">A_VEN_7:00-9:30</field>
<field name="planning_id" ref="shift.shift_planning_1_demo" />
<field name="day_nb_id" ref="shift.shift_daynumber_5_demo" />
<field name="task_type_id" ref="shift.shift_task_type_1_demo" />
<field name="start_time">7</field>
<field name="end_time">9.5</field>
<field name="duration">2.5</field>
<field name="worker_nb">7</field>
<!-- WARNING: issue, worker not registered in demo -->
<field
name="worker_ids"
eval="[(6, 0, [ref('shift.res_partner_worker_6_demo')])]"
/>
</record>

</odoo>
Loading

0 comments on commit 6ce9884

Please sign in to comment.