fix: update quantity validation using asset quantity field instead of… (#46731)

* fix: update quantity validation using asset quantity field instead of total records

* fix: update throw message
This commit is contained in:
l0gesh29
2025-04-28 12:25:24 +05:30
committed by GitHub
parent cf3237a252
commit eae08bc619

View File

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