-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: patch to enable total number of booked depreciations field (ba…
…ckport #41940) (#42042) * chore: patch to enable total number of booked depreciations field (#41940) * chore: patch to enable total number of booked depreciations field * fix: conflict resolved * refactor: replaced fb_row.db_set with set_value (cherry picked from commit 5fdd1d3) # Conflicts: # erpnext/patches.txt * fix: resolved conflicts * fix: removed unmerged patches --------- Co-authored-by: Khushi Rawat <142375893+khushi8112@users.noreply.github.com>
- Loading branch information
1 parent
cf4d4ba
commit b294357
Showing
3 changed files
with
37 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
erpnext/patches/v15_0/update_total_number_of_booked_depreciations.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import frappe | ||
|
||
from erpnext.assets.doctype.asset_depreciation_schedule.asset_depreciation_schedule import ( | ||
get_depr_schedule, | ||
) | ||
|
||
|
||
def execute(): | ||
if frappe.db.has_column("Asset Finance Book", "total_number_of_booked_depreciations"): | ||
assets = frappe.get_all( | ||
"Asset", filters={"docstatus": 1}, fields=["name", "opening_number_of_booked_depreciations"] | ||
) | ||
|
||
for asset in assets: | ||
asset_doc = frappe.get_doc("Asset", asset.name) | ||
|
||
for fb_row in asset_doc.get("finance_books"): | ||
depr_schedule = get_depr_schedule(asset.name, "Active", fb_row.finance_book) | ||
total_number_of_booked_depreciations = asset.opening_number_of_booked_depreciations or 0 | ||
|
||
for je in depr_schedule: | ||
if je.journal_entry: | ||
total_number_of_booked_depreciations += 1 | ||
frappe.db.set_value( | ||
"Asset Finance Book", | ||
fb_row.name, | ||
"total_number_of_booked_depreciations", | ||
total_number_of_booked_depreciations, | ||
) |