From 83fe78bcda462905fc4e632db20140bfffed69a9 Mon Sep 17 00:00:00 2001 From: Khushi Rawat <142375893+khushi8112@users.noreply.github.com> Date: Thu, 29 Aug 2024 17:10:12 +0530 Subject: [PATCH] fix: improve asset item matching logic --- .../patches/v15_0/link_purchase_item_to_asset_doc.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/erpnext/patches/v15_0/link_purchase_item_to_asset_doc.py b/erpnext/patches/v15_0/link_purchase_item_to_asset_doc.py index e4311a8879d..e5386c1de0a 100644 --- a/erpnext/patches/v15_0/link_purchase_item_to_asset_doc.py +++ b/erpnext/patches/v15_0/link_purchase_item_to_asset_doc.py @@ -53,7 +53,7 @@ def get_linked_item(doctype, parent, item_code, amount, quantity): "parent": parent, "item_code": item_code, }, - fields=["name", "amount", "qty", "landed_cost_voucher_amount"], + fields=["name", "rate", "amount", "qty", "landed_cost_voucher_amount"], ) if len(items) == 1: # If only one item exists, return it directly @@ -61,8 +61,13 @@ def get_linked_item(doctype, parent, item_code, amount, quantity): for item in items: landed_cost = item.get("landed_cost_voucher_amount", 0) - if item.amount + landed_cost == amount and item.qty == quantity: - return item.name + # Check if the asset is grouped + if quantity > 1: + if item.amount + landed_cost == amount and item.qty == quantity: + return item.name + else: + if item.rate + landed_cost == amount: + return item.name # If no exact match, return None return None