fix: Add indexes in stock queries

This commit is contained in:
Deepesh Garg
2021-10-02 22:56:46 +05:30
parent 5aae91e6cb
commit ed98125807
3 changed files with 4 additions and 3 deletions

View File

@@ -591,7 +591,7 @@ def future_sle_exists(args, sl_entries=None):
data = frappe.db.sql("""
select item_code, warehouse, count(name) as total_row
from `tabStock Ledger Entry`
from `tabStock Ledger Entry` force index (item_warehouse)
where
({})
and timestamp(posting_date, posting_time)

View File

@@ -182,3 +182,4 @@ def on_doctype_update():
frappe.db.add_index("Stock Ledger Entry", ["voucher_no", "voucher_type"])
frappe.db.add_index("Stock Ledger Entry", ["batch_no", "item_code", "warehouse"])
frappe.db.add_index("Stock Ledger Entry", ["voucher_detail_no"])
frappe.db.add_index("Stock Ledger Entry", ["item_code", "warehouse"], "item_warehouse")

View File

@@ -910,7 +910,7 @@ def get_valuation_rate(item_code, warehouse, voucher_type, voucher_no,
company = erpnext.get_default_company()
last_valuation_rate = frappe.db.sql("""select valuation_rate
from `tabStock Ledger Entry`
from `tabStock Ledger Entry` force index (item_warehouse)
where
item_code = %s
AND warehouse = %s
@@ -921,7 +921,7 @@ def get_valuation_rate(item_code, warehouse, voucher_type, voucher_no,
if not last_valuation_rate:
# Get valuation rate from last sle for the item against any warehouse
last_valuation_rate = frappe.db.sql("""select valuation_rate
from `tabStock Ledger Entry`
from `tabStock Ledger Entry` force index (item_code)
where
item_code = %s
AND valuation_rate > 0