Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: timeout error (backport #43154) #43158

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading