brotherton-erpnext/erpnext/patches/v14_0/update_total_asset_cost_field.py
mergify[bot] 58f1df5004
feat: total_asset_cost field (backport #38879) (#38887)
* feat: total_asset_cost field (#38879)

(cherry picked from commit d370c60a6c840be23ec4094593b9bbf1d1dca88b)

# Conflicts:
#	erpnext/patches.txt

* chore: resolve conflicts

* chore: remove unnecessary patch

---------

Co-authored-by: Anand Baburajan <anandbaburajan@gmail.com>
2023-12-20 22:47:48 +05:30

18 lines
538 B
Python

import frappe
def execute():
asset = frappe.qb.DocType("Asset")
frappe.qb.update(asset).set(asset.total_asset_cost, asset.gross_purchase_amount).run()
asset_repair_list = frappe.db.get_all(
"Asset Repair",
filters={"docstatus": 1, "repair_status": "Completed", "capitalize_repair_cost": 1},
fields=["asset", "repair_cost"],
)
for asset_repair in asset_repair_list:
frappe.qb.update(asset).set(
asset.total_asset_cost, asset.total_asset_cost + asset_repair.repair_cost
).where(asset.name == asset_repair.asset).run()