mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-23 23:19:20 +00:00
fix: better validation message
This commit is contained in:
@@ -446,12 +446,15 @@ class Asset(AccountsController):
|
|||||||
Asset = frappe.qb.DocType("Asset")
|
Asset = frappe.qb.DocType("Asset")
|
||||||
|
|
||||||
if doctype == "Purchase Invoice":
|
if doctype == "Purchase Invoice":
|
||||||
asset_filter = (Asset.purchase_invoice == purchase_doc) & (Asset.name != self.name)
|
asset_filter = Asset.purchase_invoice == purchase_doc
|
||||||
else:
|
else:
|
||||||
asset_filter = (Asset.purchase_receipt == purchase_doc) & (Asset.name != self.name)
|
asset_filter = Asset.purchase_receipt == purchase_doc
|
||||||
|
|
||||||
existing_asset_qty = (
|
existing_asset_qty = (
|
||||||
frappe.qb.from_(Asset).select(IfNull(Sum(Asset.asset_quantity), 0)).where(asset_filter)
|
frappe.qb.from_(Asset)
|
||||||
|
.select(IfNull(Sum(Asset.asset_quantity), 0))
|
||||||
|
.where((Asset.item_code == self.item_code) & (Asset.name != self.name))
|
||||||
|
.where(asset_filter)
|
||||||
).run()[0][0]
|
).run()[0][0]
|
||||||
|
|
||||||
PurchaseDoc = frappe.qb.DocType(doctype)
|
PurchaseDoc = frappe.qb.DocType(doctype)
|
||||||
@@ -468,12 +471,17 @@ class Asset(AccountsController):
|
|||||||
|
|
||||||
if (existing_asset_qty + self.asset_quantity) > purchased_qty:
|
if (existing_asset_qty + self.asset_quantity) > purchased_qty:
|
||||||
frappe.throw(
|
frappe.throw(
|
||||||
_("Created assets {0} exceed the purchased quantity {1} for item {2} " "in {3} {4}").format(
|
_(
|
||||||
(existing_asset_qty + self.asset_quantity),
|
"<b>Cannot create asset.</b><br><br>"
|
||||||
|
"You're trying to create <b>{0} asset(s)</b> from {2} {3}.<br>"
|
||||||
|
"However, only <b>{1} item(s)</b> were purchased and <b>{4} asset(s)</b> already exist against {5}."
|
||||||
|
).format(
|
||||||
|
self.asset_quantity,
|
||||||
purchased_qty,
|
purchased_qty,
|
||||||
self.item_code,
|
|
||||||
doctype,
|
doctype,
|
||||||
get_link_to_form(doctype, purchase_doc),
|
get_link_to_form(doctype, purchase_doc),
|
||||||
|
existing_asset_qty,
|
||||||
|
purchase_doc,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user