diff --git a/hr_timesheet_overtime/models/account_analytic_line.py b/hr_timesheet_overtime/models/account_analytic_line.py index b4667b9..038e0aa 100644 --- a/hr_timesheet_overtime/models/account_analytic_line.py +++ b/hr_timesheet_overtime/models/account_analytic_line.py @@ -24,8 +24,14 @@ def create(self, vals_list): @api.multi def write(self, values): if not self.env.context.get("create"): # sale module - self._update_values(values) - return super().write(values) + for record in self: + # TODO: this is slow and inefficient. + vals_copy = values.copy() + record._update_values(vals_copy) + super(AnalyticLine, record).write(vals_copy) + return True + else: + return super().write(values) @api.model def _update_values(self, values): diff --git a/hr_timesheet_overtime/tests/test_overtime.py b/hr_timesheet_overtime/tests/test_overtime.py index ee73fa9..54eb0b9 100644 --- a/hr_timesheet_overtime/tests/test_overtime.py +++ b/hr_timesheet_overtime/tests/test_overtime.py @@ -421,3 +421,34 @@ def test_stored_change_today(self): self.assertEqual(self.ts1.working_time, 9 * 5) # Affected by the extra overtime self.assertEqual(self.ts1.timesheet_overtime, 2) + + def test_write_multiple_lines(self): + """When writing multiple analytic lines, overtime rates are applied + separately to each record. + """ + overtime = self.env["resource.overtime"].create({"name": "test"}) + self.env["resource.overtime.rate"].create( + { + "name": "test", + "dayofweek": "0", # Monday + "rate": 2.0, + "overtime_id": overtime.id, + } + ) + + lines = self.env["account.analytic.line"].browse() + # monday and tuesday + for day in range(9, 11): + lines += self.env["account.analytic.line"].create( + { + "project_id": self.project_01.id, + "amount": 0.0, + "date": date(2019, 12, day), + "name": "-", + "employee_id": self.employee1.id, + } + ) + lines.write({"unit_amount": 1}) + + self.assertEqual(lines[0].unit_amount, 2) + self.assertEqual(lines[1].unit_amount, 1)