Skip to content

Commit

Permalink
fix: effect of fnf statement cancellation on gratuity record
Browse files Browse the repository at this point in the history
  • Loading branch information
AyshaHakeem committed Dec 16, 2024
1 parent b5af146 commit 2a131a2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ class FullandFinalStatement(Document):
def on_change(self):
for payable in self.payables:
if payable.component == "Gratuity":
frappe.db.set_value(
"Gratuity",
payable.reference_document,
{"status": self.status, "paid_amount": payable.amount},
)
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)

def before_insert(self):
self.get_outstanding_statements()
Expand Down
13 changes: 10 additions & 3 deletions hrms/payroll/doctype/gratuity/gratuity.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def gratuity_settings(self):

return self._gratuity_settings

def set_status(self, update=False):
def set_status(self, update=False, cancel=False):
status = {"0": "Draft", "1": "Submitted", "2": "Cancelled"}[cstr(self.docstatus or 0)]

if self.docstatus == 1:
Expand All @@ -47,17 +47,24 @@ def set_status(self, update=False):
else:
status = "Unpaid"

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

if cancel and self.docstatus != 2:
self.db_set("docstatus", 2)

def on_submit(self):
if self.pay_via_salary_slip:
self.create_additional_salary()
else:
self.create_gl_entries()

def on_change(self):
self.set_status(update=True)

def on_cancel(self):
self.ignore_linked_doctypes = ["GL Entry"]
self.create_gl_entries(cancel=True)
Expand Down

0 comments on commit 2a131a2

Please sign in to comment.