|
|
@ -41,7 +41,7 @@ class LandedCostVoucher(Document): |
|
|
|
|
|
|
|
def validate(self): |
|
|
|
self.check_mandatory() |
|
|
|
self.validate_purchase_receipts() |
|
|
|
self.validate_receipt_documents() |
|
|
|
init_landed_taxes_and_totals(self) |
|
|
|
self.set_total_taxes_and_charges() |
|
|
|
if not self.get("items"): |
|
|
@ -56,25 +56,23 @@ class LandedCostVoucher(Document): |
|
|
|
frappe.throw(_("Please enter Receipt Document")) |
|
|
|
|
|
|
|
|
|
|
|
def validate_purchase_receipts(self): |
|
|
|
def validate_receipt_documents(self): |
|
|
|
receipt_documents = [] |
|
|
|
|
|
|
|
for d in self.get("purchase_receipts"): |
|
|
|
doc_data = frappe.db.get_values( |
|
|
|
d.receipt_document_type, |
|
|
|
d.receipt_document, |
|
|
|
["docstatus", "update_stock"], |
|
|
|
as_dict=1 |
|
|
|
)[0] |
|
|
|
if doc_data.get("docstatus") != 1: |
|
|
|
msg = f"Row {d.idx}: Receipt Document {frappe.bold(d.receipt_document)} must be submitted" |
|
|
|
docstatus = frappe.db.get_value(d.receipt_document_type, d.receipt_document, "docstatus") |
|
|
|
if docstatus != 1: |
|
|
|
msg = f"Row {d.idx}: {d.receipt_document_type} {frappe.bold(d.receipt_document)} must be submitted" |
|
|
|
frappe.throw(_(msg), title=_("Invalid Document")) |
|
|
|
elif d.receipt_document_type == "Purchase Invoice" and not doc_data.get("update_stock"): |
|
|
|
msg = _(f"Row {d.idx}: Purchase Invoice {frappe.bold(d.receipt_document)} has no stock impact.") |
|
|
|
msg += "<br>" + _("Please create Landed Cost Vouchers against Invoices with 'Update Stock' enabled.") |
|
|
|
frappe.throw(msg, title=_("Incorrect Invoice")) |
|
|
|
else: |
|
|
|
receipt_documents.append(d.receipt_document) |
|
|
|
|
|
|
|
if d.receipt_document_type == "Purchase Invoice": |
|
|
|
update_stock = frappe.db.get_value(d.receipt_document_type, d.receipt_document, "update_stock") |
|
|
|
if not update_stock: |
|
|
|
msg = _("Row {0}: Purchase Invoice {1} has no stock impact.").format(d.idx, frappe.bold(d.receipt_document)) |
|
|
|
msg += "<br>" + _("Please create Landed Cost Vouchers against Invoices that have 'Update Stock' enabled.") |
|
|
|
frappe.throw(msg, title=_("Incorrect Invoice")) |
|
|
|
|
|
|
|
receipt_documents.append(d.receipt_document) |
|
|
|
|
|
|
|
for item in self.get("items"): |
|
|
|
if not item.receipt_document: |
|
|
|