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 79d67c49ae..949fbb89e7 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,17 @@ 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() @@ -24,7 +35,6 @@ 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: @@ -249,18 +259,6 @@ 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): @@ -315,7 +313,6 @@ 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" @@ -324,4 +321,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() - fnf.set_gratuity_status() diff --git a/hrms/payroll/doctype/gratuity/gratuity.py b/hrms/payroll/doctype/gratuity/gratuity.py index 23d997e055..0747513276 100644 --- a/hrms/payroll/doctype/gratuity/gratuity.py +++ b/hrms/payroll/doctype/gratuity/gratuity.py @@ -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(update=True) + self.set_status() @property def gratuity_settings(self): @@ -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: @@ -48,7 +48,13 @@ def set_status(self, update=False): status = "Unpaid" if update and self.status != status: - self.db_set("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: @@ -56,6 +62,9 @@ def on_submit(self): 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)