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: SABB #44764

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
5 changes: 4 additions & 1 deletion erpnext/controllers/stock_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -1761,6 +1761,9 @@ def make_bundle_for_material_transfer(**kwargs):
bundle_doc.calculate_qty_and_amount()
bundle_doc.flags.ignore_permissions = True
bundle_doc.flags.ignore_validate = True
bundle_doc.save(ignore_permissions=True)
if kwargs.do_not_submit:
bundle_doc.save(ignore_permissions=True)
else:
bundle_doc.submit()

return bundle_doc.name
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,10 @@ def validate(self):
self.validate_duplicate_serial_and_batch_no()
self.validate_voucher_no()

if self.docstatus == 0:
self.allow_existing_serial_nos()

if self.type_of_transaction == "Maintenance":
return

self.allow_existing_serial_nos()
if not self.flags.ignore_validate_serial_batch or frappe.flags.in_test:
self.validate_serial_nos_duplicate()
self.check_future_entries_exists()
Expand Down Expand Up @@ -2101,6 +2099,8 @@ def update_available_batches(available_batches, *reserved_batches) -> None:


def get_available_batches(kwargs):
from erpnext.stock.utils import get_combine_datetime

stock_ledger_entry = frappe.qb.DocType("Stock Ledger Entry")
batch_ledger = frappe.qb.DocType("Serial and Batch Entry")
batch_table = frappe.qb.DocType("Batch")
Expand Down Expand Up @@ -2128,9 +2128,9 @@ def get_available_batches(kwargs):
if kwargs.get("posting_time") is None:
kwargs.posting_time = nowtime()

timestamp_condition = CombineDatetime(
stock_ledger_entry.posting_date, stock_ledger_entry.posting_time
) <= CombineDatetime(kwargs.posting_date, kwargs.posting_time)
timestamp_condition = stock_ledger_entry.posting_datetime <= get_combine_datetime(
kwargs.posting_date, kwargs.posting_time
)

query = query.where(timestamp_condition)

Expand Down
16 changes: 4 additions & 12 deletions erpnext/stock/serial_batch_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,15 +725,6 @@ def set_stock_value_difference(self):
stock_value_change = self.batch_avg_rate[batch_no] * ledger.qty
self.stock_value_change += stock_value_change

frappe.db.set_value(
"Serial and Batch Entry",
ledger.name,
{
"stock_value_difference": stock_value_change,
"incoming_rate": self.batch_avg_rate[batch_no],
},
)

def calculate_valuation_rate(self):
if not hasattr(self, "wh_data"):
return
Expand Down Expand Up @@ -947,12 +938,13 @@ def make_serial_and_batch_bundle(self):
if self.get("make_bundle_from_sle") and self.type_of_transaction == "Inward":
doc.flags.ignore_validate_serial_batch = True

doc.save()
self.validate_qty(doc)

if not hasattr(self, "do_not_submit") or not self.do_not_submit:
doc.flags.ignore_voucher_validation = True
doc.submit()
else:
doc.save()

self.validate_qty(doc)

return doc

Expand Down
25 changes: 15 additions & 10 deletions erpnext/stock/stock_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -989,18 +989,23 @@ def calculate_valuation_for_serial_batch_bundle(self, sle):
if not frappe.db.exists("Serial and Batch Bundle", sle.serial_and_batch_bundle):
return

doc = frappe.get_cached_doc("Serial and Batch Bundle", sle.serial_and_batch_bundle)

doc.set_incoming_rate(save=True, allow_negative_stock=self.allow_negative_stock)
doc.calculate_qty_and_amount(save=True)
if self.args.get("sle_id") and sle.actual_qty < 0:
doc = frappe.db.get_value(
"Serial and Batch Bundle",
sle.serial_and_batch_bundle,
["total_amount", "total_qty"],
as_dict=1,
)
else:
doc = frappe.get_doc("Serial and Batch Bundle", sle.serial_and_batch_bundle)
doc.set_incoming_rate(save=True, allow_negative_stock=self.allow_negative_stock)
doc.calculate_qty_and_amount(save=True)

self.wh_data.stock_value = round_off_if_near_zero(self.wh_data.stock_value + doc.total_amount)

precision = doc.precision("total_qty")
self.wh_data.qty_after_transaction += flt(doc.total_qty, precision)
if flt(self.wh_data.qty_after_transaction, precision):
self.wh_data.valuation_rate = flt(self.wh_data.stock_value, precision) / flt(
self.wh_data.qty_after_transaction, precision
self.wh_data.qty_after_transaction += flt(doc.total_qty, self.flt_precision)
if flt(self.wh_data.qty_after_transaction, self.flt_precision):
self.wh_data.valuation_rate = flt(self.wh_data.stock_value, self.flt_precision) / flt(
self.wh_data.qty_after_transaction, self.flt_precision
)

def update_valuation_rate_in_serial_and_batch_bundle(self, sle, valuation_rate):
Expand Down
Loading