From a663df376cfb37a902a2b6005daf9af849a2eeb1 Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Sun, 26 Feb 2023 16:06:04 +0530 Subject: [PATCH] fix: Add patch to update closing balances --- .../patches/v14_0/update_closing_balances.py | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/erpnext/patches/v14_0/update_closing_balances.py b/erpnext/patches/v14_0/update_closing_balances.py index cd120b553cc..47d26257bed 100644 --- a/erpnext/patches/v14_0/update_closing_balances.py +++ b/erpnext/patches/v14_0/update_closing_balances.py @@ -2,8 +2,25 @@ # License: MIT. See LICENSE -# import frappe +import frappe + +from erpnext.accounts.utils import get_fiscal_year def execute(): - pass + company_wise_order = {} + for pcv in frappe.db.get_all( + "Period Closing Voucher", + fields=["company", "posting_date", "name"], + filters={"docstatus": 1}, + order_by="posting_date", + ): + + company_wise_order.setdefault(pcv.company, []) + if pcv.posting_date not in company_wise_order[pcv.company]: + pcv_doc = frappe.get_doc("Period Closing Voucher", pcv.name) + pcv_doc.year_start_date = get_fiscal_year( + pcv.posting_date, pcv.fiscal_year, company=pcv.company + )[1] + pcv_doc.make_closing_entries() + company_wise_order[pcv.company].append(pcv.posting_date)