From c6baa34812765b1db365842ec24803c86b37f5b7 Mon Sep 17 00:00:00 2001 From: khushi8112 Date: Sun, 29 Jun 2025 22:46:39 +0530 Subject: [PATCH] fix: validate asset before repair --- erpnext/assets/doctype/asset_repair/asset_repair.json | 6 ++++-- erpnext/assets/doctype/asset_repair/asset_repair.py | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/erpnext/assets/doctype/asset_repair/asset_repair.json b/erpnext/assets/doctype/asset_repair/asset_repair.json index f49de50838a..935ed1b4e98 100644 --- a/erpnext/assets/doctype/asset_repair/asset_repair.json +++ b/erpnext/assets/doctype/asset_repair/asset_repair.json @@ -127,6 +127,7 @@ "fieldtype": "Link", "in_list_view": 1, "label": "Asset", + "link_filters": "[[\"Asset\",\"status\",\"not in\",[\"Work In Progress\",\"Capitalized\",\"Fully Depreciated\",\"Sold\",\"Scrapped\",null]]]", "options": "Asset", "reqd": 1 }, @@ -259,7 +260,7 @@ "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], - "modified": "2024-12-27 18:11:40.548727", + "modified": "2025-06-29 22:30:00.589597", "modified_by": "Administrator", "module": "Assets", "name": "Asset Repair", @@ -297,10 +298,11 @@ "write": 1 } ], + "row_format": "Dynamic", "sort_field": "creation", "sort_order": "DESC", "states": [], "title_field": "asset_name", "track_changes": 1, "track_seen": 1 -} \ No newline at end of file +} diff --git a/erpnext/assets/doctype/asset_repair/asset_repair.py b/erpnext/assets/doctype/asset_repair/asset_repair.py index e487c22cd0d..a1c741316a6 100644 --- a/erpnext/assets/doctype/asset_repair/asset_repair.py +++ b/erpnext/assets/doctype/asset_repair/asset_repair.py @@ -57,6 +57,7 @@ class AssetRepair(AccountsController): def validate(self): self.asset_doc = frappe.get_doc("Asset", self.asset) + self.validate_asset() self.validate_dates() self.validate_purchase_invoices() self.update_status() @@ -65,6 +66,14 @@ class AssetRepair(AccountsController): self.calculate_total_repair_cost() self.check_repair_status() + def validate_asset(self): + if self.asset_doc.status in ("Sold", "Fully Depreciated", "Scrapped"): + frappe.throw( + _("Asset {0} is in {1} status and cannot be repaired.").format( + get_link_to_form("Asset", self.asset), self.asset_doc.status + ) + ) + def validate_dates(self): if self.completion_date and (self.failure_date > self.completion_date): frappe.throw(