From 2e6112f21b359abace6a5bbc1d43001d967fd919 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 28 Apr 2025 14:18:51 +0530 Subject: [PATCH] =?UTF-8?q?fix:=20update=20quantity=20validation=20using?= =?UTF-8?q?=20asset=20quantity=20field=20instead=20of=E2=80=A6=20(backport?= =?UTF-8?q?=20#46731)=20(#47284)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 (cherry picked from commit eae08bc619a9a23698ec79dd0d4f84471bf4edfa) # Conflicts: # erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py * chore: resolved conflicts --------- Co-authored-by: l0gesh29 Co-authored-by: Khushi Rawat <142375893+khushi8112@users.noreply.github.com> --- .../landed_cost_voucher.py | 22 ++++++++++++++----- 1 file changed, 16 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 eb84fdbc7c0..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 @@ -268,14 +268,24 @@ class LandedCostVoucher(Document): ) docs = frappe.db.get_all( "Asset", - filters={receipt_document_type: item.receipt_document, "item_code": item.item_code}, - fields=["name", "docstatus"], + filters={ + receipt_document_type: item.receipt_document, + "item_code": item.item_code, + "docstatus": ["!=", 2], + }, + 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: