Skip to content

Commit

Permalink
chore: add gratuity test and update fnf test
Browse files Browse the repository at this point in the history
  • Loading branch information
AyshaHakeem committed Dec 18, 2024
1 parent 2a131a2 commit 5dd9e1e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ class FullandFinalStatement(Document):
def on_change(self):
for payable in self.payables:
if payable.component == "Gratuity":
gratuity = frappe.get_doc("Gratuity", payable.reference_document)
if self.status == "Paid":
amount = payable.amount if self.docstatus == 1 else 0
gratuity.db_set("paid_amount", amount)
if self.docstatus == 2:
gratuity.set_status(update=True, cancel=True)
if frappe.db.exists("Gratuity", payable.reference_document):
gratuity = frappe.get_doc("Gratuity", payable.reference_document)
if self.status == "Paid":
amount = payable.amount if self.docstatus == 1 else 0
gratuity.db_set("paid_amount", amount)
if self.docstatus == 2:
gratuity.set_status(cancel=True)

def before_insert(self):
self.get_outstanding_statements()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_check_bootstraped_data_asset_movement_and_jv_creation(self):
"Leave Encashment",
]

receivable_bootstraped_component = ["Employee Advance", "Loan"]
receivable_bootstraped_component = self.fnf.get_receivable_component()

# checking payables and receivables bootstraped value
self.assertEqual([payable.component for payable in self.fnf.payables], payables_bootstraped_component)
Expand Down
47 changes: 47 additions & 0 deletions hrms/payroll/doctype/gratuity/test_gratuity.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,52 @@ def test_gratuity_amount_consistent_irrespective_of_payment_days(self):
)
self.assertEqual(gratuity.amount, 190000.0)

@set_holiday_list("Salary Slip Test Holiday List", "_Test Company")
def test_settle_gratuity_via_fnf_statement(self):
from hrms.hr.doctype.full_and_final_statement.test_full_and_final_statement import (
create_full_and_final_statement,
)

create_salary_slip(self.employee)
setup_gratuity_rule("Rule Under Limited Contract (UAE)")
set_mode_of_payment_account()

# create gratuity
gratuity = create_gratuity(
expense_account="Payment Account - _TC", mode_of_payment="Cash", employee=self.employee
)
gratuity.reload()

# create Full and Final Statement and add gratuity as Payables
fnf = create_full_and_final_statement(self.employee)
fnf.payables = []
fnf.receivables = []
fnf.append(
"payables",
{
"component": "Gratuity",
"reference_document_type": "Gratuity",
"reference_document": gratuity.name,
"amount": gratuity.amount,
"account": gratuity.payable_account,
"status": "Settled",
},
)
fnf.save()
fnf.create_journal_entry()

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

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

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


def setup_gratuity_rule(name: str) -> dict:
from hrms.regional.united_arab_emirates.setup import setup
Expand Down Expand Up @@ -201,6 +247,7 @@ def create_gratuity(**args):
gratuity.expense_account = args.expense_account or "Payment Account - _TC"
gratuity.payable_account = args.payable_account or get_payable_account("_Test Company")
gratuity.mode_of_payment = args.mode_of_payment or "Cash"
gratuity.cost_center = args.cost_center or "Main - _TC"

gratuity.save()
gratuity.submit()
Expand Down

0 comments on commit 5dd9e1e

Please sign in to comment.