From cbb8410c8595876f7b21412f50d58e2b8ee3b884 Mon Sep 17 00:00:00 2001 From: Carmen Bianca BAKKER Date: Thu, 20 Jun 2024 14:19:21 +0200 Subject: [PATCH 1/3] [IMP] hr_timesheet_overtime: Use model_create_multi in analytic line Signed-off-by: Carmen Bianca BAKKER --- hr_timesheet_overtime/models/account_analytic_line.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/hr_timesheet_overtime/models/account_analytic_line.py b/hr_timesheet_overtime/models/account_analytic_line.py index 4e33ceb..2022e55 100644 --- a/hr_timesheet_overtime/models/account_analytic_line.py +++ b/hr_timesheet_overtime/models/account_analytic_line.py @@ -3,7 +3,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). import logging -from odoo import fields, models +from odoo import api, fields, models _logger = logging.getLogger(__name__) @@ -15,9 +15,11 @@ class AnalyticLine(models.Model): _inherit = "account.analytic.line" - def create(self, values): - self._update_values(values) - return super().create(values) + @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 From 53a2a481f1598d1ea25f78a5a407e698db66e877 Mon Sep 17 00:00:00 2001 From: Carmen Bianca BAKKER Date: Thu, 20 Jun 2024 14:26:44 +0200 Subject: [PATCH 2/3] [REF] hr_timesheet_overtime: Make more extensible Signed-off-by: Carmen Bianca BAKKER --- .../models/account_analytic_line.py | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/hr_timesheet_overtime/models/account_analytic_line.py b/hr_timesheet_overtime/models/account_analytic_line.py index 2022e55..47b82d8 100644 --- a/hr_timesheet_overtime/models/account_analytic_line.py +++ b/hr_timesheet_overtime/models/account_analytic_line.py @@ -31,17 +31,19 @@ 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) - - # rate management - weekday = fields.Date.from_string(date).weekday() - rate = ( - self.env["resource.overtime.rate"] - .search([("dayofweek", "=", weekday)], limit=1) - .rate - or 1.0 - ) - - # update - values["unit_amount"] = unit_amount * rate + values["unit_amount"] = unit_amount * self.rate_for_date(date) + + @api.model + def rate_for_date(self, date): + # n.b. from_string also works on date objects, returning itself. + weekday = fields.Date.from_string(date).weekday() + return ( + self.env["resource.overtime.rate"] + .search([("dayofweek", "=", weekday)], limit=1) + .rate + or 1.0 + ) From 84a8072c7b45959a3054d03035b50775413f796e Mon Sep 17 00:00:00 2001 From: Carmen Bianca BAKKER Date: Fri, 28 Jun 2024 15:30:10 +0200 Subject: [PATCH 3/3] [IMP] hr_timesheet_overtime: Add roadmap Signed-off-by: Carmen Bianca BAKKER --- hr_timesheet_overtime/README.rst | 26 ++++++++++ hr_timesheet_overtime/readme/ROADMAP.rst | 22 +++++++++ .../static/description/index.html | 48 ++++++++++++++----- 3 files changed, 83 insertions(+), 13 deletions(-) create mode 100644 hr_timesheet_overtime/readme/ROADMAP.rst diff --git a/hr_timesheet_overtime/README.rst b/hr_timesheet_overtime/README.rst index 328e663..861db99 100644 --- a/hr_timesheet_overtime/README.rst +++ b/hr_timesheet_overtime/README.rst @@ -29,6 +29,32 @@ 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/readme/ROADMAP.rst b/hr_timesheet_overtime/readme/ROADMAP.rst new file mode 100644 index 0000000..08e5a7f --- /dev/null +++ b/hr_timesheet_overtime/readme/ROADMAP.rst @@ -0,0 +1,22 @@ +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 802d4a3..b0b4321 100644 --- a/hr_timesheet_overtime/static/description/index.html +++ b/hr_timesheet_overtime/static/description/index.html @@ -366,25 +366,47 @@

Timesheet/Contract - Overtime

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

Beta License: AGPL-3 coopiteasy/cie-timesheet

Computes overtime hours according to employee’s contracts.

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 @@ -392,15 +414,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.