Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Closing balance for period closing and reporting #34257

Merged
merged 35 commits into from Mar 24, 2023

Conversation

deepeshgarg007
Copy link
Member

@deepeshgarg007 deepeshgarg007 commented Mar 1, 2023

Introducing a new doctype "Account Closing Balance" for calculating opening balances in Financial Statements

Adding this brings in some minor restrictions on the way users post accounting entries in ERPNext.
Since the calculation of the closing balances is tied to the period closing voucher, users won't be able to change any accounting entry or post opening-entries before the period closing voucher's posting date. Only once the period closing voucher is canceled previous entries can be updated.

This also has support for custom accounting dimensions so dimension-based filtering is also possible. If there are PCVs posted and no account closing balances have been created then by default GL entries are used for computation as per the current behavior

Why is this required?

Right now for calculating the opening balances or even account balances the reports and functions go through all the previous GLs (could be of just 1 fiscal year or 10 years for some) even when practically there is not much change in the entries

These reports and functions usually take a lot of time or fail for users dealing with more than a million GL entries, so pre-computing balances for such time frames help with such performance improvements.

On a typical site with 1.5 million GL entries running the trial balance report without "Account Closing Balance" the report takes around 21s whereas with "Account Closing Balance" it comes down to 8s

Before:
Screenshot 2023-03-08 at 2 27 25 PM

After:
Screenshot 2023-03-08 at 2 27 40 PM

ToDo List

  • Update Trial Balance report
  • Patch to create closing balance records
  • Update financial statements (Balance Sheet)

no-docs

@deepeshgarg007 deepeshgarg007 marked this pull request as ready for review March 21, 2023 11:30
erpnext/accounts/general_ledger.py Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Mar 23, 2023

Codecov Report

Merging #34257 (8ce1da1) into develop (d8e73b6) will increase coverage by 0.01%.
The diff coverage is 58.33%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #34257      +/-   ##
===========================================
+ Coverage    63.79%   63.80%   +0.01%     
===========================================
  Files          809      810       +1     
  Lines        59347    59530     +183     
===========================================
+ Hits         37859    37984     +125     
- Misses       21488    21546      +58     
Impacted Files Coverage Δ
...ext/accounts/report/balance_sheet/balance_sheet.py 36.03% <0.00%> (-0.33%) ⬇️
...cial_statement/consolidated_financial_statement.py 88.78% <ø> (ø)
...ext/accounts/report/trial_balance/trial_balance.py 0.00% <0.00%> (ø)
erpnext/hooks.py 100.00% <ø> (ø)
erpnext/accounts/report/financial_statements.py 31.29% <5.00%> (-1.66%) ⬇️
erpnext/accounts/utils.py 75.35% <83.33%> (+0.31%) ⬆️
...e/period_closing_voucher/period_closing_voucher.py 85.91% <92.42%> (+4.59%) ⬆️
erpnext/accounts/general_ledger.py 94.24% <92.85%> (-0.08%) ⬇️
...account_closing_balance/account_closing_balance.py 93.75% <93.75%> (ø)

... and 5 files with indirect coverage changes

@nabinhait nabinhait merged commit 282a0ee into frappe:develop Mar 24, 2023
13 checks passed
@deepeshgarg007 deepeshgarg007 added the backport version-14-hotfix backport to version 14 label Jul 9, 2023
deepeshgarg007 added a commit that referenced this pull request Jul 10, 2023
* feat: Introduce opening entry for reporting

(cherry picked from commit 9739d8b)

* feat: Introduce opening entry for reporting

(cherry picked from commit b44a19b)

* fix: Add patches to create accounting dimension in Closing Balance

(cherry picked from commit 36c08d0)

* feat: Cascade closing balances on PCV submit

(cherry picked from commit c3f39c3)

# Conflicts:
#	erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.py
#	erpnext/patches.txt

* feat: Add views in standard filter

(cherry picked from commit e18336e)

* chore: Rewrite query using query builder

(cherry picked from commit 7fa7d6b)

# Conflicts:
#	erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.py

* feat: Add validations against period closing voucher

(cherry picked from commit f92c63f)

* fix: Order by issue in aggregation query

(cherry picked from commit 6607c8b)

* fix: Add patch to update closing balances

(cherry picked from commit a663df3)

* fix: Closing balance entries for period closing voucher

(cherry picked from commit 436fc03)

* fix: Update patch to generate closing balance entries

(cherry picked from commit 95c9aaf)

# Conflicts:
#	erpnext/patches.txt

* perf: Apply closing balance in Trial Balance report

(cherry picked from commit e5f603c)

# Conflicts:
#	erpnext/accounts/report/trial_balance/trial_balance.py

* chore: Minor fixes

(cherry picked from commit c089c41)

# Conflicts:
#	erpnext/patches.txt

* fix: Aggregation with previous closing balance

(cherry picked from commit 4a2046d)

# Conflicts:
#	erpnext/patches.txt

* test: Add static posting dates to tests

(cherry picked from commit 310f71c)

* chore: Add index to period closing voucher column

(cherry picked from commit 5dabc98)

* chore: rename Closing Balance to Account Closing Balance

(cherry picked from commit 3249a79)

* test: Add test case for closing balance

(cherry picked from commit f0267fe)

* chore: Use account closing balance in set gl entries

(cherry picked from commit 0157fa1)

# Conflicts:
#	erpnext/accounts/report/financial_statements.py

* fix: Update patch

(cherry picked from commit 76775a3)

* fix: Account sub query

(cherry picked from commit 7f11373)

* chore: Simplify query

(cherry picked from commit 00fe304)

# Conflicts:
#	erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.py

* chore: Add missing validations

(cherry picked from commit 0aadb68)

* chore: Remove unnecessary list comprehension

(cherry picked from commit 44053db)

# Conflicts:
#	erpnext/accounts/report/financial_statements.py

* fix: Ignore opening entries if PCV posted

(cherry picked from commit f9397a8)

# Conflicts:
#	erpnext/accounts/report/financial_statements.py

* fix: Don't validate if no GL Entry exists

(cherry picked from commit 528ab50)

* chore: Fix Typo

(cherry picked from commit 3fd9520)

* fix: Validation for cancelation

(cherry picked from commit 30eb6c8)

* fix: Partial trial balance view

(cherry picked from commit b7dcf27)

* fix: CS financial statement param

(cherry picked from commit f8cff09)

* chore: Improve validation message

(cherry picked from commit 8ce1da1)

* chore: Resolve conflicts

* chore: Resolve conflicts

---------

Co-authored-by: Deepesh Garg <deepeshgarg6@gmail.com>
frappe-pr-bot pushed a commit that referenced this pull request Jul 11, 2023
# [14.30.0](v14.29.2...v14.30.0) (2023-07-11)

### Bug Fixes

* accepted warehouse and rejected warehouse can't be same ([5d77e3c](5d77e3c))
* also check on_hold ([#35910](#35910)) ([59b3277](59b3277))
* conflicts ([e55a264](e55a264))
* conflicts ([79f9785](79f9785))
* conflicts ([a178e66](a178e66))
* conflicts ([6459c28](6459c28))
* deferred accounting entries on accounts frozen ([#35978](#35978)) ([573183c](573183c))
* Delivery Note return valuation ([296f312](296f312))
* German translations ([#35990](#35990)) ([b7b864e](b7b864e))
* incorrect status in MR created from PP (backport [#36085](#36085)) ([#36086](#36086)) ([6dc7a19](6dc7a19))
* incorrect TCS amount while customer has advance payment ([#35397](#35397)) ([2a4bbf3](2a4bbf3))
* labels and translations ([#35963](#35963)) ([04b1d45](04b1d45))
* Opening balance in presentation currency in Trial Balance report ([#36036](#36036)) ([39e38bf](39e38bf))
* payment entry `voucher_type` error ([#35779](#35779)) ([f3af0b2](f3af0b2))
* **Payment Entry:** compare rounded amount ([#36011](#36011)) ([d80b0aa](d80b0aa))
* possible type error on ERR creation ([0569899](0569899))
* precision causing outstanding issue on partly paid invoices ([#36030](#36030)) ([3e711e8](3e711e8))
* Share ledger showing cancelled docs ([#35993](#35993)) ([5102d0c](5102d0c))
* Validate for missing expense account ([#36078](#36078)) ([f4f886c](f4f886c))
* Vietnamese translation of "Company" ([#35887](#35887)) ([e443e6c](e443e6c))

### Features

* Closing balance for period closing and reporting ([#34257](#34257)) ([ebf3c01](ebf3c01))
@JitendraSAW
Copy link

@deepeshgarg007 , Can you help us as we can check this Use Case, Can you provide any List of Transactions or Flow we can check the same.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants