Skip to content

Commit

Permalink
[REF] hr_timesheet_overtime: Make more extensible
Browse files Browse the repository at this point in the history
Signed-off-by: Carmen Bianca BAKKER <[email protected]>
  • Loading branch information
carmenbianca committed Jun 20, 2024
1 parent cbb8410 commit 53a2a48
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions hr_timesheet_overtime/models/account_analytic_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,19 @@ def _update_values(self, values):
Update values if date or unit_amount fields have changed
"""
if "date" in values or "unit_amount" in values:
# TODO: self.date and self.unit_amount do not exist when called from
# create().
date = values.get("date", self.date)
unit_amount = values.get("unit_amount", self.unit_amount)

# rate management
weekday = fields.Date.from_string(date).weekday()
rate = (
self.env["resource.overtime.rate"]
.search([("dayofweek", "=", weekday)], limit=1)
.rate
or 1.0
)

# update
values["unit_amount"] = unit_amount * rate
values["unit_amount"] = unit_amount * self.rate_for_date(date)

@api.model
def rate_for_date(self, date):
# n.b. from_string also works on date objects, returning itself.
weekday = fields.Date.from_string(date).weekday()
return (
self.env["resource.overtime.rate"]
.search([("dayofweek", "=", weekday)], limit=1)
.rate
or 1.0
)

0 comments on commit 53a2a48

Please sign in to comment.