Skip to content

Commit

Permalink
[ADD] hr_timesheet_overtime_rate: Factored out of hr_timesheet_overtime
Browse files Browse the repository at this point in the history
This functionality was completely unlinked from the rest of
hr_timesheet_overtime.

I would have done this in two commits, but then the files wouldn't move
over cleanly, losing history.

Signed-off-by: Carmen Bianca BAKKER <[email protected]>
  • Loading branch information
carmenbianca committed Jul 5, 2024
1 parent ef2a7bb commit 9c6f4cb
Show file tree
Hide file tree
Showing 30 changed files with 751 additions and 162 deletions.
26 changes: 0 additions & 26 deletions hr_timesheet_overtime/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,6 @@ Computes overtime hours according to employee's contracts.
.. contents::
:local:

Known issues / Roadmap
======================

There is a problem with the way this module handles rates for overtime. If the
rate ever changes, things will start to break.

At time of writing (2024-06-28), the way a rate is computed for a date is by
looking _exclusively_ at the corresponding day of the week. This should be more
robust.

Furthermore, when inserting hours worked, the actual hours worked get lost. You
(try to) write a value to ``unit_amount``, but an augmented value gets written
to the field instead. This is rather ugly.

We can improve this by relying on the computation of ``unit_amount`` in Odoo
≥16: create a new field ``hours_worked``, which contains the actual hours worked
sans rate. Then, compute ``unit_amount`` from ``hours_worked`` (in a more robust
fashion than is presently the case). In the interface, show ``hours_worked``
more prominently than ``unit_amount`` as the main editable field.

To make this module subsequently compatible with ``hr_timesheet_begin_end``,
``hours_worked`` must be computed from ``time_stop`` and ``time_start``, and
``unit_amount`` must use this module's computation method instead of
``hr_timesheet_begin_end``'s. The compatibility layer should go into its own
module.

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

Expand Down
3 changes: 0 additions & 3 deletions hr_timesheet_overtime/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
"resource_work_time_from_contracts",
],
"data": [
"security/ir.model.access.csv",
"views/account_analytic_line_views.xml",
"views/hr_employee_view.xml",
"views/resource_view.xml",
"views/hr_timesheet_sheet_view.xml",
],
"demo": [
Expand Down
4 changes: 0 additions & 4 deletions hr_timesheet_overtime/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
from . import account_analytic_line
from . import hr_employee
from . import hr_timesheet_sheet
from . import hr_timesheet_sheet_line
from . import resource_overtime
from . import resource_overtime_rate
5 changes: 0 additions & 5 deletions hr_timesheet_overtime/models/hr_timesheet_sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,3 @@ def _compute_timesheet_overtime_trimmed(self):
working_time = employee.get_working_time(start_date, end_date)
worked_time = sheet.get_worked_time(start_date, end_date)
sheet.timesheet_overtime_trimmed = worked_time - working_time

def _get_default_sheet_line(self, matrix, key):
result = super()._get_default_sheet_line(matrix, key)
result["hours_worked"] = sum(t.hours_worked for t in matrix[key])
return result
22 changes: 0 additions & 22 deletions hr_timesheet_overtime/readme/ROADMAP.rst

This file was deleted.

46 changes: 12 additions & 34 deletions hr_timesheet_overtime/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -374,56 +374,34 @@ <h1 class="title">Timesheet/Contract - Overtime</h1>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#known-issues-roadmap" id="toc-entry-1">Known issues / Roadmap</a></li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-2">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-3">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-4">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-5">Contributors</a></li>
<li><a class="reference internal" href="#other-credits" id="toc-entry-6">Other credits</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-7">Maintainers</a></li>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-1">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-2">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-3">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-4">Contributors</a></li>
<li><a class="reference internal" href="#other-credits" id="toc-entry-5">Other credits</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-6">Maintainers</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="known-issues-roadmap">
<h1><a class="toc-backref" href="#toc-entry-1">Known issues / Roadmap</a></h1>
<p>There is a problem with the way this module handles rates for overtime. If the
rate ever changes, things will start to break.</p>
<p>At time of writing (2024-06-28), the way a rate is computed for a date is by
looking _exclusively_ at the corresponding day of the week. This should be more
robust.</p>
<p>Furthermore, when inserting hours worked, the actual hours worked get lost. You
(try to) write a value to <tt class="docutils literal">unit_amount</tt>, but an augmented value gets written
to the field instead. This is rather ugly.</p>
<p>We can improve this by relying on the computation of <tt class="docutils literal">unit_amount</tt> in Odoo
≥16: create a new field <tt class="docutils literal">hours_worked</tt>, which contains the actual hours worked
sans rate. Then, compute <tt class="docutils literal">unit_amount</tt> from <tt class="docutils literal">hours_worked</tt> (in a more robust
fashion than is presently the case). In the interface, show <tt class="docutils literal">hours_worked</tt>
more prominently than <tt class="docutils literal">unit_amount</tt> as the main editable field.</p>
<p>To make this module subsequently compatible with <tt class="docutils literal">hr_timesheet_begin_end</tt>,
<tt class="docutils literal">hours_worked</tt> must be computed from <tt class="docutils literal">time_stop</tt> and <tt class="docutils literal">time_start</tt>, and
<tt class="docutils literal">unit_amount</tt> must use this module’s computation method instead of
<tt class="docutils literal">hr_timesheet_begin_end</tt>’s. The compatibility layer should go into its own
module.</p>
</div>
<div class="section" id="bug-tracker">
<h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
<h1><a class="toc-backref" href="#toc-entry-1">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/coopiteasy/cie-timesheet/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 to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/coopiteasy/cie-timesheet/issues/new?body=module:%20hr_timesheet_overtime%0Aversion:%2016.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="#toc-entry-3">Credits</a></h1>
<h1><a class="toc-backref" href="#toc-entry-2">Credits</a></h1>
<div class="section" id="authors">
<h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-3">Authors</a></h2>
<ul class="simple">
<li>Coop IT Easy SC</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
<ul class="simple">
<li><a class="reference external" href="https://coopiteasy.be">Coop IT Easy SC</a>:<ul>
<li>Vincent Van Rossem</li>
Expand All @@ -435,12 +413,12 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
</ul>
</div>
<div class="section" id="other-credits">
<h2><a class="toc-backref" href="#toc-entry-6">Other credits</a></h2>
<h2><a class="toc-backref" href="#toc-entry-5">Other credits</a></h2>
<p>The development of this module has been paid for by
<a class="reference external" href="https://www.provelo.org/">Pro Velo</a>.</p>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<p>This module is part of the <a class="reference external" href="https://github.com/coopiteasy/cie-timesheet/tree/16.0/hr_timesheet_overtime">coopiteasy/cie-timesheet</a> project on GitHub.</p>
<p>You are welcome to contribute.</p>
</div>
Expand Down
21 changes: 10 additions & 11 deletions hr_timesheet_overtime/tests/test_overtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def setUpClass(cls):
"date": "2019-12-02",
"name": "-",
"sheet_id": cls.ts1.id,
"hours_worked": 10.0, # 1 hour overtime
"unit_amount": 10.0, # 1 hour overtime
"user_id": cls.employee1.user_id.id,
}
)
Expand All @@ -85,7 +85,7 @@ def setUpClass(cls):
"date": date(2019, 12, day),
"name": "-",
"sheet_id": cls.ts1.id,
"hours_worked": 9.0, # expected time
"unit_amount": 9.0, # expected time
"user_id": cls.employee1.user_id.id,
}
)
Expand Down Expand Up @@ -121,7 +121,7 @@ def test_overtime_02(self):
"date": date(2019, 12, day),
"name": "-",
"sheet_id": ts2.id,
"hours_worked": 10.0, # 1 hour overtime
"unit_amount": 10.0, # 1 hour overtime
"user_id": self.employee1.user_id.id,
}
)
Expand All @@ -134,7 +134,7 @@ def test_overtime_02(self):
"date": date(2019, 12, day),
"name": "-",
"sheet_id": ts2.id,
"hours_worked": 9.0, # expected time
"unit_amount": 9.0, # expected time
"user_id": self.employee1.user_id.id,
}
)
Expand Down Expand Up @@ -182,7 +182,7 @@ def test_overtime_04(self):
"date": "2019-12-09",
"name": "-",
"sheet_id": ts2.id,
"hours_worked": 10.0, # 1 hour overtime
"unit_amount": 10.0, # 1 hour overtime
"user_id": self.employee1.user_id.id,
}
)
Expand All @@ -195,7 +195,7 @@ def test_overtime_04(self):
"date": date(2019, 12, day),
"name": "-",
"sheet_id": ts2.id,
"hours_worked": 9.0, # expected time
"unit_amount": 9.0, # expected time
"user_id": self.employee1.user_id.id,
}
)
Expand Down Expand Up @@ -256,7 +256,7 @@ def test_overtime_05(self):
"date": "2020-01-06",
"name": "-",
"sheet_id": self.ts2.id,
"hours_worked": 9.0, # expected time from previous contract
"unit_amount": 9.0, # expected time from previous contract
"user_id": self.employee1.user_id.id,
}
)
Expand All @@ -270,7 +270,7 @@ def test_overtime_05(self):
"date": date(2020, 1, day),
"name": "-",
"sheet_id": self.ts2.id,
"hours_worked": 4.0, # expected time from new contract
"unit_amount": 4.0, # expected time from new contract
"user_id": self.employee1.user_id.id,
}
)
Expand Down Expand Up @@ -301,7 +301,7 @@ def test_overtime_archived_timesheet(self):
"date": date(2019, 12, day),
"name": "-",
"sheet_id": ts2.id,
"hours_worked": 10.0, # 1 hour overtime
"unit_amount": 10.0, # 1 hour overtime
"user_id": self.employee1.user_id.id,
}
)
Expand Down Expand Up @@ -406,8 +406,7 @@ def test_stored_change_today(self):
("sheet_id", "=", self.ts1.id),
]
)
line.hours_worked = 10
self.assertEqual(line.unit_amount, 10)
line.unit_amount = 10
self.assertEqual(self.ts1.timesheet_overtime_trimmed, 2)
self.assertEqual(self.ts1.timesheet_overtime, 2)
self.assertEqual(self.ts1.total_overtime, 2)
Expand Down
50 changes: 0 additions & 50 deletions hr_timesheet_overtime/views/hr_timesheet_sheet_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,40 +58,6 @@
decoration-info="total_overtime &gt;= 0"
/>
</xpath>

<!-- FIXME: this is presently broken. the summary page does not
compute unit_amount when changing hours_worked -->
<xpath expr="//field[@name='line_ids']" position="attributes">
<attribute name="field_value">hours_worked</attribute>
</xpath>

<xpath
expr="//field[@name='line_ids']/tree/field[@name='unit_amount']"
position="before"
>
<field name="hours_worked" widget="float_time" />
</xpath>


<xpath
expr="//field[@name='timesheet_ids']/tree/field[@name='unit_amount']"
position="before"
>
<field
name="hours_worked"
widget="float_time"
string="Hours Worked"
sum="Hours Worked"
/>
</xpath>

<xpath
expr="//field[@name='timesheet_ids']/form//field[@name='unit_amount']"
position="before"
>
<field name="hours_worked" widget="float_time" string="Hours Worked" />
</xpath>

</field>
</record>

Expand Down Expand Up @@ -129,20 +95,4 @@
</field>
</record>

<menuitem
name="Overtime"
id="menu_hr_timesheet_overtime"
sequence="99"
parent="hr_timesheet.timesheet_menu_root"
/>

<menuitem
name="Overtime Rate"
id="menu_hr_timesheet_overtime_rate"
sequence="100"
parent="menu_hr_timesheet_overtime"
groups="hr.group_hr_manager"
action="action_resource_overtime_form"
/>

</odoo>
Loading

0 comments on commit 9c6f4cb

Please sign in to comment.