Skip to content

Commit

Permalink
fix: refactor code, consider fnf payment status update via journal entry
Browse files Browse the repository at this point in the history
  • Loading branch information
AyshaHakeem committed Dec 31, 2024
1 parent 5dd9e1e commit 9079dbb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,6 @@


class FullandFinalStatement(Document):
def on_change(self):
for payable in self.payables:
if payable.component == "Gratuity":
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 All @@ -35,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 @@ -259,6 +249,18 @@ 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)
if self.docstatus == 2:
gratuity.cancel()
else:
gratuity.set_status(update=True)


@frappe.whitelist()
def get_account_and_amount(ref_doctype, ref_document):
Expand Down Expand Up @@ -313,6 +315,7 @@ def get_account_and_amount(ref_doctype, ref_document):


def update_full_and_final_statement_status(doc, method=None):
print("\n\n at update_full_and_final_statement_status \n\n")
"""Updates FnF status on Journal Entry Submission/Cancellation"""
status = "Paid" if doc.docstatus == 1 else "Unpaid"

Expand All @@ -321,3 +324,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()
15 changes: 3 additions & 12 deletions 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()
self.set_status(update=True)

@property
def gratuity_settings(self):
Expand All @@ -37,7 +37,7 @@ def gratuity_settings(self):

return self._gratuity_settings

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

if self.docstatus == 1:
Expand All @@ -48,23 +48,14 @@ def set_status(self, update=False, cancel=False):
status = "Unpaid"

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)
self.db_set("status", status)

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 9079dbb

Please sign in to comment.