From a111618d3aaef38364217f98dd467ee0f27f47a3 Mon Sep 17 00:00:00 2001 From: Carmen Bianca BAKKER Date: Thu, 18 Jul 2024 13:54:24 +0200 Subject: [PATCH] [REF] hr_timesheet_overtime_rate: Rate acquisition is no longer an @api.model method This makes it easier to extend with additional available information on the record. Signed-off-by: Carmen Bianca BAKKER --- .../models/account_analytic_line.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/hr_timesheet_overtime_rate/models/account_analytic_line.py b/hr_timesheet_overtime_rate/models/account_analytic_line.py index 6371fb2..e5ad3dc 100644 --- a/hr_timesheet_overtime_rate/models/account_analytic_line.py +++ b/hr_timesheet_overtime_rate/models/account_analytic_line.py @@ -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) @@ -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])