Skip to content

Commit

Permalink
[MIG] hr_timesheet_overtime_begin_end: backport to 12.0
Browse files Browse the repository at this point in the history
Signed-off-by: Carmen Bianca BAKKER <[email protected]>
  • Loading branch information
carmenbianca committed Jul 18, 2024
1 parent 521f400 commit d861ab0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
6 changes: 3 additions & 3 deletions hr_timesheet_overtime_begin_end/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
"name": "Timesheet - Overtime and begin/end hours compatibility",
"summary": """
Make the two modules compatible.""",
"version": "16.0.1.0.0",
"version": "12.0.1.0.0",
"category": "Human Resources",
"website": "https://github.com/coopiteasy/cie-timesheet",
"website": "https://coopiteasy.be",
"author": "Coop IT Easy SC",
"maintainers": ["carmenbianca"],
"license": "AGPL-3",
"application": False,
"depends": [
"hr_timesheet_overtime",
"hr_timesheet_begin_end",
"hr_timesheet_activity_begin_end",
],
"auto_install": True,
}
22 changes: 21 additions & 1 deletion hr_timesheet_overtime_begin_end/models/account_analytic_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,32 @@
#
# SPDX-License-Identifier: AGPL-3.0-or-later

from odoo import models
from odoo import api, models


class AnalyticLine(models.Model):
_inherit = "account.analytic.line"

# This is a bit of a hack. Normally in hr_timesheet_overtime, the value of
# unit_amount is updated in this method as part of writing or creating a
# record. However, in hr_timesheet_activity_begin_end, unit_amount is
# adjusted during an onchange using unit_amount_from_start_stop.
#
# If BOTH the onchange and the write method adjust the value of unit_amount,
# then the rate is applied twice, which is not good. Therefore, this method
# is 'disabled', and we instead rely on onchange to correctly set the value
# of unit_amount.
#
# The disadvantage is that programmatic usages of hr_timesheet_overtime no
# longer work here. The advantage is that you can now manually override the
# value of unit_amount without the rate being automatically applied.
#
# In version 16, this behaviour is a lot less messy, because it uses compute
# functions instead of the aforementioned methods.
@api.model
def _update_values(self, values):
return

def unit_amount_from_start_stop(self):
result = super().unit_amount_from_start_stop()
result *= self.rate_for_date(self.date)
Expand Down
16 changes: 5 additions & 11 deletions hr_timesheet_overtime_begin_end/tests/test_analytic_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
#
# SPDX-License-Identifier: AGPL-3.0-or-later

from odoo.tests.common import TransactionCase
from odoo.tests.common import SavepointCase


class TestAnalyticLine(TransactionCase):
class TestAnalyticLine(SavepointCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
Expand Down Expand Up @@ -34,15 +34,8 @@ def base_line(self):

def test_rate_applied(self):
line = self.base_line()
line_record = self.env["account.analytic.line"].create(line)
self.assertEqual(line_record.unit_amount, 4.0)

def test_rate_applied_after_edit(self):
line = self.base_line()
del line["time_start"]
del line["time_stop"]
line_record = self.env["account.analytic.line"].create(line)
line_record.write({"time_start": 10.0, "time_stop": 12.0})
line_record = self.env["account.analytic.line"].new(line)
line_record.onchange_hours_start_stop()
self.assertEqual(line_record.unit_amount, 4.0)

def test_rate_not_double_applied(self):
Expand All @@ -54,6 +47,7 @@ def test_rate_not_double_applied(self):
line_new = self.env["account.analytic.line"].new(line)
line_new.time_start = 10.0
line_new.time_stop = 12.0
line_new.onchange_hours_start_stop()
self.assertEqual(line_new.unit_amount, 4.0)

# Prepare the transient data for writing to a new record.
Expand Down

0 comments on commit d861ab0

Please sign in to comment.