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 2ca85d90ae6..c80bcc8123b 100644 --- a/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py +++ b/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py @@ -7,7 +7,7 @@ from frappe import _ from frappe.model.document import Document from frappe.model.meta import get_field_precision from frappe.query_builder.custom import ConstantColumn -from frappe.utils import flt +from frappe.utils import cint, flt import erpnext from erpnext.controllers.taxes_and_totals import init_landed_taxes_and_totals @@ -273,13 +273,19 @@ class LandedCostVoucher(Document): "item_code": item.item_code, "docstatus": ["!=", 2], }, - fields=["name", "docstatus"], + fields=["name", "docstatus", "asset_quantity"], ) - if not docs or len(docs) < item.qty: + + total_asset_qty = sum((cint(d.asset_quantity)) for d in docs) + + if not docs or total_asset_qty < item.qty: frappe.throw( _( - "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) + "For item {0}, only {1} asset have been created or linked to {2}. " + "Please create or link {3} more asset with the respective document." + ).format( + item.item_code, total_asset_qty, item.receipt_document, item.qty - total_asset_qty + ) ) if docs: for d in docs: