Skip to content

Commit

Permalink
fixup! [ADD] hr_timesheet_overtime_begin_end
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 4, 2024
1 parent 7f84162 commit c09e734
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions hr_timesheet_overtime_begin_end/tests/test_analytic_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,29 @@ def test_rate_applied_after_edit(self):
line_record = self.env["account.analytic.line"].create(line)
line_record.write({"time_start": 10.0, "time_stop": 12.0})
self.assertEqual(line_record.unit_amount, 4.0)

def test_rate_not_double_applied(self):
line = self.base_line()
del line["time_start"]
del line["time_stop"]

# Emulating a transient record before it is actually created.
line_new = self.env["account.analytic.line"].new(line)
line_new.time_start = 10.0
line_new.time_stop = 12.0
self.assertEqual(line_new.unit_amount, 4.0)

# Prepare the transient data for writing to a new record.
#
# Annoyingly, the value for unit_amount is not in _cache, so we have to
# add it here.
#
# Ideally I would emulate this with a Form(), but the necessary fields
# are not available in a form. This is the closest emulation.
vals = line_new._convert_to_write(line_new._cache)
vals.setdefault("unit_amount", line_new.unit_amount)
line_record = self.env["account.analytic.line"].create(vals)

# The rate was already applied on the transient record. Don't also apply
# it on creation.
self.assertEqual(line_record.unit_amount, 4.0)

0 comments on commit c09e734

Please sign in to comment.