Skip to content

Commit

Permalink
perf: timeout error (#43154)
Browse files Browse the repository at this point in the history
(cherry picked from commit 1bf6024)
  • Loading branch information
rohitwaghchaure authored and mergify[bot] committed Sep 10, 2024
1 parent cd57e00 commit b0e4e69
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
4 changes: 4 additions & 0 deletions erpnext/public/js/controllers/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -1879,6 +1879,10 @@ erpnext.TransactionController = class TransactionController extends erpnext.taxe
const fields = ["discount_percentage",
"discount_amount", "margin_rate_or_amount", "rate_with_margin"];

if (!item) {
return;
}

if(item.remove_free_item) {
let items = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1558,13 +1558,14 @@ def get_serial_nos_based_on_posting_date(kwargs, ignore_serial_nos):
serial_nos = set()
data = get_stock_ledgers_for_serial_nos(kwargs)

bundle_wise_serial_nos = get_bundle_wise_serial_nos(data)
for d in data:
if d.serial_and_batch_bundle:
sns = get_serial_nos_from_bundle(d.serial_and_batch_bundle, kwargs.get("serial_nos", []))
if d.actual_qty > 0:
serial_nos.update(sns)
else:
serial_nos.difference_update(sns)
if sns := bundle_wise_serial_nos.get(d.serial_and_batch_bundle):
if d.actual_qty > 0:
serial_nos.update(sns)
else:
serial_nos.difference_update(sns)

elif d.serial_no:
sns = get_serial_nos(d.serial_no)
Expand All @@ -1581,6 +1582,25 @@ def get_serial_nos_based_on_posting_date(kwargs, ignore_serial_nos):
return serial_nos


def get_bundle_wise_serial_nos(data):
bundle_wise_serial_nos = defaultdict(list)
bundles = [d.serial_and_batch_bundle for d in data if d.serial_and_batch_bundle]
if not bundles:
return bundle_wise_serial_nos

bundle_data = frappe.get_all(
"Serial and Batch Entry",
fields=["serial_no", "parent"],
filters={"parent": ("in", bundles), "docstatus": 1, "serial_no": ("is", "set")},
)

for d in bundle_data:
if d.parent:
bundle_wise_serial_nos[d.parent].append(d.serial_no)

return bundle_wise_serial_nos


def get_reserved_serial_nos(kwargs) -> list:
"""Returns a list of `Serial No` reserved in POS Invoice and Stock Reservation Entry."""

Expand Down

0 comments on commit b0e4e69

Please sign in to comment.