Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update status of gratuity record referenced in fnf #2518

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def before_submit(self):

def on_cancel(self):
self.ignore_linked_doctypes = ("GL Entry",)
self.set_gratuity_status()

def validate_relieving_date(self):
if not self.relieving_date:
Expand Down Expand Up @@ -248,6 +249,15 @@ def create_journal_entry(self):
)
return jv

def set_gratuity_status(self):
for payable in self.payables:
if payable.component != "Gratuity":
continue
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)
gratuity.set_status(update=True)


@frappe.whitelist()
def get_account_and_amount(ref_doctype, ref_document):
Expand Down Expand Up @@ -310,3 +320,4 @@ def update_full_and_final_statement_status(doc, method=None):
fnf = frappe.get_doc("Full and Final Statement", entry.reference_name)
fnf.db_set("status", status)
fnf.notify_update()
fnf.set_gratuity_status()
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
2 changes: 1 addition & 1 deletion hrms/payroll/doctype/gratuity/gratuity.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def set_status(self, update=False):
else:
status = "Unpaid"

if update:
if update and self.status != status:
self.db_set("status", status)
else:
self.status = status
Expand Down
49 changes: 49 additions & 0 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 @@ -171,6 +174,51 @@ 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.create_journal_entry()
fnf.status = "Paid"
fnf.save()
fnf.submit()

fnf.set_gratuity_status()

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

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


def setup_gratuity_rule(name: str) -> dict:
from hrms.regional.united_arab_emirates.setup import setup
Expand Down Expand Up @@ -201,6 +249,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
Loading