fix: incorrect accumulated depr amount in asset depr ledger (#41654)
* fix: incorrect accumulated depr amount in asset depr ledger
* refactor: depreciation amount retrieval with query builder
* style: apply formatting changes from pre-commit
(cherry picked from commit a8fc32dc32)
Co-authored-by: Khushi Rawat <142375893+khushi8112@users.noreply.github.com>
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
import frappe
|
||||
from frappe import _
|
||||
from frappe.query_builder import DocType
|
||||
from frappe.utils import cstr, flt
|
||||
|
||||
|
||||
@@ -75,11 +76,24 @@ def get_data(filters):
|
||||
asset_data = assets_details.get(d.against_voucher)
|
||||
if asset_data:
|
||||
if not asset_data.get("accumulated_depreciation_amount"):
|
||||
asset_data.accumulated_depreciation_amount = d.debit + asset_data.get(
|
||||
"opening_accumulated_depreciation"
|
||||
)
|
||||
AssetDepreciationSchedule = DocType("Asset Depreciation Schedule")
|
||||
DepreciationSchedule = DocType("Depreciation Schedule")
|
||||
query = (
|
||||
frappe.qb.from_(DepreciationSchedule)
|
||||
.join(AssetDepreciationSchedule)
|
||||
.on(DepreciationSchedule.parent == AssetDepreciationSchedule.name)
|
||||
.select(DepreciationSchedule.accumulated_depreciation_amount)
|
||||
.where(
|
||||
(AssetDepreciationSchedule.asset == d.against_voucher)
|
||||
& (DepreciationSchedule.parenttype == "Asset Depreciation Schedule")
|
||||
& (DepreciationSchedule.schedule_date == d.posting_date)
|
||||
)
|
||||
).run(as_dict=True)
|
||||
asset_data.accumulated_depreciation_amount = query[0]["accumulated_depreciation_amount"]
|
||||
|
||||
else:
|
||||
asset_data.accumulated_depreciation_amount += d.debit
|
||||
asset_data.opening_accumulated_depreciation = asset_data.accumulated_depreciation_amount - d.debit
|
||||
|
||||
row = frappe._dict(asset_data)
|
||||
row.update(
|
||||
|
||||
Reference in New Issue
Block a user