Skip to content

Commit

Permalink
fix: set per_billed based on hours when amounts are zero (#33984)
Browse files Browse the repository at this point in the history
fix: set per_billed based on hours when amounts are zero (#33984)

* fix: set per_billed based on hours when amounts are zero

* test: calculate_percentage_billed

(cherry picked from commit e4953df)

Co-authored-by: Raffael Meyer <14891507+barredterra@users.noreply.github.com>
  • Loading branch information
mergify[bot] and barredterra authored Feb 11, 2023
1 parent b0ed3c8 commit 5270fbe
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
31 changes: 31 additions & 0 deletions erpnext/projects/doctype/timesheet/test_timesheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,37 @@ def test_to_time(self):
to_time = timesheet.time_logs[0].to_time
self.assertEqual(to_time, add_to_date(from_time, hours=2, as_datetime=True))

def test_per_billed_hours(self):
"""If amounts are 0, per_billed should be calculated based on hours."""
ts = frappe.new_doc("Timesheet")
ts.total_billable_amount = 0
ts.total_billed_amount = 0
ts.total_billable_hours = 2

ts.total_billed_hours = 0.5
ts.calculate_percentage_billed()
self.assertEqual(ts.per_billed, 25)

ts.total_billed_hours = 2
ts.calculate_percentage_billed()
self.assertEqual(ts.per_billed, 100)

def test_per_billed_amount(self):
"""If amounts are > 0, per_billed should be calculated based on amounts, regardless of hours."""
ts = frappe.new_doc("Timesheet")
ts.total_billable_hours = 2
ts.total_billed_hours = 1
ts.total_billable_amount = 200
ts.total_billed_amount = 50
ts.calculate_percentage_billed()
self.assertEqual(ts.per_billed, 25)

ts.total_billed_hours = 3
ts.total_billable_amount = 200
ts.total_billed_amount = 200
ts.calculate_percentage_billed()
self.assertEqual(ts.per_billed, 100)


def make_timesheet(
employee,
Expand Down
2 changes: 2 additions & 0 deletions erpnext/projects/doctype/timesheet/timesheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def calculate_percentage_billed(self):
self.per_billed = 0
if self.total_billed_amount > 0 and self.total_billable_amount > 0:
self.per_billed = (self.total_billed_amount * 100) / self.total_billable_amount
elif self.total_billed_hours > 0 and self.total_billable_hours > 0:
self.per_billed = (self.total_billed_hours * 100) / self.total_billable_hours

def update_billing_hours(self, args):
if args.is_billable:
Expand Down

0 comments on commit 5270fbe

Please sign in to comment.