From 6086d1a99d2ff266eeb75aa0288a568abd00ec81 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Fri, 16 Jun 2023 18:25:58 +0530 Subject: [PATCH] perf: duplicate queries while checking prevdoc (#35746) These values can't change durning DB transaction AFAIK --- .../accounts/doctype/sales_invoice/sales_invoice.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 2075d57a35..7ab1c89397 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -1001,10 +1001,16 @@ class SalesInvoice(SellingController): def check_prev_docstatus(self): for d in self.get("items"): - if d.sales_order and frappe.db.get_value("Sales Order", d.sales_order, "docstatus") != 1: + if ( + d.sales_order + and frappe.db.get_value("Sales Order", d.sales_order, "docstatus", cache=True) != 1 + ): frappe.throw(_("Sales Order {0} is not submitted").format(d.sales_order)) - if d.delivery_note and frappe.db.get_value("Delivery Note", d.delivery_note, "docstatus") != 1: + if ( + d.delivery_note + and frappe.db.get_value("Delivery Note", d.delivery_note, "docstatus", cache=True) != 1 + ): throw(_("Delivery Note {0} is not submitted").format(d.delivery_note)) def make_gl_entries(self, gl_entries=None, from_repost=False):