mirror of
https://github.com/frappe/erpnext.git
synced 2026-04-14 04:15:10 +00:00
* 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 eae08bc619)
# Conflicts:
# erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py
* chore: resolved conflicts
---------
Co-authored-by: l0gesh29 <logeshperiyasamy24@gmail.com>
Co-authored-by: Khushi Rawat <142375893+khushi8112@users.noreply.github.com>
This commit is contained in:
@@ -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
|
||||||
@@ -268,14 +268,24 @@ class LandedCostVoucher(Document):
|
|||||||
)
|
)
|
||||||
docs = frappe.db.get_all(
|
docs = frappe.db.get_all(
|
||||||
"Asset",
|
"Asset",
|
||||||
filters={receipt_document_type: item.receipt_document, "item_code": item.item_code},
|
filters={
|
||||||
fields=["name", "docstatus"],
|
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(
|
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:
|
||||||
|
|||||||
Reference in New Issue
Block a user