mirror of
https://github.com/frappe/erpnext.git
synced 2026-02-21 10:26:30 +00:00
fix: asset cancellation issue (#47639)
(cherry picked from commit 33ab64dec2)
Co-authored-by: Khushi Rawat <142375893+khushi8112@users.noreply.github.com>
This commit is contained in:
@@ -153,8 +153,6 @@ class AssetMovement(Document):
|
|||||||
args,
|
args,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.validate_movement_cancellation(d, latest_movement_entry)
|
|
||||||
|
|
||||||
if latest_movement_entry:
|
if latest_movement_entry:
|
||||||
current_location = latest_movement_entry[0][0]
|
current_location = latest_movement_entry[0][0]
|
||||||
current_employee = latest_movement_entry[0][1]
|
current_employee = latest_movement_entry[0][1]
|
||||||
@@ -182,12 +180,3 @@ class AssetMovement(Document):
|
|||||||
d.asset,
|
d.asset,
|
||||||
_("Asset issued to Employee {0}").format(get_link_to_form("Employee", current_employee)),
|
_("Asset issued to Employee {0}").format(get_link_to_form("Employee", current_employee)),
|
||||||
)
|
)
|
||||||
|
|
||||||
def validate_movement_cancellation(self, row, latest_movement_entry):
|
|
||||||
asset_doc = frappe.get_doc("Asset", row.asset)
|
|
||||||
if not latest_movement_entry and asset_doc.docstatus == 1:
|
|
||||||
frappe.throw(
|
|
||||||
_(
|
|
||||||
"Asset {0} has only one movement record. Please create another movement before deleting this one to maintain asset tracking."
|
|
||||||
).format(row.asset)
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -147,45 +147,6 @@ class TestAssetMovement(unittest.TestCase):
|
|||||||
movement1.cancel()
|
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")
|
||||||
|
|
||||||
def test_last_movement_cancellation_validation(self):
|
|
||||||
pr = make_purchase_receipt(item_code="Macbook Pro", qty=1, rate=100000.0, location="Test Location")
|
|
||||||
|
|
||||||
asset_name = frappe.db.get_value("Asset", {"purchase_receipt": pr.name}, "name")
|
|
||||||
asset = frappe.get_doc("Asset", asset_name)
|
|
||||||
asset.calculate_depreciation = 1
|
|
||||||
asset.available_for_use_date = "2020-06-06"
|
|
||||||
asset.purchase_date = "2020-06-06"
|
|
||||||
asset.append(
|
|
||||||
"finance_books",
|
|
||||||
{
|
|
||||||
"expected_value_after_useful_life": 10000,
|
|
||||||
"next_depreciation_date": "2020-12-31",
|
|
||||||
"depreciation_method": "Straight Line",
|
|
||||||
"total_number_of_depreciations": 3,
|
|
||||||
"frequency_of_depreciation": 10,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
if asset.docstatus == 0:
|
|
||||||
asset.submit()
|
|
||||||
|
|
||||||
AssetMovement = frappe.qb.DocType("Asset Movement")
|
|
||||||
AssetMovementItem = frappe.qb.DocType("Asset Movement Item")
|
|
||||||
|
|
||||||
asset_movement = (
|
|
||||||
frappe.qb.from_(AssetMovement)
|
|
||||||
.join(AssetMovementItem)
|
|
||||||
.on(AssetMovementItem.parent == AssetMovement.name)
|
|
||||||
.select(AssetMovement.name)
|
|
||||||
.where(
|
|
||||||
(AssetMovementItem.asset == asset.name)
|
|
||||||
& (AssetMovement.company == asset.company)
|
|
||||||
& (AssetMovement.docstatus == 1)
|
|
||||||
)
|
|
||||||
).run(as_dict=True)
|
|
||||||
|
|
||||||
asset_movement_doc = frappe.get_doc("Asset Movement", asset_movement[0].name)
|
|
||||||
self.assertRaises(frappe.ValidationError, asset_movement_doc.cancel)
|
|
||||||
|
|
||||||
|
|
||||||
def create_asset_movement(**args):
|
def create_asset_movement(**args):
|
||||||
args = frappe._dict(args)
|
args = frappe._dict(args)
|
||||||
|
|||||||
Reference in New Issue
Block a user