Skip to content

Commit

Permalink
[REF] hr_timesheet_overtime_rate: Rate acquisition is no longer an @a…
Browse files Browse the repository at this point in the history
…pi.model method

This makes it easier to extend with additional available information on
the record.

Signed-off-by: Carmen Bianca BAKKER <[email protected]>
  • Loading branch information
carmenbianca committed Jul 18, 2024
1 parent 90d017e commit a111618
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions hr_timesheet_overtime_rate/models/account_analytic_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ def _compute_unit_amount_from_hours(self):
# Do not compute/adjust the unit_amount of non-timesheets.
lines = self.filtered(lambda line: line.project_id)
for line in lines:
line.unit_amount = line.hours_worked * line.rate_for_date(line.date)
line.unit_amount = line.hours_worked * line.get_rate()

@api.model
def rate_for_date(self, date):
def get_rate(self):
self.ensure_one()
# n.b. from_string also works on date objects, returning itself.
weekday = fields.Date.from_string(date).weekday()
weekday = fields.Date.from_string(self.date).weekday()
return (
self.env["resource.overtime.rate"]
.search([("dayofweek", "=", weekday)], limit=1)
Expand All @@ -61,7 +61,7 @@ def _init_hours_worked(self):
params = []

for line in self.filtered(lambda item: item.project_id):
rate = self.rate_for_date(line.date)
rate = line.get_rate()
hours_worked = line.unit_amount / rate
query += "WHEN id=%s THEN %s "
params.extend([line.id, hours_worked])
Expand Down

0 comments on commit a111618

Please sign in to comment.