Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[12.0][FIX] hr_timesheet_overtime: Make write function accept multiple records #40

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading