Skip to content

Commit

Permalink
fix: set gratuity to unpaid on FFN cancellation, edit test
Browse files Browse the repository at this point in the history
  • Loading branch information
AyshaHakeem committed Jan 1, 2025
1 parent 8f98b70 commit da2d504
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,7 @@ def set_gratuity_status(self):
gratuity = frappe.get_doc("Gratuity", payable.reference_document)
amount = payable.amount if self.docstatus == 1 and self.status == "Paid" else 0
gratuity.db_set("paid_amount", amount)
if self.docstatus == 2:
gratuity.cancel()
else:
gratuity.set_status(update=True)
gratuity.set_status(update=True)


@frappe.whitelist()
Expand Down
4 changes: 3 additions & 1 deletion hrms/payroll/doctype/gratuity/gratuity.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def validate(self):
data = self.calculate_work_experience_and_amount()
self.current_work_experience = data["current_work_experience"]
self.amount = data["amount"]
self.set_status(update=True)
self.set_status()

@property
def gratuity_settings(self):
Expand Down Expand Up @@ -49,6 +49,8 @@ def set_status(self, update=False):

if update and self.status != status:
self.db_set("status", status)
else:
self.status = status

def on_submit(self):
if self.pay_via_salary_slip:
Expand Down
12 changes: 7 additions & 5 deletions hrms/payroll/doctype/gratuity/test_gratuity.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

from hrms.hr.doctype.attendance.attendance import mark_attendance
from hrms.hr.doctype.expense_claim.test_expense_claim import get_payable_account
from hrms.hr.doctype.full_and_final_statement.full_and_final_statement import (
update_full_and_final_statement_status,
)
from hrms.payroll.doctype.gratuity.gratuity import get_last_salary_slip
from hrms.payroll.doctype.salary_slip.test_salary_slip import (
make_deduction_salary_component,
Expand Down Expand Up @@ -202,20 +205,19 @@ def test_settle_gratuity_via_fnf_statement(self):
"status": "Settled",
},
)
fnf.save()
fnf.create_journal_entry()

# mark fnf as paid and submit it
fnf.status = "Paid"
fnf.save()
fnf.submit()

fnf.set_gratuity_status()

gratuity.reload()
self.assertEqual(gratuity.status, "Paid")
self.assertEqual(gratuity.status, fnf.status)

fnf.cancel()
gratuity.reload()
self.assertEqual(gratuity.status, "Cancelled")
self.assertEqual(gratuity.status, "Unpaid")


def setup_gratuity_rule(name: str) -> dict:
Expand Down

0 comments on commit da2d504

Please sign in to comment.