From f4cdb4912676f811d3390f270c2d7b279e6c0bba Mon Sep 17 00:00:00 2001 From: KerollesFathy Date: Wed, 10 Sep 2025 18:27:39 +0300 Subject: [PATCH 1/2] fix: clear asset custodian when asset take back from employee without assign to another employee --- erpnext/assets/doctype/asset_movement/asset_movement.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/erpnext/assets/doctype/asset_movement/asset_movement.py b/erpnext/assets/doctype/asset_movement/asset_movement.py index db4e7510670..b9fb331ae12 100644 --- a/erpnext/assets/doctype/asset_movement/asset_movement.py +++ b/erpnext/assets/doctype/asset_movement/asset_movement.py @@ -144,6 +144,10 @@ class AssetMovement(Document): if employee and employee != asset.custodian: frappe.db.set_value("Asset", asset_id, "custodian", employee) + + elif not employee and asset.custodian: + frappe.db.set_value("Asset", asset_id, "custodian", None) + if location and location != asset.location: frappe.db.set_value("Asset", asset_id, "location", location) From 4bc76be1304282357704c1a61f4aa59a6c782feb Mon Sep 17 00:00:00 2001 From: KerollesFathy Date: Wed, 10 Sep 2025 19:01:14 +0300 Subject: [PATCH 2/2] refactor: optimize asset location and custodian update logic to avoid multiple updates --- .../assets/doctype/asset_movement/asset_movement.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/erpnext/assets/doctype/asset_movement/asset_movement.py b/erpnext/assets/doctype/asset_movement/asset_movement.py index b9fb331ae12..affc0cf1424 100644 --- a/erpnext/assets/doctype/asset_movement/asset_movement.py +++ b/erpnext/assets/doctype/asset_movement/asset_movement.py @@ -142,14 +142,18 @@ class AssetMovement(Document): def update_asset_location_and_custodian(self, asset_id, location, employee): asset = frappe.get_doc("Asset", asset_id) + updates = {} if employee and employee != asset.custodian: - frappe.db.set_value("Asset", asset_id, "custodian", employee) + updates["custodian"] = employee elif not employee and asset.custodian: - frappe.db.set_value("Asset", asset_id, "custodian", None) + updates["custodian"] = "" if location and location != asset.location: - frappe.db.set_value("Asset", asset_id, "location", location) + updates["location"] = location + + if updates: + frappe.db.set_value("Asset", asset_id, updates) def log_asset_activity(self, asset_id, location, employee): if location and employee: