From 961e691bdcd2dbed08af35fee3e185371ddd72a6 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Thu, 24 Mar 2022 22:36:20 +0530 Subject: [PATCH] fix: Expense Claim conditions for Paid status - status doesn't change to Paid if the entire required amount is already covered via linked advances - status doesn't change to Paid if the claim is partially paid via advances - patch to update such uncancelled claims to Paid --- .../hr/doctype/expense_claim/expense_claim.py | 12 ++++++++--- erpnext/patches.txt | 1 + ..._expense_claim_status_for_paid_advances.py | 21 +++++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 erpnext/patches/v13_0/update_expense_claim_status_for_paid_advances.py diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.py b/erpnext/hr/doctype/expense_claim/expense_claim.py index 7e3898b7d51..f11d4018878 100644 --- a/erpnext/hr/doctype/expense_claim/expense_claim.py +++ b/erpnext/hr/doctype/expense_claim/expense_claim.py @@ -42,10 +42,16 @@ class ExpenseClaim(AccountsController): "2": "Cancelled" }[cstr(self.docstatus or 0)] - paid_amount = flt(self.total_amount_reimbursed) + flt(self.total_advance_amount) precision = self.precision("grand_total") - if (self.is_paid or (flt(self.total_sanctioned_amount) > 0 and self.docstatus == 1 - and flt(self.grand_total, precision) == flt(paid_amount, precision))) and self.approval_status == 'Approved': + + if ( + # set as paid + self.is_paid + # grand total is reimbursed + or (flt(self.total_sanctioned_amount) > 0 and self.docstatus == 1 and flt(self.grand_total, precision) == flt(self.total_amount_reimbursed, precision)) + # grand total (to be paid) is 0 since linked advances already cover the claimed amount + or (flt(self.grand_total, precision) == 0) + ) and self.approval_status == "Approved": status = "Paid" elif flt(self.total_sanctioned_amount) > 0 and self.docstatus == 1 and self.approval_status == 'Approved': status = "Unpaid" diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 3faab2eb1d1..70f642b7fdb 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -355,3 +355,4 @@ erpnext.patches.v13_0.update_accounts_in_loan_docs erpnext.patches.v13_0.remove_unknown_links_to_prod_plan_items # 24-03-2022 erpnext.patches.v13_0.rename_non_profit_fields erpnext.patches.v13_0.enable_ksa_vat_docs #1 +erpnext.patches.v13_0.update_expense_claim_status_for_paid_advances \ No newline at end of file diff --git a/erpnext/patches/v13_0/update_expense_claim_status_for_paid_advances.py b/erpnext/patches/v13_0/update_expense_claim_status_for_paid_advances.py new file mode 100644 index 00000000000..206d032f534 --- /dev/null +++ b/erpnext/patches/v13_0/update_expense_claim_status_for_paid_advances.py @@ -0,0 +1,21 @@ +import frappe + + +def execute(): + """ + Update Expense Claim status to Paid if: + - the entire required amount is already covered via linked advances + - the claim is partially paid via advances and the rest is reimbursed + """ + + ExpenseClaim = frappe.qb.DocType('Expense Claim') + + (frappe.qb + .update(ExpenseClaim) + .set(ExpenseClaim.status, 'Paid') + .where( + ((ExpenseClaim.grand_total == 0) | (ExpenseClaim.grand_total == ExpenseClaim.total_amount_reimbursed)) + & (ExpenseClaim.approval_status == 'Approved') + & (ExpenseClaim.docstatus != 2) + ) + ).run()