From d27b647ac49308b8f23382d43aa2db0863f43111 Mon Sep 17 00:00:00 2001 From: Aysha Date: Thu, 31 Oct 2024 17:48:58 +0530 Subject: [PATCH 1/3] fix: update status of reference documents --- .../full_and_final_statement/full_and_final_statement.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/hrms/hr/doctype/full_and_final_statement/full_and_final_statement.py b/hrms/hr/doctype/full_and_final_statement/full_and_final_statement.py index 2a465d1ed6..5424f75e11 100644 --- a/hrms/hr/doctype/full_and_final_statement/full_and_final_statement.py +++ b/hrms/hr/doctype/full_and_final_statement/full_and_final_statement.py @@ -8,6 +8,9 @@ class FullandFinalStatement(Document): + def on_change(self): + update_status_of_reference_documents(self, self.status) + def before_insert(self): self.get_outstanding_statements() @@ -310,3 +313,9 @@ 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() + + +def update_status_of_reference_documents(doc, status="Paid"): + for payable in doc.payables: + if payable.component == "Gratuity": + frappe.db.set_value("Gratuity", payable.reference_document, "status", status) From daaf601c2105c95a49c8909fb354f1dff30d61fd Mon Sep 17 00:00:00 2001 From: Aysha Date: Tue, 19 Nov 2024 12:35:42 +0530 Subject: [PATCH 2/3] fix: set gratuity paid_amont field --- .../full_and_final_statement.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/hrms/hr/doctype/full_and_final_statement/full_and_final_statement.py b/hrms/hr/doctype/full_and_final_statement/full_and_final_statement.py index 5424f75e11..482fdd4bc9 100644 --- a/hrms/hr/doctype/full_and_final_statement/full_and_final_statement.py +++ b/hrms/hr/doctype/full_and_final_statement/full_and_final_statement.py @@ -9,7 +9,13 @@ class FullandFinalStatement(Document): def on_change(self): - update_status_of_reference_documents(self, self.status) + for payable in self.payables: + if payable.component == "Gratuity": + frappe.db.set_value( + "Gratuity", + payable.reference_document, + {"status": self.status, "paid_amount": payable.amount}, + ) def before_insert(self): self.get_outstanding_statements() @@ -313,9 +319,3 @@ 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() - - -def update_status_of_reference_documents(doc, status="Paid"): - for payable in doc.payables: - if payable.component == "Gratuity": - frappe.db.set_value("Gratuity", payable.reference_document, "status", status) From 59e509da69a78ac653416e2fdf00737ca39fa0e6 Mon Sep 17 00:00:00 2001 From: Aysha Date: Tue, 10 Dec 2024 14:08:08 +0530 Subject: [PATCH 3/3] fix: effect of fnf statement cancellation on gratuity record --- .../full_and_final_statement.py | 11 ++++++----- hrms/payroll/doctype/gratuity/gratuity.py | 13 ++++++++++--- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/hrms/hr/doctype/full_and_final_statement/full_and_final_statement.py b/hrms/hr/doctype/full_and_final_statement/full_and_final_statement.py index 482fdd4bc9..a48c4860b8 100644 --- a/hrms/hr/doctype/full_and_final_statement/full_and_final_statement.py +++ b/hrms/hr/doctype/full_and_final_statement/full_and_final_statement.py @@ -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() diff --git a/hrms/payroll/doctype/gratuity/gratuity.py b/hrms/payroll/doctype/gratuity/gratuity.py index ea7d80db31..0747513276 100644 --- a/hrms/payroll/doctype/gratuity/gratuity.py +++ b/hrms/payroll/doctype/gratuity/gratuity.py @@ -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: @@ -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)