From 11bddc14bb3169fed080ea7451b6573f1b92a980 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 20 Feb 2024 11:58:47 +0530 Subject: [PATCH 1/3] fix: Delete linked asset movement record on cancellation of purchase receipt/invoice --- erpnext/controllers/buying_controller.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py index 4a627696032..1abf95f5953 100644 --- a/erpnext/controllers/buying_controller.py +++ b/erpnext/controllers/buying_controller.py @@ -811,7 +811,8 @@ class BuyingController(SubcontractingController): if self.doctype == "Purchase Invoice" and not self.get("update_stock"): return - frappe.db.sql("delete from `tabAsset Movement` where reference_name=%s", self.name) + asset_movement = frappe.db.get_value("Asset Movement", {"reference_name": self.name}, "name") + frappe.delete_doc("Asset Movement", asset_movement, force=1) def validate_schedule_date(self): if not self.get("items"): From 46cd929d00a0a71ef067ef66490d999921884110 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 20 Feb 2024 12:11:12 +0530 Subject: [PATCH 2/3] fix: Delete orphaned asset movement item records --- erpnext/patches.txt | 1 + .../v14_0/delete_orphaned_asset_movement_item_records.py | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100644 erpnext/patches/v14_0/delete_orphaned_asset_movement_item_records.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 6b7b13ff46e..125158a5add 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -358,3 +358,4 @@ erpnext.patches.v14_0.migrate_gl_to_payment_ledger erpnext.stock.doctype.delivery_note.patches.drop_unused_return_against_index # 2023-12-20 erpnext.patches.v14_0.set_maintain_stock_for_bom_item execute:frappe.db.set_single_value('E Commerce Settings', 'show_actual_qty', 1) +erpnext.patches.v14_0.delete_orphaned_asset_movement_item_records diff --git a/erpnext/patches/v14_0/delete_orphaned_asset_movement_item_records.py b/erpnext/patches/v14_0/delete_orphaned_asset_movement_item_records.py new file mode 100644 index 00000000000..dff04c09458 --- /dev/null +++ b/erpnext/patches/v14_0/delete_orphaned_asset_movement_item_records.py @@ -0,0 +1,7 @@ +import frappe + +def execute(): + frappe.db.sql(""" + DELETE FROM `tabAsset Movement Item` + WHERE parent NOT IN (SELECT name FROM `tabAsset Movement`) + """) \ No newline at end of file From ea1a0b3a28cdb4cc2f6e41c748e9577a49470ac8 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 20 Feb 2024 15:51:29 +0530 Subject: [PATCH 3/3] fix: linter issue --- .../delete_orphaned_asset_movement_item_records.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/erpnext/patches/v14_0/delete_orphaned_asset_movement_item_records.py b/erpnext/patches/v14_0/delete_orphaned_asset_movement_item_records.py index dff04c09458..a1d7dc9b3d4 100644 --- a/erpnext/patches/v14_0/delete_orphaned_asset_movement_item_records.py +++ b/erpnext/patches/v14_0/delete_orphaned_asset_movement_item_records.py @@ -1,7 +1,11 @@ import frappe + def execute(): - frappe.db.sql(""" - DELETE FROM `tabAsset Movement Item` - WHERE parent NOT IN (SELECT name FROM `tabAsset Movement`) - """) \ No newline at end of file + # nosemgrep + frappe.db.sql( + """ + DELETE FROM `tabAsset Movement Item` + WHERE parent NOT IN (SELECT name FROM `tabAsset Movement`) + """ + )