Skip to content

Commit

Permalink
Merge pull request #958 from frappe/version-14-hotfix
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchamahabal authored Oct 12, 2023
2 parents 58c5027 + 0a184ab commit 559917b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
19 changes: 18 additions & 1 deletion hrms/hr/doctype/expense_claim/expense_claim.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,32 +268,48 @@ def validate_account_details(self):
def calculate_total_amount(self):
self.total_claimed_amount = 0
self.total_sanctioned_amount = 0

for d in self.get("expenses"):
self.round_floats_in(d)

if self.approval_status == "Rejected":
d.sanctioned_amount = 0.0

self.total_claimed_amount += flt(d.amount)
self.total_sanctioned_amount += flt(d.sanctioned_amount)

self.round_floats_in(self, ["total_claimed_amount", "total_sanctioned_amount"])

@frappe.whitelist()
def calculate_taxes(self):
self.total_taxes_and_charges = 0
for tax in self.taxes:
self.round_floats_in(tax)

if tax.rate:
tax.tax_amount = flt(self.total_sanctioned_amount) * flt(tax.rate / 100)
tax.tax_amount = flt(
flt(self.total_sanctioned_amount) * flt(tax.rate / 100),
tax.precision("tax_amount"),
)

tax.total = flt(tax.tax_amount) + flt(self.total_sanctioned_amount)
self.total_taxes_and_charges += flt(tax.tax_amount)

self.round_floats_in(self, ["total_taxes_and_charges"])

self.grand_total = (
flt(self.total_sanctioned_amount)
+ flt(self.total_taxes_and_charges)
- flt(self.total_advance_amount)
)
self.round_floats_in(self, ["grand_total"])

def validate_advances(self):
self.total_advance_amount = 0

for d in self.get("advances"):
self.round_floats_in(d)

ref_doc = frappe.db.get_value(
"Employee Advance",
d.employee_advance,
Expand All @@ -315,6 +331,7 @@ def validate_advances(self):
self.total_advance_amount += flt(d.allocated_amount)

if self.total_advance_amount:
self.round_floats_in(self, ["total_advance_amount"])
precision = self.precision("total_advance_amount")
amount_with_taxes = flt(
(flt(self.total_sanctioned_amount, precision) + flt(self.total_taxes_and_charges, precision)),
Expand Down
31 changes: 27 additions & 4 deletions hrms/hr/doctype/expense_claim/test_expense_claim.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,12 +491,37 @@ def test_accounting_dimension_mapping(self):
self.assertEqual(dimensions.project, project)
self.assertEqual(dimensions.cost_center, expense_claim.cost_center)

def test_rounding(self):
payable_account = get_payable_account(company_name)
taxes = generate_taxes(rate=7)
expense_claim = make_expense_claim(
payable_account,
130.84,
130.84,
company_name,
"Travel Expenses - _TC3",
taxes=taxes,
)

self.assertEqual(expense_claim.total_sanctioned_amount, 130.84)
self.assertEqual(expense_claim.total_taxes_and_charges, 9.16)
self.assertEqual(expense_claim.grand_total, 140)

pe = make_payment_entry(expense_claim, 140)

expense_claim.reload()
self.assertEqual(expense_claim.status, "Paid")

pe.cancel()
expense_claim.reload()
self.assertEqual(expense_claim.status, "Unpaid")


def get_payable_account(company):
return frappe.get_cached_value("Company", company, "default_payable_account")


def generate_taxes(company=None):
def generate_taxes(company=None, rate=None) -> dict:
company = company or company_name
parent_account = frappe.db.get_value(
"Account", filters={"account_name": "Duties and Taxes", "company": company}
Expand All @@ -515,10 +540,8 @@ def generate_taxes(company=None):
{
"account_head": account,
"cost_center": cost_center,
"rate": 9,
"rate": rate or 9,
"description": "CGST",
"tax_amount": 10,
"total": 210,
}
]
}
Expand Down

0 comments on commit 559917b

Please sign in to comment.