* feat: Introduce opening entry for reporting (cherry picked from commit9739d8b52a) * feat: Introduce opening entry for reporting (cherry picked from commitb44a19bd1a) * fix: Add patches to create accounting dimension in Closing Balance (cherry picked from commit36c08d0835) * feat: Cascade closing balances on PCV submit (cherry picked from commitc3f39c3f32) # Conflicts: # erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.py # erpnext/patches.txt * feat: Add views in standard filter (cherry picked from commite18336ebe7) * chore: Rewrite query using query builder (cherry picked from commit7fa7d6b5e4) # Conflicts: # erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.py * feat: Add validations against period closing voucher (cherry picked from commitf92c63fb10) * fix: Order by issue in aggregation query (cherry picked from commit6607c8bd82) * fix: Add patch to update closing balances (cherry picked from commita663df376c) * fix: Closing balance entries for period closing voucher (cherry picked from commit436fc03eda) * fix: Update patch to generate closing balance entries (cherry picked from commit95c9aafda9) # Conflicts: # erpnext/patches.txt * perf: Apply closing balance in Trial Balance report (cherry picked from commite5f603c9d9) # Conflicts: # erpnext/accounts/report/trial_balance/trial_balance.py * chore: Minor fixes (cherry picked from commitc089c4156c) # Conflicts: # erpnext/patches.txt * fix: Aggregation with previous closing balance (cherry picked from commit4a2046dfb6) # Conflicts: # erpnext/patches.txt * test: Add static posting dates to tests (cherry picked from commit310f71c313) * chore: Add index to period closing voucher column (cherry picked from commit5dabc98ba5) * chore: rename Closing Balance to Account Closing Balance (cherry picked from commit3249a79f07) * test: Add test case for closing balance (cherry picked from commitf0267feca8) * chore: Use account closing balance in set gl entries (cherry picked from commit0157fa15eb) # Conflicts: # erpnext/accounts/report/financial_statements.py * fix: Update patch (cherry picked from commit76775a3e49) * fix: Account sub query (cherry picked from commit7f11373b58) * chore: Simplify query (cherry picked from commit00fe3042b2) # Conflicts: # erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.py * chore: Add missing validations (cherry picked from commit0aadb680eb) * chore: Remove unnecessary list comprehension (cherry picked from commit44053db010) # Conflicts: # erpnext/accounts/report/financial_statements.py * fix: Ignore opening entries if PCV posted (cherry picked from commitf9397a87ac) # Conflicts: # erpnext/accounts/report/financial_statements.py * fix: Don't validate if no GL Entry exists (cherry picked from commit528ab503f2) * chore: Fix Typo (cherry picked from commit3fd95200da) * fix: Validation for cancelation (cherry picked from commit30eb6c8512) * fix: Partial trial balance view (cherry picked from commitb7dcf27b01) * fix: CS financial statement param (cherry picked from commitf8cff09129) * chore: Improve validation message (cherry picked from commit8ce1da111e) * chore: Resolve conflicts * chore: Resolve conflicts --------- Co-authored-by: Deepesh Garg <deepeshgarg6@gmail.com>
69 lines
1.9 KiB
Python
69 lines
1.9 KiB
Python
# Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and Contributors
|
|
# License: MIT. See LICENSE
|
|
|
|
|
|
import frappe
|
|
|
|
from erpnext.accounts.doctype.account_closing_balance.account_closing_balance import (
|
|
make_closing_entries,
|
|
)
|
|
from erpnext.accounts.utils import get_fiscal_year
|
|
|
|
|
|
def execute():
|
|
frappe.db.truncate("Account Closing Balance")
|
|
|
|
i = 0
|
|
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]
|
|
|
|
# get gl entries against pcv
|
|
gl_entries = frappe.db.get_all(
|
|
"GL Entry", filters={"voucher_no": pcv.name, "is_cancelled": 0}, fields=["*"]
|
|
)
|
|
for entry in gl_entries:
|
|
entry["is_period_closing_voucher_entry"] = 1
|
|
entry["closing_date"] = pcv_doc.posting_date
|
|
entry["period_closing_voucher"] = pcv_doc.name
|
|
|
|
# get all gl entries for the year
|
|
closing_entries = frappe.db.get_all(
|
|
"GL Entry",
|
|
filters={
|
|
"is_cancelled": 0,
|
|
"voucher_no": ["!=", pcv.name],
|
|
"posting_date": ["between", [pcv_doc.year_start_date, pcv.posting_date]],
|
|
"is_opening": "No",
|
|
},
|
|
fields=["*"],
|
|
)
|
|
|
|
if i == 0:
|
|
# add opening entries only for the first pcv
|
|
closing_entries += frappe.db.get_all(
|
|
"GL Entry",
|
|
filters={"is_cancelled": 0, "is_opening": "Yes"},
|
|
fields=["*"],
|
|
)
|
|
|
|
for entry in closing_entries:
|
|
entry["closing_date"] = pcv_doc.posting_date
|
|
entry["period_closing_voucher"] = pcv_doc.name
|
|
|
|
make_closing_entries(gl_entries + closing_entries, voucher_name=pcv.name)
|
|
company_wise_order[pcv.company].append(pcv.posting_date)
|
|
|
|
i += 1
|