Skip to content

Commit

Permalink
Merge PR #40 into 12.0
Browse files Browse the repository at this point in the history
Signed-off-by huguesdk
  • Loading branch information
github-grap-bot committed Oct 11, 2024
2 parents 2a65a86 + 77e55c7 commit 9932b7c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
10 changes: 8 additions & 2 deletions hr_timesheet_overtime/models/account_analytic_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
31 changes: 31 additions & 0 deletions hr_timesheet_overtime/tests/test_overtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 9932b7c

Please sign in to comment.