From ef2a7bb3a0f1233e4bdad3c9ce7b804e8c1df152 Mon Sep 17 00:00:00 2001 From: Carmen Bianca BAKKER Date: Thu, 4 Jul 2024 18:48:32 +0200 Subject: [PATCH 1/8] [REF] hr_timesheet_overtime: Add hours_worked field Signed-off-by: Carmen Bianca BAKKER --- hr_timesheet_overtime/__manifest__.py | 3 +- .../migrations/16.0.3.0.0/post-upgrade.py | 19 ++++ hr_timesheet_overtime/models/__init__.py | 1 + .../models/account_analytic_line.py | 44 ++++----- .../models/hr_timesheet_sheet.py | 5 ++ .../models/hr_timesheet_sheet_line.py | 31 +++++++ .../static/description/index.html | 9 +- hr_timesheet_overtime/tests/test_overtime.py | 21 ++--- .../views/account_analytic_line_views.xml | 89 +++++++++++++++++++ .../views/hr_timesheet_sheet_view.xml | 33 +++++++ 10 files changed, 219 insertions(+), 36 deletions(-) create mode 100644 hr_timesheet_overtime/migrations/16.0.3.0.0/post-upgrade.py create mode 100644 hr_timesheet_overtime/models/hr_timesheet_sheet_line.py create mode 100644 hr_timesheet_overtime/views/account_analytic_line_views.xml diff --git a/hr_timesheet_overtime/__manifest__.py b/hr_timesheet_overtime/__manifest__.py index 90e0318..dd04421 100644 --- a/hr_timesheet_overtime/__manifest__.py +++ b/hr_timesheet_overtime/__manifest__.py @@ -3,7 +3,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { "name": "Timesheet/Contract - Overtime", - "version": "16.0.2.1.0", + "version": "16.0.3.0.0", "category": "Human Resources", "summary": "Overtime Calculation", "author": "Coop IT Easy SC, Odoo Community Association (OCA)", @@ -16,6 +16,7 @@ ], "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", diff --git a/hr_timesheet_overtime/migrations/16.0.3.0.0/post-upgrade.py b/hr_timesheet_overtime/migrations/16.0.3.0.0/post-upgrade.py new file mode 100644 index 0000000..508abce --- /dev/null +++ b/hr_timesheet_overtime/migrations/16.0.3.0.0/post-upgrade.py @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: 2024 Coop IT Easy SC +# +# SPDX-License-Identifier: AGPL-3.0-or-later + + +def migrate(cr, version): + # This is not strictly true, but it's the best way to populate the field + # with sensible data. + # + # TODO: Does this run upon module installation? This needs to be run on + # module installation as well. + cr.execute( + # Perfect symmetry is joyous + """ + UPDATE account_analytic_line + SET hours_worked=unit_amount + WHERE project_id IS NOT NULL + """ + ) diff --git a/hr_timesheet_overtime/models/__init__.py b/hr_timesheet_overtime/models/__init__.py index c01dbe6..4f13953 100644 --- a/hr_timesheet_overtime/models/__init__.py +++ b/hr_timesheet_overtime/models/__init__.py @@ -1,5 +1,6 @@ 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 diff --git a/hr_timesheet_overtime/models/account_analytic_line.py b/hr_timesheet_overtime/models/account_analytic_line.py index 47b82d8..5706ffc 100644 --- a/hr_timesheet_overtime/models/account_analytic_line.py +++ b/hr_timesheet_overtime/models/account_analytic_line.py @@ -15,27 +15,29 @@ class AnalyticLine(models.Model): _inherit = "account.analytic.line" - @api.model_create_multi - def create(self, vals_list): - for vals in vals_list: - self._update_values(vals) - return super().create(vals_list) - - def write(self, values): - if not self.env.context.get("create"): # sale module - self._update_values(values) - return super().write(values) - - def _update_values(self, values): - """ - Update values if date or unit_amount fields have changed - """ - if "date" in values or "unit_amount" in values: - # TODO: self.date and self.unit_amount do not exist when called from - # create(). - date = values.get("date", self.date) - unit_amount = values.get("unit_amount", self.unit_amount) - values["unit_amount"] = unit_amount * self.rate_for_date(date) + hours_worked = fields.Float( + default=0.0, + ) + # Override to be a computed field. + unit_amount = fields.Float( + # We use a kind of custom name here because `hr_timesheet_begin_end` + # also overrides this, and the two compute methods are not necessarily + # compatible. + compute="_compute_unit_amount_from_hours", + store=True, + readonly=False, + # This triggers computation on creation. default=False and default=0 do + # not trigger computation. + default=None, + ) + + # TODO: should this also depend on resource.overtime.rate, somehow? + @api.depends("hours_worked", "date") + def _compute_unit_amount_from_hours(self): + # Do not compute/adjust the unit_amount of non-timesheets. + lines = self.filtered(lambda line: line.project_id) + for line in lines: + line.unit_amount = line.hours_worked * line.rate_for_date(line.date) @api.model def rate_for_date(self, date): diff --git a/hr_timesheet_overtime/models/hr_timesheet_sheet.py b/hr_timesheet_overtime/models/hr_timesheet_sheet.py index 08b9ec1..17a8ec2 100644 --- a/hr_timesheet_overtime/models/hr_timesheet_sheet.py +++ b/hr_timesheet_overtime/models/hr_timesheet_sheet.py @@ -148,3 +148,8 @@ 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 diff --git a/hr_timesheet_overtime/models/hr_timesheet_sheet_line.py b/hr_timesheet_overtime/models/hr_timesheet_sheet_line.py new file mode 100644 index 0000000..38e0de3 --- /dev/null +++ b/hr_timesheet_overtime/models/hr_timesheet_sheet_line.py @@ -0,0 +1,31 @@ +# SPDX-FileCopyrightText: 2024 Coop IT Easy SC +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +from odoo import api, fields, models + + +class HrTimesheetSheetLineAbstract(models.AbstractModel): + _inherit = "hr_timesheet.sheet.line.abstract" + + hours_worked = fields.Float(default=0.0) + unit_amount = fields.Float( + compute="_compute_unit_amount_from_hours", readonly=False + ) + + # TODO: this is basically identical to account.analytic.line. it's probably + # fine? + @api.depends("hours_worked", "date") + def _compute_unit_amount_from_hours(self): + for line in self: + line.unit_amount = line.hours_worked * self.env[ + "account.analytic.line" + ].rate_for_date(line.date) + + +class HrTimesheetSheetLine(models.TransientModel): + _inherit = "hr_timesheet.sheet.line" + + @api.onchange("unit_amount", "hours_worked") + def onchange_unit_amount(self): + return super().onchange_unit_amount() diff --git a/hr_timesheet_overtime/static/description/index.html b/hr_timesheet_overtime/static/description/index.html index b0b4321..fdf16be 100644 --- a/hr_timesheet_overtime/static/description/index.html +++ b/hr_timesheet_overtime/static/description/index.html @@ -8,10 +8,11 @@ /* :Author: David Goodger (goodger@python.org) -:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $ +:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $ :Copyright: This stylesheet has been placed in the public domain. Default cascading style sheet for the HTML output of Docutils. +Despite the name, some widely supported CSS2 features are used. See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to customize this style sheet. @@ -274,7 +275,7 @@ margin-left: 2em ; margin-right: 2em } -pre.code .ln { color: grey; } /* line numbers */ +pre.code .ln { color: gray; } /* line numbers */ pre.code, code { background-color: #eeeeee } pre.code .comment, code .comment { color: #5C6576 } pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } @@ -300,7 +301,7 @@ span.pre { white-space: pre } -span.problematic { +span.problematic, pre.problematic { color: red } span.section-subtitle { @@ -366,7 +367,7 @@

Timesheet/Contract - Overtime

!! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:f303e3ad17e5d88c4ddf2a1baf816f420994d594a04db998c4fd2c1e9f1b2131 +!! source digest: sha256:bde6f189b3da65ae6a23a4337c16402e0a29f4ebbb8dd39431f53c37a66249ef !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

Beta License: AGPL-3 coopiteasy/cie-timesheet

Computes overtime hours according to employee’s contracts.

diff --git a/hr_timesheet_overtime/tests/test_overtime.py b/hr_timesheet_overtime/tests/test_overtime.py index 52f12e9..b4ff636 100644 --- a/hr_timesheet_overtime/tests/test_overtime.py +++ b/hr_timesheet_overtime/tests/test_overtime.py @@ -72,7 +72,7 @@ def setUpClass(cls): "date": "2019-12-02", "name": "-", "sheet_id": cls.ts1.id, - "unit_amount": 10.0, # 1 hour overtime + "hours_worked": 10.0, # 1 hour overtime "user_id": cls.employee1.user_id.id, } ) @@ -85,7 +85,7 @@ def setUpClass(cls): "date": date(2019, 12, day), "name": "-", "sheet_id": cls.ts1.id, - "unit_amount": 9.0, # expected time + "hours_worked": 9.0, # expected time "user_id": cls.employee1.user_id.id, } ) @@ -121,7 +121,7 @@ def test_overtime_02(self): "date": date(2019, 12, day), "name": "-", "sheet_id": ts2.id, - "unit_amount": 10.0, # 1 hour overtime + "hours_worked": 10.0, # 1 hour overtime "user_id": self.employee1.user_id.id, } ) @@ -134,7 +134,7 @@ def test_overtime_02(self): "date": date(2019, 12, day), "name": "-", "sheet_id": ts2.id, - "unit_amount": 9.0, # expected time + "hours_worked": 9.0, # expected time "user_id": self.employee1.user_id.id, } ) @@ -182,7 +182,7 @@ def test_overtime_04(self): "date": "2019-12-09", "name": "-", "sheet_id": ts2.id, - "unit_amount": 10.0, # 1 hour overtime + "hours_worked": 10.0, # 1 hour overtime "user_id": self.employee1.user_id.id, } ) @@ -195,7 +195,7 @@ def test_overtime_04(self): "date": date(2019, 12, day), "name": "-", "sheet_id": ts2.id, - "unit_amount": 9.0, # expected time + "hours_worked": 9.0, # expected time "user_id": self.employee1.user_id.id, } ) @@ -256,7 +256,7 @@ def test_overtime_05(self): "date": "2020-01-06", "name": "-", "sheet_id": self.ts2.id, - "unit_amount": 9.0, # expected time from previous contract + "hours_worked": 9.0, # expected time from previous contract "user_id": self.employee1.user_id.id, } ) @@ -270,7 +270,7 @@ def test_overtime_05(self): "date": date(2020, 1, day), "name": "-", "sheet_id": self.ts2.id, - "unit_amount": 4.0, # expected time from new contract + "hours_worked": 4.0, # expected time from new contract "user_id": self.employee1.user_id.id, } ) @@ -301,7 +301,7 @@ def test_overtime_archived_timesheet(self): "date": date(2019, 12, day), "name": "-", "sheet_id": ts2.id, - "unit_amount": 10.0, # 1 hour overtime + "hours_worked": 10.0, # 1 hour overtime "user_id": self.employee1.user_id.id, } ) @@ -406,7 +406,8 @@ def test_stored_change_today(self): ("sheet_id", "=", self.ts1.id), ] ) - line.unit_amount = 10 + line.hours_worked = 10 + self.assertEqual(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) diff --git a/hr_timesheet_overtime/views/account_analytic_line_views.xml b/hr_timesheet_overtime/views/account_analytic_line_views.xml new file mode 100644 index 0000000..407c919 --- /dev/null +++ b/hr_timesheet_overtime/views/account_analytic_line_views.xml @@ -0,0 +1,89 @@ + + + + + account.analytic.line.tree.hr_timesheet + account.analytic.line + + + + + + + + + + account.analytic.line.pivot + account.analytic.line + + + + + + + + + + account.analytic.line.graph + account.analytic.line + + + + + + + + + + account.analytic.line.graph + account.analytic.line + + + + + + + + + + account.analytic.line.graph + account.analytic.line + + + + + + + + + + account.analytic.line.form + account.analytic.line + + + + + + + + + + account.analytic.line.kanban + account.analytic.line + + + + + + + + + diff --git a/hr_timesheet_overtime/views/hr_timesheet_sheet_view.xml b/hr_timesheet_overtime/views/hr_timesheet_sheet_view.xml index 10c7965..ef491c2 100644 --- a/hr_timesheet_overtime/views/hr_timesheet_sheet_view.xml +++ b/hr_timesheet_overtime/views/hr_timesheet_sheet_view.xml @@ -59,6 +59,39 @@ /> + + + hours_worked + + + + + + + + + + + + + + + From 9c6f4cb3c6451b54d40a356f9345bee0bf838abe Mon Sep 17 00:00:00 2001 From: Carmen Bianca BAKKER Date: Fri, 5 Jul 2024 11:23:43 +0200 Subject: [PATCH 2/8] [ADD] hr_timesheet_overtime_rate: Factored out of hr_timesheet_overtime 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 --- hr_timesheet_overtime/README.rst | 26 -- hr_timesheet_overtime/__manifest__.py | 3 - hr_timesheet_overtime/models/__init__.py | 4 - .../models/hr_timesheet_sheet.py | 5 - hr_timesheet_overtime/readme/ROADMAP.rst | 22 - .../static/description/index.html | 46 +- hr_timesheet_overtime/tests/test_overtime.py | 21 +- .../views/hr_timesheet_sheet_view.xml | 50 -- hr_timesheet_overtime_rate/README.rst | 87 ++++ hr_timesheet_overtime_rate/__init__.py | 5 + hr_timesheet_overtime_rate/__manifest__.py | 28 ++ .../migrations/16.0.1.0.0}/post-upgrade.py | 2 +- hr_timesheet_overtime_rate/models/__init__.py | 9 + .../models/account_analytic_line.py | 9 +- .../models/hr_timesheet_sheet.py | 14 + .../models/hr_timesheet_sheet_line.py | 0 .../models/resource_overtime.py | 0 .../models/resource_overtime_rate.py | 0 .../readme/CONTRIBUTORS.rst | 3 + .../readme/DESCRIPTION.rst | 1 + hr_timesheet_overtime_rate/readme/ROADMAP.rst | 13 + .../security/ir.model.access.csv | 0 .../static/description/index.html | 436 ++++++++++++++++++ hr_timesheet_overtime_rate/tests/__init__.py | 5 + .../tests/test_overtime.py | 58 +++ .../views/account_analytic_line_views.xml | 0 .../views/hr_timesheet_sheet_views.xml | 59 +++ .../views/resource_views.xml | 0 .../odoo/addons/hr_timesheet_overtime_rate | 1 + setup/hr_timesheet_overtime_rate/setup.py | 6 + 30 files changed, 751 insertions(+), 162 deletions(-) delete mode 100644 hr_timesheet_overtime/readme/ROADMAP.rst create mode 100644 hr_timesheet_overtime_rate/README.rst create mode 100644 hr_timesheet_overtime_rate/__init__.py create mode 100644 hr_timesheet_overtime_rate/__manifest__.py rename {hr_timesheet_overtime/migrations/16.0.3.0.0 => hr_timesheet_overtime_rate/migrations/16.0.1.0.0}/post-upgrade.py (93%) create mode 100644 hr_timesheet_overtime_rate/models/__init__.py rename {hr_timesheet_overtime => hr_timesheet_overtime_rate}/models/account_analytic_line.py (88%) create mode 100644 hr_timesheet_overtime_rate/models/hr_timesheet_sheet.py rename {hr_timesheet_overtime => hr_timesheet_overtime_rate}/models/hr_timesheet_sheet_line.py (100%) rename {hr_timesheet_overtime => hr_timesheet_overtime_rate}/models/resource_overtime.py (100%) rename {hr_timesheet_overtime => hr_timesheet_overtime_rate}/models/resource_overtime_rate.py (100%) create mode 100644 hr_timesheet_overtime_rate/readme/CONTRIBUTORS.rst create mode 100644 hr_timesheet_overtime_rate/readme/DESCRIPTION.rst create mode 100644 hr_timesheet_overtime_rate/readme/ROADMAP.rst rename {hr_timesheet_overtime => hr_timesheet_overtime_rate}/security/ir.model.access.csv (100%) create mode 100644 hr_timesheet_overtime_rate/static/description/index.html create mode 100644 hr_timesheet_overtime_rate/tests/__init__.py create mode 100644 hr_timesheet_overtime_rate/tests/test_overtime.py rename {hr_timesheet_overtime => hr_timesheet_overtime_rate}/views/account_analytic_line_views.xml (100%) create mode 100644 hr_timesheet_overtime_rate/views/hr_timesheet_sheet_views.xml rename hr_timesheet_overtime/views/resource_view.xml => hr_timesheet_overtime_rate/views/resource_views.xml (100%) create mode 120000 setup/hr_timesheet_overtime_rate/odoo/addons/hr_timesheet_overtime_rate create mode 100644 setup/hr_timesheet_overtime_rate/setup.py diff --git a/hr_timesheet_overtime/README.rst b/hr_timesheet_overtime/README.rst index 72b1faf..1bc6c3e 100644 --- a/hr_timesheet_overtime/README.rst +++ b/hr_timesheet_overtime/README.rst @@ -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 =========== diff --git a/hr_timesheet_overtime/__manifest__.py b/hr_timesheet_overtime/__manifest__.py index dd04421..80fef81 100644 --- a/hr_timesheet_overtime/__manifest__.py +++ b/hr_timesheet_overtime/__manifest__.py @@ -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": [ diff --git a/hr_timesheet_overtime/models/__init__.py b/hr_timesheet_overtime/models/__init__.py index 4f13953..88ae19e 100644 --- a/hr_timesheet_overtime/models/__init__.py +++ b/hr_timesheet_overtime/models/__init__.py @@ -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 diff --git a/hr_timesheet_overtime/models/hr_timesheet_sheet.py b/hr_timesheet_overtime/models/hr_timesheet_sheet.py index 17a8ec2..08b9ec1 100644 --- a/hr_timesheet_overtime/models/hr_timesheet_sheet.py +++ b/hr_timesheet_overtime/models/hr_timesheet_sheet.py @@ -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 diff --git a/hr_timesheet_overtime/readme/ROADMAP.rst b/hr_timesheet_overtime/readme/ROADMAP.rst deleted file mode 100644 index 08e5a7f..0000000 --- a/hr_timesheet_overtime/readme/ROADMAP.rst +++ /dev/null @@ -1,22 +0,0 @@ -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. diff --git a/hr_timesheet_overtime/static/description/index.html b/hr_timesheet_overtime/static/description/index.html index fdf16be..9e211b7 100644 --- a/hr_timesheet_overtime/static/description/index.html +++ b/hr_timesheet_overtime/static/description/index.html @@ -374,40 +374,18 @@

Timesheet/Contract - Overtime

Table of contents

-
-

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

+

Bug Tracker

Bugs are tracked on GitHub 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 @@ -415,15 +393,15 @@

Bug Tracker

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

-

Credits

+

Credits

-

Authors

+

Authors

  • Coop IT Easy SC
-

Contributors

+

Contributors

-

Other credits

+

Other credits

The development of this module has been paid for by Pro Velo.

-

Maintainers

+

Maintainers

This module is part of the coopiteasy/cie-timesheet project on GitHub.

You are welcome to contribute.

diff --git a/hr_timesheet_overtime/tests/test_overtime.py b/hr_timesheet_overtime/tests/test_overtime.py index b4ff636..52f12e9 100644 --- a/hr_timesheet_overtime/tests/test_overtime.py +++ b/hr_timesheet_overtime/tests/test_overtime.py @@ -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, } ) @@ -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, } ) @@ -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, } ) @@ -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, } ) @@ -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, } ) @@ -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, } ) @@ -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, } ) @@ -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, } ) @@ -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, } ) @@ -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) diff --git a/hr_timesheet_overtime/views/hr_timesheet_sheet_view.xml b/hr_timesheet_overtime/views/hr_timesheet_sheet_view.xml index ef491c2..eb30eb0 100644 --- a/hr_timesheet_overtime/views/hr_timesheet_sheet_view.xml +++ b/hr_timesheet_overtime/views/hr_timesheet_sheet_view.xml @@ -58,40 +58,6 @@ decoration-info="total_overtime >= 0" /> - - - - hours_worked - - - - - - - - - - - - - - - @@ -129,20 +95,4 @@ - - - - diff --git a/hr_timesheet_overtime_rate/README.rst b/hr_timesheet_overtime_rate/README.rst new file mode 100644 index 0000000..9baae5f --- /dev/null +++ b/hr_timesheet_overtime_rate/README.rst @@ -0,0 +1,87 @@ +============= +Overtime Rate +============= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:36d3b7bc33750523cfa2cc468002678f8db599e083759ba12ede988ee84d6431 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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-coopiteasy%2Fcie--timesheet-lightgray.png?logo=github + :target: https://github.com/coopiteasy/cie-timesheet/tree/16.0/hr_timesheet_overtime_rate + :alt: coopiteasy/cie-timesheet + +|badge1| |badge2| |badge3| + +Define an extra rate for working certain days. + +**Table of contents** + +.. 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. + +Because ``unit_amount`` is computed from ``hours_worked``, this module is not +compatible with ``hr_timesheet_begin_end``.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 +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Coop IT Easy SC + +Contributors +~~~~~~~~~~~~ + +* `Coop IT Easy SC `_: + + * Carmen Bianca BAKKER + +Maintainers +~~~~~~~~~~~ + +.. |maintainer-carmenbianca| image:: https://github.com/carmenbianca.png?size=40px + :target: https://github.com/carmenbianca + :alt: carmenbianca + +Current maintainer: + +|maintainer-carmenbianca| + +This module is part of the `coopiteasy/cie-timesheet `_ project on GitHub. + +You are welcome to contribute. diff --git a/hr_timesheet_overtime_rate/__init__.py b/hr_timesheet_overtime_rate/__init__.py new file mode 100644 index 0000000..3eb7887 --- /dev/null +++ b/hr_timesheet_overtime_rate/__init__.py @@ -0,0 +1,5 @@ +# SPDX-FileCopyrightText: 2024 Coop IT Easy SC +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +from . import models diff --git a/hr_timesheet_overtime_rate/__manifest__.py b/hr_timesheet_overtime_rate/__manifest__.py new file mode 100644 index 0000000..b8c3f79 --- /dev/null +++ b/hr_timesheet_overtime_rate/__manifest__.py @@ -0,0 +1,28 @@ +# SPDX-FileCopyrightText: 2024 Coop IT Easy SC +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +{ + "name": "Overtime Rate", + "summary": """ + Define an extra rate for working certain days.""", + "version": "16.0.1.0.0", + "category": "Human Resources", + "website": "https://github.com/coopiteasy/cie-timesheet", + "author": "Coop IT Easy SC", + "maintainers": ["carmenbianca"], + "license": "AGPL-3", + "application": False, + "depends": [ + "hr_timesheet_sheet", + ], + "excludes": [], + "data": [ + "security/ir.model.access.csv", + "views/resource_views.xml", + "views/account_analytic_line_views.xml", + "views/hr_timesheet_sheet_views.xml", + ], + "demo": [], + "qweb": [], +} diff --git a/hr_timesheet_overtime/migrations/16.0.3.0.0/post-upgrade.py b/hr_timesheet_overtime_rate/migrations/16.0.1.0.0/post-upgrade.py similarity index 93% rename from hr_timesheet_overtime/migrations/16.0.3.0.0/post-upgrade.py rename to hr_timesheet_overtime_rate/migrations/16.0.1.0.0/post-upgrade.py index 508abce..9cc5489 100644 --- a/hr_timesheet_overtime/migrations/16.0.3.0.0/post-upgrade.py +++ b/hr_timesheet_overtime_rate/migrations/16.0.1.0.0/post-upgrade.py @@ -8,7 +8,7 @@ def migrate(cr, version): # with sensible data. # # TODO: Does this run upon module installation? This needs to be run on - # module installation as well. + # module installation. cr.execute( # Perfect symmetry is joyous """ diff --git a/hr_timesheet_overtime_rate/models/__init__.py b/hr_timesheet_overtime_rate/models/__init__.py new file mode 100644 index 0000000..8bfbbd0 --- /dev/null +++ b/hr_timesheet_overtime_rate/models/__init__.py @@ -0,0 +1,9 @@ +# SPDX-FileCopyrightText: 2024 Coop IT Easy SC +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +from . import account_analytic_line +from . import hr_timesheet_sheet +from . import hr_timesheet_sheet_line +from . import resource_overtime +from . import resource_overtime_rate diff --git a/hr_timesheet_overtime/models/account_analytic_line.py b/hr_timesheet_overtime_rate/models/account_analytic_line.py similarity index 88% rename from hr_timesheet_overtime/models/account_analytic_line.py rename to hr_timesheet_overtime_rate/models/account_analytic_line.py index 5706ffc..d27e8a0 100644 --- a/hr_timesheet_overtime/models/account_analytic_line.py +++ b/hr_timesheet_overtime_rate/models/account_analytic_line.py @@ -1,12 +1,9 @@ -# Copyright 2020 Coop IT Easy SC -# - Vincent Van Rossem -# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -import logging +# SPDX-FileCopyrightText: 2024 Coop IT Easy SC +# +# SPDX-License-Identifier: AGPL-3.0-or-later from odoo import api, fields, models -_logger = logging.getLogger(__name__) - class AnalyticLine(models.Model): """ diff --git a/hr_timesheet_overtime_rate/models/hr_timesheet_sheet.py b/hr_timesheet_overtime_rate/models/hr_timesheet_sheet.py new file mode 100644 index 0000000..9489431 --- /dev/null +++ b/hr_timesheet_overtime_rate/models/hr_timesheet_sheet.py @@ -0,0 +1,14 @@ +# SPDX-FileCopyrightText: 2024 Coop IT Easy SC +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +from odoo import models + + +class HrTimesheetSheet(models.Model): + _inherit = "hr_timesheet.sheet" + + 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 diff --git a/hr_timesheet_overtime/models/hr_timesheet_sheet_line.py b/hr_timesheet_overtime_rate/models/hr_timesheet_sheet_line.py similarity index 100% rename from hr_timesheet_overtime/models/hr_timesheet_sheet_line.py rename to hr_timesheet_overtime_rate/models/hr_timesheet_sheet_line.py diff --git a/hr_timesheet_overtime/models/resource_overtime.py b/hr_timesheet_overtime_rate/models/resource_overtime.py similarity index 100% rename from hr_timesheet_overtime/models/resource_overtime.py rename to hr_timesheet_overtime_rate/models/resource_overtime.py diff --git a/hr_timesheet_overtime/models/resource_overtime_rate.py b/hr_timesheet_overtime_rate/models/resource_overtime_rate.py similarity index 100% rename from hr_timesheet_overtime/models/resource_overtime_rate.py rename to hr_timesheet_overtime_rate/models/resource_overtime_rate.py diff --git a/hr_timesheet_overtime_rate/readme/CONTRIBUTORS.rst b/hr_timesheet_overtime_rate/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000..f1ac675 --- /dev/null +++ b/hr_timesheet_overtime_rate/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Coop IT Easy SC `_: + + * Carmen Bianca BAKKER diff --git a/hr_timesheet_overtime_rate/readme/DESCRIPTION.rst b/hr_timesheet_overtime_rate/readme/DESCRIPTION.rst new file mode 100644 index 0000000..2f57b00 --- /dev/null +++ b/hr_timesheet_overtime_rate/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Define an extra rate for working certain days. diff --git a/hr_timesheet_overtime_rate/readme/ROADMAP.rst b/hr_timesheet_overtime_rate/readme/ROADMAP.rst new file mode 100644 index 0000000..b590c14 --- /dev/null +++ b/hr_timesheet_overtime_rate/readme/ROADMAP.rst @@ -0,0 +1,13 @@ +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. + +Because ``unit_amount`` is computed from ``hours_worked``, this module is not +compatible with ``hr_timesheet_begin_end``.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. diff --git a/hr_timesheet_overtime/security/ir.model.access.csv b/hr_timesheet_overtime_rate/security/ir.model.access.csv similarity index 100% rename from hr_timesheet_overtime/security/ir.model.access.csv rename to hr_timesheet_overtime_rate/security/ir.model.access.csv diff --git a/hr_timesheet_overtime_rate/static/description/index.html b/hr_timesheet_overtime_rate/static/description/index.html new file mode 100644 index 0000000..85c3b42 --- /dev/null +++ b/hr_timesheet_overtime_rate/static/description/index.html @@ -0,0 +1,436 @@ + + + + + +Overtime Rate + + + +
+

Overtime Rate

+ + +

Beta License: AGPL-3 coopiteasy/cie-timesheet

+

Define an extra rate for working certain days.

+

Table of contents

+ +
+

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.

+

Because unit_amount is computed from hours_worked, this module is not +compatible with hr_timesheet_begin_end.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

+

Bugs are tracked on GitHub 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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • Coop IT Easy SC
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

Current maintainer:

+

carmenbianca

+

This module is part of the coopiteasy/cie-timesheet project on GitHub.

+

You are welcome to contribute.

+
+
+
+ + diff --git a/hr_timesheet_overtime_rate/tests/__init__.py b/hr_timesheet_overtime_rate/tests/__init__.py new file mode 100644 index 0000000..f143b69 --- /dev/null +++ b/hr_timesheet_overtime_rate/tests/__init__.py @@ -0,0 +1,5 @@ +# SPDX-FileCopyrightText: 2024 Coop IT Easy SC +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +from . import test_overtime diff --git a/hr_timesheet_overtime_rate/tests/test_overtime.py b/hr_timesheet_overtime_rate/tests/test_overtime.py new file mode 100644 index 0000000..ab23cfe --- /dev/null +++ b/hr_timesheet_overtime_rate/tests/test_overtime.py @@ -0,0 +1,58 @@ +# SPDX-FileCopyrightText: 2024 Coop IT Easy SC +# +# SPDX-License-Identifier: AGPL-3.0-or-later + +from datetime import date + +from odoo.tests.common import TransactionCase + + +class TestOvertime(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + # users + user1_dict = {"name": "User 1", "login": "user1", "password": "user1"} + cls.user1 = cls.env["res.users"].create(user1_dict) + # employees + employee1_dict = { + "name": "Employee 1", + "user_id": cls.user1.id, + "address_id": cls.user1.partner_id.id, + } + cls.employee1 = cls.env["hr.employee"].create(employee1_dict) + # projects + cls.project_01 = cls.env["project.project"].create({"name": "Project 01"}) + + def test_write_multiple_lines(self): + """When writing multiple analytic lines, overtime rates are applied + separately to each record. + """ + overtime = self.env["resource.overtime"].create({"name": "test"}) + self.env["resource.overtime.rate"].create( + { + "name": "test", + "dayofweek": "0", # Monday + "rate": 2.0, + "overtime_id": overtime.id, + } + ) + + lines = self.env["account.analytic.line"].browse() + # monday and tuesday + for day in range(9, 11): + lines += self.env["account.analytic.line"].create( + { + "project_id": self.project_01.id, + "amount": 0.0, + "date": date(2019, 12, day), + "name": "-", + "employee_id": self.employee1.id, + } + ) + lines.write({"hours_worked": 1}) + + self.assertEqual(lines[0].unit_amount, 2) + self.assertEqual(lines[0].hours_worked, 1) + self.assertEqual(lines[1].unit_amount, 1) + self.assertEqual(lines[1].hours_worked, 1) diff --git a/hr_timesheet_overtime/views/account_analytic_line_views.xml b/hr_timesheet_overtime_rate/views/account_analytic_line_views.xml similarity index 100% rename from hr_timesheet_overtime/views/account_analytic_line_views.xml rename to hr_timesheet_overtime_rate/views/account_analytic_line_views.xml diff --git a/hr_timesheet_overtime_rate/views/hr_timesheet_sheet_views.xml b/hr_timesheet_overtime_rate/views/hr_timesheet_sheet_views.xml new file mode 100644 index 0000000..88eeea4 --- /dev/null +++ b/hr_timesheet_overtime_rate/views/hr_timesheet_sheet_views.xml @@ -0,0 +1,59 @@ + + + + hr.timesheet.sheet.form + hr_timesheet.sheet + + + + + + hours_worked + + + + + + + + + + + + + + + + + + + + + diff --git a/hr_timesheet_overtime/views/resource_view.xml b/hr_timesheet_overtime_rate/views/resource_views.xml similarity index 100% rename from hr_timesheet_overtime/views/resource_view.xml rename to hr_timesheet_overtime_rate/views/resource_views.xml diff --git a/setup/hr_timesheet_overtime_rate/odoo/addons/hr_timesheet_overtime_rate b/setup/hr_timesheet_overtime_rate/odoo/addons/hr_timesheet_overtime_rate new file mode 120000 index 0000000..cb4c829 --- /dev/null +++ b/setup/hr_timesheet_overtime_rate/odoo/addons/hr_timesheet_overtime_rate @@ -0,0 +1 @@ +../../../../hr_timesheet_overtime_rate \ No newline at end of file diff --git a/setup/hr_timesheet_overtime_rate/setup.py b/setup/hr_timesheet_overtime_rate/setup.py new file mode 100644 index 0000000..28c57bb --- /dev/null +++ b/setup/hr_timesheet_overtime_rate/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) From 907d4666b7c3dff7ccc2331830d36d0e26d46650 Mon Sep 17 00:00:00 2001 From: Carmen Bianca BAKKER Date: Fri, 5 Jul 2024 17:31:10 +0200 Subject: [PATCH 3/8] [REM] hr_timesheet_overtime_rate: Make summary view read-only Signed-off-by: Carmen Bianca BAKKER --- hr_timesheet_overtime_rate/README.rst | 4 +++ hr_timesheet_overtime_rate/models/__init__.py | 2 -- .../models/hr_timesheet_sheet.py | 14 --------- .../models/hr_timesheet_sheet_line.py | 31 ------------------- hr_timesheet_overtime_rate/readme/ROADMAP.rst | 4 +++ .../static/description/index.html | 3 ++ .../views/hr_timesheet_sheet_views.xml | 15 +++------ 7 files changed, 15 insertions(+), 58 deletions(-) delete mode 100644 hr_timesheet_overtime_rate/models/hr_timesheet_sheet.py delete mode 100644 hr_timesheet_overtime_rate/models/hr_timesheet_sheet_line.py diff --git a/hr_timesheet_overtime_rate/README.rst b/hr_timesheet_overtime_rate/README.rst index 9baae5f..f2fe4ca 100644 --- a/hr_timesheet_overtime_rate/README.rst +++ b/hr_timesheet_overtime_rate/README.rst @@ -46,6 +46,10 @@ 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. +Furthermore, the summary view of timesheet sheets are set read-only in this +module. Because of programming complexities, it is not easy to change this view +to use ``hours_worked`` instead of ``unit_amount``. + Bug Tracker =========== diff --git a/hr_timesheet_overtime_rate/models/__init__.py b/hr_timesheet_overtime_rate/models/__init__.py index 8bfbbd0..0aa99e9 100644 --- a/hr_timesheet_overtime_rate/models/__init__.py +++ b/hr_timesheet_overtime_rate/models/__init__.py @@ -3,7 +3,5 @@ # SPDX-License-Identifier: AGPL-3.0-or-later from . import account_analytic_line -from . import hr_timesheet_sheet -from . import hr_timesheet_sheet_line from . import resource_overtime from . import resource_overtime_rate diff --git a/hr_timesheet_overtime_rate/models/hr_timesheet_sheet.py b/hr_timesheet_overtime_rate/models/hr_timesheet_sheet.py deleted file mode 100644 index 9489431..0000000 --- a/hr_timesheet_overtime_rate/models/hr_timesheet_sheet.py +++ /dev/null @@ -1,14 +0,0 @@ -# SPDX-FileCopyrightText: 2024 Coop IT Easy SC -# -# SPDX-License-Identifier: AGPL-3.0-or-later - -from odoo import models - - -class HrTimesheetSheet(models.Model): - _inherit = "hr_timesheet.sheet" - - 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 diff --git a/hr_timesheet_overtime_rate/models/hr_timesheet_sheet_line.py b/hr_timesheet_overtime_rate/models/hr_timesheet_sheet_line.py deleted file mode 100644 index 38e0de3..0000000 --- a/hr_timesheet_overtime_rate/models/hr_timesheet_sheet_line.py +++ /dev/null @@ -1,31 +0,0 @@ -# SPDX-FileCopyrightText: 2024 Coop IT Easy SC -# -# SPDX-License-Identifier: AGPL-3.0-or-later - -from odoo import api, fields, models - - -class HrTimesheetSheetLineAbstract(models.AbstractModel): - _inherit = "hr_timesheet.sheet.line.abstract" - - hours_worked = fields.Float(default=0.0) - unit_amount = fields.Float( - compute="_compute_unit_amount_from_hours", readonly=False - ) - - # TODO: this is basically identical to account.analytic.line. it's probably - # fine? - @api.depends("hours_worked", "date") - def _compute_unit_amount_from_hours(self): - for line in self: - line.unit_amount = line.hours_worked * self.env[ - "account.analytic.line" - ].rate_for_date(line.date) - - -class HrTimesheetSheetLine(models.TransientModel): - _inherit = "hr_timesheet.sheet.line" - - @api.onchange("unit_amount", "hours_worked") - def onchange_unit_amount(self): - return super().onchange_unit_amount() diff --git a/hr_timesheet_overtime_rate/readme/ROADMAP.rst b/hr_timesheet_overtime_rate/readme/ROADMAP.rst index b590c14..f6a36a7 100644 --- a/hr_timesheet_overtime_rate/readme/ROADMAP.rst +++ b/hr_timesheet_overtime_rate/readme/ROADMAP.rst @@ -11,3 +11,7 @@ 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. + +Furthermore, the summary view of timesheet sheets are set read-only in this +module. Because of programming complexities, it is not easy to change this view +to use ``hours_worked`` instead of ``unit_amount``. diff --git a/hr_timesheet_overtime_rate/static/description/index.html b/hr_timesheet_overtime_rate/static/description/index.html index 85c3b42..dd99b2d 100644 --- a/hr_timesheet_overtime_rate/static/description/index.html +++ b/hr_timesheet_overtime_rate/static/description/index.html @@ -397,6 +397,9 @@

Known issues / Roadmap

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.

+

Furthermore, the summary view of timesheet sheets are set read-only in this +module. Because of programming complexities, it is not easy to change this view +to use hours_worked instead of unit_amount.

Bug Tracker

diff --git a/hr_timesheet_overtime_rate/views/hr_timesheet_sheet_views.xml b/hr_timesheet_overtime_rate/views/hr_timesheet_sheet_views.xml index 88eeea4..639ff7d 100644 --- a/hr_timesheet_overtime_rate/views/hr_timesheet_sheet_views.xml +++ b/hr_timesheet_overtime_rate/views/hr_timesheet_sheet_views.xml @@ -5,18 +5,11 @@ hr_timesheet.sheet - - + - hours_worked - - - - + 1 Date: Thu, 11 Jul 2024 13:18:46 +0200 Subject: [PATCH 4/8] [FIX] hr_timesheet_overtime_rate: Populate hours_worked on installation Signed-off-by: Carmen Bianca BAKKER --- hr_timesheet_overtime_rate/__manifest__.py | 1 + hr_timesheet_overtime_rate/data/data.xml | 13 +++++++++++ .../migrations/16.0.1.0.0/post-upgrade.py | 19 --------------- .../models/account_analytic_line.py | 23 +++++++++++++++++++ 4 files changed, 37 insertions(+), 19 deletions(-) create mode 100644 hr_timesheet_overtime_rate/data/data.xml delete mode 100644 hr_timesheet_overtime_rate/migrations/16.0.1.0.0/post-upgrade.py diff --git a/hr_timesheet_overtime_rate/__manifest__.py b/hr_timesheet_overtime_rate/__manifest__.py index b8c3f79..d5c5e84 100644 --- a/hr_timesheet_overtime_rate/__manifest__.py +++ b/hr_timesheet_overtime_rate/__manifest__.py @@ -19,6 +19,7 @@ "excludes": [], "data": [ "security/ir.model.access.csv", + "data/data.xml", "views/resource_views.xml", "views/account_analytic_line_views.xml", "views/hr_timesheet_sheet_views.xml", diff --git a/hr_timesheet_overtime_rate/data/data.xml b/hr_timesheet_overtime_rate/data/data.xml new file mode 100644 index 0000000..202225e --- /dev/null +++ b/hr_timesheet_overtime_rate/data/data.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/hr_timesheet_overtime_rate/migrations/16.0.1.0.0/post-upgrade.py b/hr_timesheet_overtime_rate/migrations/16.0.1.0.0/post-upgrade.py deleted file mode 100644 index 9cc5489..0000000 --- a/hr_timesheet_overtime_rate/migrations/16.0.1.0.0/post-upgrade.py +++ /dev/null @@ -1,19 +0,0 @@ -# SPDX-FileCopyrightText: 2024 Coop IT Easy SC -# -# SPDX-License-Identifier: AGPL-3.0-or-later - - -def migrate(cr, version): - # This is not strictly true, but it's the best way to populate the field - # with sensible data. - # - # TODO: Does this run upon module installation? This needs to be run on - # module installation. - cr.execute( - # Perfect symmetry is joyous - """ - UPDATE account_analytic_line - SET hours_worked=unit_amount - WHERE project_id IS NOT NULL - """ - ) diff --git a/hr_timesheet_overtime_rate/models/account_analytic_line.py b/hr_timesheet_overtime_rate/models/account_analytic_line.py index d27e8a0..6371fb2 100644 --- a/hr_timesheet_overtime_rate/models/account_analytic_line.py +++ b/hr_timesheet_overtime_rate/models/account_analytic_line.py @@ -46,3 +46,26 @@ def rate_for_date(self, date): .rate or 1.0 ) + + def _init_hours_worked(self): + """Upon module installation (or manually any other time, if you really + want), this method is called to populate hours_worked with something + sensible, derived from unit_amount and the rate for that day. + """ + # We use an SQL query because we do not want to trigger computation upon + # writing to hours_worked. + query = """ + UPDATE account_analytic_line + SET hours_worked=CASE + """ + params = [] + + for line in self.filtered(lambda item: item.project_id): + rate = self.rate_for_date(line.date) + hours_worked = line.unit_amount / rate + query += "WHEN id=%s THEN %s " + params.extend([line.id, hours_worked]) + query += "END WHERE id IN %s" + + if params: + self.env.cr.execute(query, (*params, tuple(line.id for line in self))) From 22179d177bab455d18e4b917973c1eef14f28e98 Mon Sep 17 00:00:00 2001 From: Carmen Bianca BAKKER Date: Thu, 18 Jul 2024 13:54:24 +0200 Subject: [PATCH 5/8] [REF] hr_timesheet_overtime_rate: Rate acquisition is no longer an @api.model method This makes it easier to extend with additional available information on the record. Signed-off-by: Carmen Bianca BAKKER --- .../models/account_analytic_line.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/hr_timesheet_overtime_rate/models/account_analytic_line.py b/hr_timesheet_overtime_rate/models/account_analytic_line.py index 6371fb2..f9f5971 100644 --- a/hr_timesheet_overtime_rate/models/account_analytic_line.py +++ b/hr_timesheet_overtime_rate/models/account_analytic_line.py @@ -34,12 +34,12 @@ def _compute_unit_amount_from_hours(self): # Do not compute/adjust the unit_amount of non-timesheets. lines = self.filtered(lambda line: line.project_id) for line in lines: - line.unit_amount = line.hours_worked * line.rate_for_date(line.date) + line.unit_amount = line.hours_worked * line.get_overtime_rate() - @api.model - def rate_for_date(self, date): + def get_overtime_rate(self): + self.ensure_one() # n.b. from_string also works on date objects, returning itself. - weekday = fields.Date.from_string(date).weekday() + weekday = fields.Date.from_string(self.date).weekday() return ( self.env["resource.overtime.rate"] .search([("dayofweek", "=", weekday)], limit=1) @@ -61,7 +61,7 @@ def _init_hours_worked(self): params = [] for line in self.filtered(lambda item: item.project_id): - rate = self.rate_for_date(line.date) + rate = line.get_overtime_rate() hours_worked = line.unit_amount / rate query += "WHEN id=%s THEN %s " params.extend([line.id, hours_worked]) From 509de5b3bf503d942e7e58f7f92c6510ac5a2012 Mon Sep 17 00:00:00 2001 From: Carmen Bianca BAKKER Date: Mon, 16 Sep 2024 15:00:02 +0200 Subject: [PATCH 6/8] [IMP] hr_timesheet_overtime_rate: Improve code aesthetics No functional differences; code is a little prettier. Signed-off-by: Carmen Bianca BAKKER --- hr_timesheet_overtime/static/description/index.html | 7 +++---- hr_timesheet_overtime_rate/README.rst | 2 +- hr_timesheet_overtime_rate/__manifest__.py | 7 +------ .../models/account_analytic_line.py | 3 +-- hr_timesheet_overtime_rate/readme/ROADMAP.rst | 2 +- hr_timesheet_overtime_rate/static/description/index.html | 9 ++++----- 6 files changed, 11 insertions(+), 19 deletions(-) diff --git a/hr_timesheet_overtime/static/description/index.html b/hr_timesheet_overtime/static/description/index.html index 9e211b7..0987ab3 100644 --- a/hr_timesheet_overtime/static/description/index.html +++ b/hr_timesheet_overtime/static/description/index.html @@ -8,11 +8,10 @@ /* :Author: David Goodger (goodger@python.org) -:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $ +:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $ :Copyright: This stylesheet has been placed in the public domain. Default cascading style sheet for the HTML output of Docutils. -Despite the name, some widely supported CSS2 features are used. See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to customize this style sheet. @@ -275,7 +274,7 @@ margin-left: 2em ; margin-right: 2em } -pre.code .ln { color: gray; } /* line numbers */ +pre.code .ln { color: grey; } /* line numbers */ pre.code, code { background-color: #eeeeee } pre.code .comment, code .comment { color: #5C6576 } pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } @@ -301,7 +300,7 @@ span.pre { white-space: pre } -span.problematic, pre.problematic { +span.problematic { color: red } span.section-subtitle { diff --git a/hr_timesheet_overtime_rate/README.rst b/hr_timesheet_overtime_rate/README.rst index f2fe4ca..f0a57bf 100644 --- a/hr_timesheet_overtime_rate/README.rst +++ b/hr_timesheet_overtime_rate/README.rst @@ -40,7 +40,7 @@ looking _exclusively_ at the corresponding day of the week. This should be more robust. Because ``unit_amount`` is computed from ``hours_worked``, this module is not -compatible with ``hr_timesheet_begin_end``.To make this module subsequently +compatible with ``hr_timesheet_begin_end``. 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 diff --git a/hr_timesheet_overtime_rate/__manifest__.py b/hr_timesheet_overtime_rate/__manifest__.py index d5c5e84..f2af5dd 100644 --- a/hr_timesheet_overtime_rate/__manifest__.py +++ b/hr_timesheet_overtime_rate/__manifest__.py @@ -4,19 +4,16 @@ { "name": "Overtime Rate", - "summary": """ - Define an extra rate for working certain days.""", + "summary": "Define an extra rate for working certain days.", "version": "16.0.1.0.0", "category": "Human Resources", "website": "https://github.com/coopiteasy/cie-timesheet", "author": "Coop IT Easy SC", "maintainers": ["carmenbianca"], "license": "AGPL-3", - "application": False, "depends": [ "hr_timesheet_sheet", ], - "excludes": [], "data": [ "security/ir.model.access.csv", "data/data.xml", @@ -24,6 +21,4 @@ "views/account_analytic_line_views.xml", "views/hr_timesheet_sheet_views.xml", ], - "demo": [], - "qweb": [], } diff --git a/hr_timesheet_overtime_rate/models/account_analytic_line.py b/hr_timesheet_overtime_rate/models/account_analytic_line.py index f9f5971..46b7ab1 100644 --- a/hr_timesheet_overtime_rate/models/account_analytic_line.py +++ b/hr_timesheet_overtime_rate/models/account_analytic_line.py @@ -38,8 +38,7 @@ def _compute_unit_amount_from_hours(self): def get_overtime_rate(self): self.ensure_one() - # n.b. from_string also works on date objects, returning itself. - weekday = fields.Date.from_string(self.date).weekday() + weekday = self.date.weekday() return ( self.env["resource.overtime.rate"] .search([("dayofweek", "=", weekday)], limit=1) diff --git a/hr_timesheet_overtime_rate/readme/ROADMAP.rst b/hr_timesheet_overtime_rate/readme/ROADMAP.rst index f6a36a7..5885dc0 100644 --- a/hr_timesheet_overtime_rate/readme/ROADMAP.rst +++ b/hr_timesheet_overtime_rate/readme/ROADMAP.rst @@ -6,7 +6,7 @@ looking _exclusively_ at the corresponding day of the week. This should be more robust. Because ``unit_amount`` is computed from ``hours_worked``, this module is not -compatible with ``hr_timesheet_begin_end``.To make this module subsequently +compatible with ``hr_timesheet_begin_end``. 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 diff --git a/hr_timesheet_overtime_rate/static/description/index.html b/hr_timesheet_overtime_rate/static/description/index.html index dd99b2d..bc923ac 100644 --- a/hr_timesheet_overtime_rate/static/description/index.html +++ b/hr_timesheet_overtime_rate/static/description/index.html @@ -8,11 +8,10 @@ /* :Author: David Goodger (goodger@python.org) -:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $ +:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $ :Copyright: This stylesheet has been placed in the public domain. Default cascading style sheet for the HTML output of Docutils. -Despite the name, some widely supported CSS2 features are used. See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to customize this style sheet. @@ -275,7 +274,7 @@ margin-left: 2em ; margin-right: 2em } -pre.code .ln { color: gray; } /* line numbers */ +pre.code .ln { color: grey; } /* line numbers */ pre.code, code { background-color: #eeeeee } pre.code .comment, code .comment { color: #5C6576 } pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } @@ -301,7 +300,7 @@ span.pre { white-space: pre } -span.problematic, pre.problematic { +span.problematic { color: red } span.section-subtitle { @@ -392,7 +391,7 @@

Known issues / Roadmap

looking _exclusively_ at the corresponding day of the week. This should be more robust.

Because unit_amount is computed from hours_worked, this module is not -compatible with hr_timesheet_begin_end.To make this module subsequently +compatible with hr_timesheet_begin_end. 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 From dc3d3d189a937d757b0820c950767693732867e2 Mon Sep 17 00:00:00 2001 From: Carmen Bianca BAKKER Date: Mon, 16 Sep 2024 15:37:58 +0200 Subject: [PATCH 7/8] [IMP] hr_timesheet_overtime_rate: Decrease priority of views By decreasing the priority, we make sure that hours_worked is as close to unit_amount as possible. Signed-off-by: Carmen Bianca BAKKER --- .../views/account_analytic_line_views.xml | 7 +++++++ .../views/hr_timesheet_sheet_views.xml | 1 + 2 files changed, 8 insertions(+) diff --git a/hr_timesheet_overtime_rate/views/account_analytic_line_views.xml b/hr_timesheet_overtime_rate/views/account_analytic_line_views.xml index 407c919..7366bbd 100644 --- a/hr_timesheet_overtime_rate/views/account_analytic_line_views.xml +++ b/hr_timesheet_overtime_rate/views/account_analytic_line_views.xml @@ -5,6 +5,7 @@ account.analytic.line.tree.hr_timesheet account.analytic.line + account.analytic.line.pivot account.analytic.line + @@ -31,6 +33,7 @@ account.analytic.line.graph account.analytic.line + @@ -42,6 +45,7 @@ account.analytic.line.graph account.analytic.line + @@ -53,6 +57,7 @@ account.analytic.line.graph account.analytic.line + @@ -64,6 +69,7 @@ account.analytic.line.form account.analytic.line + account.analytic.line.kanban account.analytic.line + diff --git a/hr_timesheet_overtime_rate/views/hr_timesheet_sheet_views.xml b/hr_timesheet_overtime_rate/views/hr_timesheet_sheet_views.xml index 639ff7d..cea373d 100644 --- a/hr_timesheet_overtime_rate/views/hr_timesheet_sheet_views.xml +++ b/hr_timesheet_overtime_rate/views/hr_timesheet_sheet_views.xml @@ -4,6 +4,7 @@ hr.timesheet.sheet.form hr_timesheet.sheet + + + + project.task.form.inherited (in hr_timesheet_overtime_rate) + project.task + + + + + + + + + + + +