fix: asset movement (#35918)
fix: asset movement fixes
(cherry picked from commit e16c14863b52aaa7856c799ad64fe977d4a4fbbe)
diff --git a/erpnext/assets/doctype/asset_movement/asset_movement.js b/erpnext/assets/doctype/asset_movement/asset_movement.js
index 2df7db9..f9c6007 100644
--- a/erpnext/assets/doctype/asset_movement/asset_movement.js
+++ b/erpnext/assets/doctype/asset_movement/asset_movement.js
@@ -70,19 +70,21 @@
else if (frm.doc.purpose === 'Issue') {
fieldnames_to_be_altered = {
target_location: { read_only: 1, reqd: 0 },
- source_location: { read_only: 1, reqd: 1 },
+ source_location: { read_only: 1, reqd: 0 },
from_employee: { read_only: 1, reqd: 0 },
to_employee: { read_only: 0, reqd: 1 }
};
}
- Object.keys(fieldnames_to_be_altered).forEach(fieldname => {
- let property_to_be_altered = fieldnames_to_be_altered[fieldname];
- Object.keys(property_to_be_altered).forEach(property => {
- let value = property_to_be_altered[property];
- frm.set_df_property(fieldname, property, value, cdn, 'assets');
+ if (fieldnames_to_be_altered) {
+ Object.keys(fieldnames_to_be_altered).forEach(fieldname => {
+ let property_to_be_altered = fieldnames_to_be_altered[fieldname];
+ Object.keys(property_to_be_altered).forEach(property => {
+ let value = property_to_be_altered[property];
+ frm.fields_dict['assets'].grid.update_docfield_property(fieldname, property, value);
+ });
});
- });
- frm.refresh_field('assets');
+ frm.refresh_field('assets');
+ }
}
});
diff --git a/erpnext/assets/doctype/asset_movement/asset_movement.json b/erpnext/assets/doctype/asset_movement/asset_movement.json
index bdce639..5382f9e 100644
--- a/erpnext/assets/doctype/asset_movement/asset_movement.json
+++ b/erpnext/assets/doctype/asset_movement/asset_movement.json
@@ -37,6 +37,7 @@
"reqd": 1
},
{
+ "default": "Now",
"fieldname": "transaction_date",
"fieldtype": "Datetime",
"in_list_view": 1,
@@ -95,10 +96,11 @@
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
- "modified": "2021-01-22 12:30:55.295670",
+ "modified": "2023-06-28 16:54:26.571083",
"modified_by": "Administrator",
"module": "Assets",
"name": "Asset Movement",
+ "naming_rule": "Expression",
"owner": "Administrator",
"permissions": [
{
@@ -148,5 +150,6 @@
}
],
"sort_field": "modified",
- "sort_order": "DESC"
+ "sort_order": "DESC",
+ "states": []
}
\ No newline at end of file
diff --git a/erpnext/assets/doctype/asset_movement/asset_movement.py b/erpnext/assets/doctype/asset_movement/asset_movement.py
index 143f215..b58ca10 100644
--- a/erpnext/assets/doctype/asset_movement/asset_movement.py
+++ b/erpnext/assets/doctype/asset_movement/asset_movement.py
@@ -28,25 +28,20 @@
def validate_location(self):
for d in self.assets:
if self.purpose in ["Transfer", "Issue"]:
- if not d.source_location:
- d.source_location = frappe.db.get_value("Asset", d.asset, "location")
-
- if not d.source_location:
- frappe.throw(_("Source Location is required for the Asset {0}").format(d.asset))
-
+ current_location = frappe.db.get_value("Asset", d.asset, "location")
if d.source_location:
- current_location = frappe.db.get_value("Asset", d.asset, "location")
-
if current_location != d.source_location:
frappe.throw(
_("Asset {0} does not belongs to the location {1}").format(d.asset, d.source_location)
)
+ else:
+ d.source_location = current_location
if self.purpose == "Issue":
if d.target_location:
frappe.throw(
_(
- "Issuing cannot be done to a location. Please enter employee who has issued Asset {0}"
+ "Issuing cannot be done to a location. Please enter employee to issue the Asset {0} to"
).format(d.asset),
title=_("Incorrect Movement Purpose"),
)
@@ -107,12 +102,12 @@
)
def on_submit(self):
- self.set_latest_location_in_asset()
+ self.set_latest_location_and_custodian_in_asset()
def on_cancel(self):
- self.set_latest_location_in_asset()
+ self.set_latest_location_and_custodian_in_asset()
- def set_latest_location_in_asset(self):
+ def set_latest_location_and_custodian_in_asset(self):
current_location, current_employee = "", ""
cond = "1=1"
diff --git a/erpnext/assets/doctype/asset_movement/test_asset_movement.py b/erpnext/assets/doctype/asset_movement/test_asset_movement.py
index 72c0575..27e7e55 100644
--- a/erpnext/assets/doctype/asset_movement/test_asset_movement.py
+++ b/erpnext/assets/doctype/asset_movement/test_asset_movement.py
@@ -47,7 +47,7 @@
if not frappe.db.exists("Location", "Test Location 2"):
frappe.get_doc({"doctype": "Location", "location_name": "Test Location 2"}).insert()
- movement1 = create_asset_movement(
+ create_asset_movement(
purpose="Transfer",
company=asset.company,
assets=[
@@ -58,7 +58,7 @@
)
self.assertEqual(frappe.db.get_value("Asset", asset.name, "location"), "Test Location 2")
- create_asset_movement(
+ movement1 = create_asset_movement(
purpose="Transfer",
company=asset.company,
assets=[
@@ -70,21 +70,32 @@
self.assertEqual(frappe.db.get_value("Asset", asset.name, "location"), "Test Location")
movement1.cancel()
- self.assertEqual(frappe.db.get_value("Asset", asset.name, "location"), "Test Location")
+ self.assertEqual(frappe.db.get_value("Asset", asset.name, "location"), "Test Location 2")
employee = make_employee("testassetmovemp@example.com", company="_Test Company")
create_asset_movement(
purpose="Issue",
company=asset.company,
- assets=[{"asset": asset.name, "source_location": "Test Location", "to_employee": employee}],
+ assets=[{"asset": asset.name, "source_location": "Test Location 2", "to_employee": employee}],
reference_doctype="Purchase Receipt",
reference_name=pr.name,
)
- # after issuing asset should belong to an employee not at a location
+ # after issuing, asset should belong to an employee not at a location
self.assertEqual(frappe.db.get_value("Asset", asset.name, "location"), None)
self.assertEqual(frappe.db.get_value("Asset", asset.name, "custodian"), employee)
+ create_asset_movement(
+ purpose="Receipt",
+ company=asset.company,
+ assets=[{"asset": asset.name, "from_employee": employee, "target_location": "Test Location"}],
+ reference_doctype="Purchase Receipt",
+ reference_name=pr.name,
+ )
+
+ # after receiving, asset should belong to a location not at an employee
+ self.assertEqual(frappe.db.get_value("Asset", asset.name, "location"), "Test Location")
+
def test_last_movement_cancellation(self):
pr = make_purchase_receipt(
item_code="Macbook Pro", qty=1, rate=100000.0, location="Test Location"