Skip to content

Commit

Permalink
feat: total_asset_cost field (backport #38879) (#38886)
Browse files Browse the repository at this point in the history
* feat: total_asset_cost field (#38879)

(cherry picked from commit d370c60)

# Conflicts:
#	erpnext/assets/doctype/asset/asset.json
#	erpnext/assets/doctype/asset/asset.py
#	erpnext/patches.txt

* chore: resolve conflicts in asset.json

* chore: resolve conflicts in asset.py

* chore: resolve conflicts in patches.txt

---------

Co-authored-by: Anand Baburajan <anandbaburajan@gmail.com>
  • Loading branch information
mergify[bot] and anandbaburajan authored Dec 20, 2023
1 parent 4d1ccd9 commit 8169c7d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
13 changes: 11 additions & 2 deletions erpnext/assets/doctype/asset/asset.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"purchase_receipt",
"purchase_invoice",
"available_for_use_date",
"total_asset_cost",
"column_break_23",
"gross_purchase_amount",
"asset_quantity",
Expand Down Expand Up @@ -532,6 +533,14 @@
"label": "Capitalized In",
"options": "Asset Capitalization",
"read_only": 1
},
{
"depends_on": "eval:doc.docstatus > 0",
"fieldname": "total_asset_cost",
"fieldtype": "Currency",
"label": "Total Asset Cost",
"options": "Company:company:default_currency",
"read_only": 1
}
],
"idx": 72,
Expand Down Expand Up @@ -565,7 +574,7 @@
"link_fieldname": "target_asset"
}
],
"modified": "2023-11-20 21:05:45.216899",
"modified": "2023-12-20 16:50:21.128595",
"modified_by": "Administrator",
"module": "Assets",
"name": "Asset",
Expand Down Expand Up @@ -609,4 +618,4 @@
"states": [],
"title_field": "asset_name",
"track_changes": 1
}
}
6 changes: 6 additions & 0 deletions erpnext/assets/doctype/asset_repair/asset_repair.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def before_submit(self):

self.increase_asset_value()

if self.capitalize_repair_cost:
self.asset_doc.total_asset_cost += self.repair_cost

if self.get("stock_consumption"):
self.check_for_stock_items_and_warehouse()
self.decrease_stock_quantity()
Expand All @@ -68,6 +71,9 @@ def before_cancel(self):

self.decrease_asset_value()

if self.capitalize_repair_cost:
self.asset_doc.total_asset_cost -= self.repair_cost

if self.get("stock_consumption"):
self.increase_stock_quantity()
if self.get("capitalize_repair_cost"):
Expand Down
3 changes: 2 additions & 1 deletion erpnext/patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,8 @@ erpnext.patches.v14_0.create_accounting_dimensions_in_supplier_quotation
erpnext.patches.v14_0.update_zero_asset_quantity_field
execute:frappe.db.set_single_value("Buying Settings", "project_update_frequency", "Each Transaction")
erpnext.patches.v14_0.clear_reconciliation_values_from_singles
erpnext.patches.v14_0.update_total_asset_cost_field
# below migration patch should always run last
erpnext.patches.v14_0.migrate_gl_to_payment_ledger
erpnext.stock.doctype.delivery_note.patches.drop_unused_return_against_index
erpnext.patches.v14_0.set_maintain_stock_for_bom_item
erpnext.patches.v14_0.set_maintain_stock_for_bom_item
17 changes: 17 additions & 0 deletions erpnext/patches/v14_0/update_total_asset_cost_field.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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()

0 comments on commit 8169c7d

Please sign in to comment.