Skip to content

Commit

Permalink
fixup! [ADD] hr_timesheet_overtime_begin_end
Browse files Browse the repository at this point in the history
Signed-off-by: Carmen Bianca BAKKER <[email protected]>
  • Loading branch information
carmenbianca committed Jul 11, 2024
1 parent dce782f commit 7b15e21
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,35 @@
#
# SPDX-License-Identifier: AGPL-3.0-or-later

from odoo import models
from odoo import api, fields, models


class AnalyticLine(models.Model):
_inherit = "account.analytic.line"

hours_worked = fields.Float(
store=True,
readonly=True,
compute="_compute_hours_worked",
)
unit_amount = fields.Float(
# Make sure unit_amount is computed from hours worked, NOT directly from
# time_start and time_stop.
compute="_compute_unit_amount_from_hours",
)

@api.depends("time_start", "time_stop")
def _compute_hours_worked(self):
for line in self:
line.hours_worked = self._hours_from_start_stop(
line.time_start, line.time_stop
)

# Add date to constrains.
@api.constrains("time_start", "time_stop", "unit_amount", "date")
def _check_time_start_stop(self):
return super()._check_time_start_stop()

def unit_amount_from_start_stop(self):
result = super().unit_amount_from_start_stop()
result *= self.rate_for_date(self.date)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,9 @@ def test_rate_not_double_applied(self):
# The rate was already applied on the transient record. Don't also apply
# it on creation.
self.assertEqual(line_record.unit_amount, 4.0)

def test_rate_changes_on_date(self):
line = self.base_line()
line_record = self.env["account.analytic.line"].create(line)
line_record.date = "2024-01-02"
self.assertEqual(line_record.unit_amount, line_record.hours_worked)

0 comments on commit 7b15e21

Please sign in to comment.