mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-07 23:22:52 +00:00
refactor: cleanup and for better readability
(cherry picked from commit 653ae84b3e)
This commit is contained in:
@@ -157,6 +157,11 @@ def resume_pcv_processing(docname: str):
|
||||
start_pcv_processing(docname)
|
||||
|
||||
|
||||
def update_default_dimensions(dimension_fields, gl_entry, dimension_values):
|
||||
for i, dimension in enumerate(dimension_fields):
|
||||
gl_entry[dimension] = dimension_values[i]
|
||||
|
||||
|
||||
def get_gle_for_pl_account(pcv, acc, balances, dimensions):
|
||||
balance_in_account_currency = flt(balances.debit_in_account_currency) - flt(
|
||||
balances.credit_in_account_currency
|
||||
@@ -185,8 +190,7 @@ def get_gle_for_pl_account(pcv, acc, balances, dimensions):
|
||||
}
|
||||
)
|
||||
# update dimensions
|
||||
for i, dimension in enumerate(dimensions):
|
||||
gl_entry[dimension] = dimensions[i]
|
||||
update_default_dimensions(get_dimensions(), gl_entry, dimensions)
|
||||
return gl_entry
|
||||
|
||||
|
||||
@@ -214,8 +218,7 @@ def get_gle_for_closing_account(pcv, dimension_balance, dimensions):
|
||||
}
|
||||
)
|
||||
# update dimensions
|
||||
for i, dimension in enumerate(dimensions):
|
||||
gl_entry[dimension] = dimensions[i]
|
||||
update_default_dimensions(get_dimensions(), gl_entry, dimensions)
|
||||
return gl_entry
|
||||
|
||||
|
||||
@@ -259,32 +262,22 @@ def schedule_next_date(docname: str):
|
||||
to_process[0].parentfield,
|
||||
)
|
||||
else:
|
||||
# summarize, build and post GL
|
||||
ppcvd = qb.DocType("Process Period Closing Voucher Detail")
|
||||
total_no_of_dates = (
|
||||
qb.from_(ppcvd).select(Count(ppcvd.star)).where(ppcvd.parent.eq(docname)).run()[0][0]
|
||||
)
|
||||
# consider both normal and opening balance
|
||||
completed = (
|
||||
qb.from_(ppcvd)
|
||||
.select(Count(ppcvd.star))
|
||||
.where(ppcvd.parent.eq(docname) & ppcvd.status.eq("Completed"))
|
||||
.run()[0][0]
|
||||
)
|
||||
# Ensure both normal and opening balances are processed for all dates
|
||||
if total_no_of_dates == completed:
|
||||
summarize_and_post_ledger_entries(docname)
|
||||
|
||||
|
||||
def summarize_and_post_ledger_entries(docname):
|
||||
# TODO: ensure all dates are processed
|
||||
running = frappe.db.get_all(
|
||||
"Process Period Closing Voucher Detail",
|
||||
filters={"parent": docname, "status": "Running"},
|
||||
fields=["processing_date"],
|
||||
order_by="processing_date",
|
||||
limit=1,
|
||||
)
|
||||
if not running:
|
||||
# calculate balances for whole PCV period
|
||||
ppcv = frappe.get_doc("Process Period Closing Voucher", docname)
|
||||
|
||||
@@ -321,9 +314,7 @@ def summarize_and_post_ledger_entries(docname):
|
||||
if balance_in_company_currency:
|
||||
pl_accounts_reverse_gle.append(get_gle_for_pl_account(pcv, acc, balances, dimensions))
|
||||
|
||||
closing_account_gle.append(
|
||||
get_gle_for_closing_account(pcv, account_balances["balances"], dimensions)
|
||||
)
|
||||
closing_account_gle.append(get_gle_for_closing_account(pcv, account_balances["balances"], dimensions))
|
||||
|
||||
gl_entries = pl_accounts_reverse_gle + closing_account_gle
|
||||
from erpnext.accounts.general_ledger import make_gl_entries
|
||||
@@ -400,8 +391,7 @@ def get_closing_entry(pcv, account, balances, dimensions):
|
||||
}
|
||||
)
|
||||
# update dimensions
|
||||
for i, dimension in enumerate(dimensions):
|
||||
closing_entry[dimension] = dimensions[i]
|
||||
update_default_dimensions(get_dimensions(), closing_entry, dimensions)
|
||||
return closing_entry
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user