diff --git a/hrms/hr/doctype/employee_advance/employee_advance.py b/hrms/hr/doctype/employee_advance/employee_advance.py index ddfba1fbd2..7d1d67f186 100644 --- a/hrms/hr/doctype/employee_advance/employee_advance.py +++ b/hrms/hr/doctype/employee_advance/employee_advance.py @@ -103,13 +103,18 @@ def set_total_advance_paid(self): if return_amount != 0: return_amount = flt(return_amount) / flt(self.exchange_rate) - if flt(paid_amount) > self.advance_amount: + precision = self.precision("paid_amount") + paid_amount = flt(paid_amount, precision) + if paid_amount > flt(self.advance_amount, precision): frappe.throw( _("Row {0}# Paid Amount cannot be greater than requested advance amount"), EmployeeAdvanceOverPayment, ) - if flt(return_amount) > 0 and flt(return_amount) > (self.paid_amount - self.claimed_amount): + precision = self.precision("return_amount") + return_amount = flt(return_amount, precision) + + if return_amount > 0 and return_amount > flt(self.paid_amount - self.claimed_amount, precision): frappe.throw(_("Return amount cannot be greater than unclaimed amount")) self.db_set("paid_amount", paid_amount) diff --git a/hrms/hr/doctype/employee_advance/test_employee_advance.py b/hrms/hr/doctype/employee_advance/test_employee_advance.py index 3d46d1c7a3..a042f43fd5 100644 --- a/hrms/hr/doctype/employee_advance/test_employee_advance.py +++ b/hrms/hr/doctype/employee_advance/test_employee_advance.py @@ -219,6 +219,45 @@ def test_payment_entry_against_advance(self): self.assertEqual(advance.status, "Unpaid") self.assertEqual(advance.paid_amount, 700) + def test_precision(self): + employee_name = make_employee("_T@employee.advance") + advance = make_employee_advance(employee_name) + journal_entry = make_journal_entry_for_advance(advance) + journal_entry.submit() + + # PARTLY CLAIMED AND RETURNED + payable_account = get_payable_account("_Test Company") + claim = make_expense_claim( + payable_account, 650.35, 619.34, "_Test Company", "Travel Expenses - _TC", do_not_submit=True + ) + + claim = get_advances_for_claim(claim, advance.name, amount=619.34) + claim.save() + claim.submit() + + advance.reload() + self.assertEqual(advance.status, "Paid") + + entry = make_return_entry( + employee=advance.employee, + company=advance.company, + employee_advance_name=advance.name, + return_amount=advance.paid_amount - advance.claimed_amount, + advance_account=advance.advance_account, + mode_of_payment=advance.mode_of_payment, + currency=advance.currency, + exchange_rate=advance.exchange_rate, + ) + + entry = frappe.get_doc(entry) + entry.insert() + entry.submit() + + advance.reload() + # precision is respected + self.assertEqual(advance.return_amount, 380.66) + self.assertEqual(advance.status, "Partly Claimed and Returned") + def make_journal_entry_for_advance(advance): journal_entry = frappe.get_doc(make_bank_entry("Employee Advance", advance.name))