diff --git a/hr_timesheet_overtime_begin_end/tests/test_analytic_line.py b/hr_timesheet_overtime_begin_end/tests/test_analytic_line.py index 5d187ec..27ef66d 100644 --- a/hr_timesheet_overtime_begin_end/tests/test_analytic_line.py +++ b/hr_timesheet_overtime_begin_end/tests/test_analytic_line.py @@ -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)