From 87d1b0f476ecc475050289c29d8c8026c99e3d90 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 8 Jan 2024 12:45:42 +0530 Subject: [PATCH] fix: Ignore asset qty and status validation while cancelling LCV (cherry picked from commit e9d36242ce3e09ee423f917eede2275bded10d6d) --- .../landed_cost_voucher/landed_cost_voucher.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py b/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py index 021c43e300c5..c6518b45cd7f 100644 --- a/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py +++ b/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py @@ -194,7 +194,8 @@ def update_landed_cost(self): for d in self.get("purchase_receipts"): doc = frappe.get_doc(d.receipt_document_type, d.receipt_document) # check if there are {qty} assets created and linked to this receipt document - self.validate_asset_qty_and_status(d.receipt_document_type, doc) + if self.docstatus != 2: + self.validate_asset_qty_and_status(d.receipt_document_type, doc) # set landed cost voucher amount in pr item doc.set_landed_cost_voucher_amount() @@ -235,20 +236,20 @@ def validate_asset_qty_and_status(self, receipt_document_type, receipt_document) filters={receipt_document_type: item.receipt_document, "item_code": item.item_code}, fields=["name", "docstatus"], ) - if not docs or len(docs) != item.qty: + if not docs or len(docs) < item.qty: frappe.throw( _( - "There are not enough asset created or linked to {0}. Please create or link {1} Assets with respective document." - ).format(item.receipt_document, item.qty) + "There are only {0} asset created or linked to {1}. Please create or link {2} Assets with respective document." + ).format(len(docs), item.receipt_document, item.qty) ) if docs: for d in docs: if d.docstatus == 1: frappe.throw( _( - "{2} {0} has submitted Assets. Remove Item {1} from table to continue." + "{0} {1} has submitted Assets. Remove Item {2} from table to continue." ).format( - item.receipt_document, item.item_code, item.receipt_document_type + item.receipt_document_type, item.receipt_document, item.item_code ) )