Skip to content

Commit d861ab0

Browse files
committed
[MIG] hr_timesheet_overtime_begin_end: backport to 12.0
Signed-off-by: Carmen Bianca BAKKER <[email protected]>
1 parent 521f400 commit d861ab0

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

hr_timesheet_overtime_begin_end/__manifest__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@
66
"name": "Timesheet - Overtime and begin/end hours compatibility",
77
"summary": """
88
Make the two modules compatible.""",
9-
"version": "16.0.1.0.0",
9+
"version": "12.0.1.0.0",
1010
"category": "Human Resources",
11-
"website": "https://github.com/coopiteasy/cie-timesheet",
11+
"website": "https://coopiteasy.be",
1212
"author": "Coop IT Easy SC",
1313
"maintainers": ["carmenbianca"],
1414
"license": "AGPL-3",
1515
"application": False,
1616
"depends": [
1717
"hr_timesheet_overtime",
18-
"hr_timesheet_begin_end",
18+
"hr_timesheet_activity_begin_end",
1919
],
2020
"auto_install": True,
2121
}

hr_timesheet_overtime_begin_end/models/account_analytic_line.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,32 @@
22
#
33
# SPDX-License-Identifier: AGPL-3.0-or-later
44

5-
from odoo import models
5+
from odoo import api, models
66

77

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

11+
# This is a bit of a hack. Normally in hr_timesheet_overtime, the value of
12+
# unit_amount is updated in this method as part of writing or creating a
13+
# record. However, in hr_timesheet_activity_begin_end, unit_amount is
14+
# adjusted during an onchange using unit_amount_from_start_stop.
15+
#
16+
# If BOTH the onchange and the write method adjust the value of unit_amount,
17+
# then the rate is applied twice, which is not good. Therefore, this method
18+
# is 'disabled', and we instead rely on onchange to correctly set the value
19+
# of unit_amount.
20+
#
21+
# The disadvantage is that programmatic usages of hr_timesheet_overtime no
22+
# longer work here. The advantage is that you can now manually override the
23+
# value of unit_amount without the rate being automatically applied.
24+
#
25+
# In version 16, this behaviour is a lot less messy, because it uses compute
26+
# functions instead of the aforementioned methods.
27+
@api.model
28+
def _update_values(self, values):
29+
return
30+
1131
def unit_amount_from_start_stop(self):
1232
result = super().unit_amount_from_start_stop()
1333
result *= self.rate_for_date(self.date)

hr_timesheet_overtime_begin_end/tests/test_analytic_line.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
#
33
# SPDX-License-Identifier: AGPL-3.0-or-later
44

5-
from odoo.tests.common import TransactionCase
5+
from odoo.tests.common import SavepointCase
66

77

8-
class TestAnalyticLine(TransactionCase):
8+
class TestAnalyticLine(SavepointCase):
99
@classmethod
1010
def setUpClass(cls):
1111
super().setUpClass()
@@ -34,15 +34,8 @@ def base_line(self):
3434

3535
def test_rate_applied(self):
3636
line = self.base_line()
37-
line_record = self.env["account.analytic.line"].create(line)
38-
self.assertEqual(line_record.unit_amount, 4.0)
39-
40-
def test_rate_applied_after_edit(self):
41-
line = self.base_line()
42-
del line["time_start"]
43-
del line["time_stop"]
44-
line_record = self.env["account.analytic.line"].create(line)
45-
line_record.write({"time_start": 10.0, "time_stop": 12.0})
37+
line_record = self.env["account.analytic.line"].new(line)
38+
line_record.onchange_hours_start_stop()
4639
self.assertEqual(line_record.unit_amount, 4.0)
4740

4841
def test_rate_not_double_applied(self):
@@ -54,6 +47,7 @@ def test_rate_not_double_applied(self):
5447
line_new = self.env["account.analytic.line"].new(line)
5548
line_new.time_start = 10.0
5649
line_new.time_stop = 12.0
50+
line_new.onchange_hours_start_stop()
5751
self.assertEqual(line_new.unit_amount, 4.0)
5852

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

0 commit comments

Comments
 (0)