Skip to content

Commit

Permalink
fix: timeout error while submitting delivery note
Browse files Browse the repository at this point in the history
(cherry picked from commit 2d5ccc0)
  • Loading branch information
rohitwaghchaure authored and mergify[bot] committed May 1, 2023
1 parent 80230fe commit e33fb3b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
16 changes: 7 additions & 9 deletions erpnext/controllers/stock_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,10 @@ def make_batches(self, warehouse_field):
"""Create batches if required. Called before submit"""
for d in self.items:
if d.get(warehouse_field) and not d.batch_no:
has_batch_no, create_new_batch = frappe.db.get_value(
has_batch_no, create_new_batch = frappe.get_cached_value(
"Item", d.item_code, ["has_batch_no", "create_new_batch"]
)

if has_batch_no and create_new_batch:
d.batch_no = (
frappe.get_doc(
Expand Down Expand Up @@ -414,7 +415,7 @@ def get_sl_entries(self, d, args):
"voucher_no": self.name,
"voucher_detail_no": d.name,
"actual_qty": (self.docstatus == 1 and 1 or -1) * flt(d.get("stock_qty")),
"stock_uom": frappe.db.get_value(
"stock_uom": frappe.get_cached_value(
"Item", args.get("item_code") or d.get("item_code"), "stock_uom"
),
"incoming_rate": 0,
Expand Down Expand Up @@ -609,7 +610,7 @@ def update_blanket_order(self):
def validate_customer_provided_item(self):
for d in self.get("items"):
# Customer Provided parts will have zero valuation rate
if frappe.db.get_value("Item", d.item_code, "is_customer_provided_item"):
if frappe.get_cached_value("Item", d.item_code, "is_customer_provided_item"):
d.allow_zero_valuation_rate = 1

def set_rate_of_stock_uom(self):
Expand Down Expand Up @@ -722,7 +723,7 @@ def prepare_over_receipt_message(self, rule, values):
message += _("Please adjust the qty or edit {0} to proceed.").format(rule_link)
return message

def repost_future_sle_and_gle(self):
def repost_future_sle_and_gle(self, force=False):
args = frappe._dict(
{
"posting_date": self.posting_date,
Expand All @@ -733,7 +734,7 @@ def repost_future_sle_and_gle(self):
}
)

if future_sle_exists(args) or repost_required_for_queue(self):
if force or future_sle_exists(args) or repost_required_for_queue(self):
item_based_reposting = cint(
frappe.db.get_single_value("Stock Reposting Settings", "item_based_reposting")
)
Expand Down Expand Up @@ -894,9 +895,6 @@ def future_sle_exists(args, sl_entries=None):
)

for d in data:
if key not in frappe.local.future_sle:
frappe.local.future_sle[key] = frappe._dict({})

frappe.local.future_sle[key][(d.item_code, d.warehouse)] = d.total_row

return len(data)
Expand All @@ -919,7 +917,7 @@ def validate_future_sle_not_exists(args, key, sl_entries=None):

def get_cached_data(args, key):
if key not in frappe.local.future_sle:
return False
frappe.local.future_sle[key] = frappe._dict({})

if args.get("item_code"):
item_key = (args.get("item_code"), args.get("warehouse"))
Expand Down
4 changes: 2 additions & 2 deletions erpnext/stock/doctype/delivery_note/delivery_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def set_actual_qty(self):

def so_required(self):
"""check in manage account if sales order required or not"""
if frappe.db.get_value("Selling Settings", None, "so_required") == "Yes":
if frappe.db.get_single_value("Selling Settings", "so_required") == "Yes":
for d in self.get("items"):
if not d.against_sales_order:
frappe.throw(_("Sales Order required for Item {0}").format(d.item_code))
Expand Down Expand Up @@ -205,7 +205,7 @@ def validate_warehouse(self):
super(DeliveryNote, self).validate_warehouse()

for d in self.get_item_list():
if not d["warehouse"] and frappe.db.get_value("Item", d["item_code"], "is_stock_item") == 1:
if not d["warehouse"] and frappe.get_cached_value("Item", d["item_code"], "is_stock_item") == 1:
frappe.throw(_("Warehouse required for stock Item {0}").format(d["item_code"]))

def update_current_stock(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,8 @@
"no_copy": 1,
"options": "Sales Order",
"print_hide": 1,
"read_only": 1
"read_only": 1,
"search_index": 1
},
{
"fieldname": "against_sales_invoice",
Expand Down Expand Up @@ -662,7 +663,8 @@
"label": "Against Sales Invoice Item",
"no_copy": 1,
"print_hide": 1,
"read_only": 1
"read_only": 1,
"search_index": 1
},
{
"fieldname": "installed_qty",
Expand Down Expand Up @@ -854,7 +856,7 @@
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2023-04-06 09:28:29.182053",
"modified": "2023-05-01 21:05:14.175640",
"modified_by": "Administrator",
"module": "Stock",
"name": "Delivery Note Item",
Expand Down
2 changes: 1 addition & 1 deletion erpnext/stock/stock_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -1392,7 +1392,7 @@ def regenerate_sle_for_batch_stock_reco(detail):
if not frappe.db.exists(
"Repost Item Valuation", {"voucher_no": doc.name, "status": "Queued", "docstatus": "1"}
):
doc.repost_future_sle_and_gle()
doc.repost_future_sle_and_gle(force=True)


def get_stock_reco_qty_shift(args):
Expand Down

0 comments on commit e33fb3b

Please sign in to comment.