mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-22 11:44:11 +00:00
fix: add validation for draft PR/PI in Asset
(cherry picked from commit 4cf481cca8)
This commit is contained in:
@@ -128,6 +128,7 @@ class Asset(AccountsController):
|
|||||||
self.validate_item()
|
self.validate_item()
|
||||||
self.validate_cost_center()
|
self.validate_cost_center()
|
||||||
self.set_missing_values()
|
self.set_missing_values()
|
||||||
|
self.validate_linked_purchase_docs()
|
||||||
self.validate_gross_and_purchase_amount()
|
self.validate_gross_and_purchase_amount()
|
||||||
self.validate_finance_books()
|
self.validate_finance_books()
|
||||||
|
|
||||||
@@ -409,6 +410,21 @@ class Asset(AccountsController):
|
|||||||
if self.available_for_use_date and getdate(self.available_for_use_date) < getdate(self.purchase_date):
|
if self.available_for_use_date and getdate(self.available_for_use_date) < getdate(self.purchase_date):
|
||||||
frappe.throw(_("Available-for-use Date should be after purchase date"))
|
frappe.throw(_("Available-for-use Date should be after purchase date"))
|
||||||
|
|
||||||
|
def validate_linked_purchase_docs(self):
|
||||||
|
for doctype_field, doctype_name in [
|
||||||
|
("purchase_receipt", "Purchase Receipt"),
|
||||||
|
("purchase_invoice", "Purchase Invoice"),
|
||||||
|
]:
|
||||||
|
linked_doc = getattr(self, doctype_field, None)
|
||||||
|
if linked_doc:
|
||||||
|
docstatus = frappe.db.get_value(doctype_name, linked_doc, "docstatus")
|
||||||
|
if docstatus == 0:
|
||||||
|
frappe.throw(
|
||||||
|
_("{0} is still in Draft. Please submit it before saving the Asset.").format(
|
||||||
|
get_link_to_form(doctype_name, linked_doc)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
def validate_gross_and_purchase_amount(self):
|
def validate_gross_and_purchase_amount(self):
|
||||||
if self.is_existing_asset:
|
if self.is_existing_asset:
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user