From 61a4188440fd44fb8f263a19c2123b182c7e9cf3 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Fri, 17 May 2024 16:36:38 +0530 Subject: [PATCH] fix: timeout error while submitting purchase invoice (#41520) --- .../purchase_receipt/purchase_receipt.py | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py index b5d646e27f5..94ad468cbc9 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -914,6 +914,15 @@ class PurchaseReceipt(BuyingController): notify=True, ) + def enable_recalculate_rate_in_sles(self): + sle_table = frappe.qb.DocType("Stock Ledger Entry") + ( + frappe.qb.update(sle_table) + .set(sle_table.recalculate_rate, 1) + .where(sle_table.voucher_no == self.name) + .where(sle_table.voucher_type == "Purchase Receipt") + ).run() + def get_stock_value_difference(voucher_no, voucher_detail_no, warehouse): return frappe.db.get_value( @@ -1086,15 +1095,10 @@ def adjust_incoming_rate_for_pr(doc): for item in doc.get("items"): item.db_update() - doc.docstatus = 2 - doc.update_stock_ledger(allow_negative_stock=True, via_landed_cost_voucher=True) - doc.make_gl_entries_on_cancel() + if doc.doctype == "Purchase Receipt": + doc.enable_recalculate_rate_in_sles() - # update stock & gl entries for submit state of PR - doc.docstatus = 1 - doc.update_stock_ledger(allow_negative_stock=True, via_landed_cost_voucher=True) - doc.make_gl_entries() - doc.repost_future_sle_and_gle() + doc.repost_future_sle_and_gle(force=True) def get_item_wise_returned_qty(pr_doc):