perf: SABB (#44764)
This commit is contained in:
@@ -1761,6 +1761,9 @@ def make_bundle_for_material_transfer(**kwargs):
|
|||||||
bundle_doc.calculate_qty_and_amount()
|
bundle_doc.calculate_qty_and_amount()
|
||||||
bundle_doc.flags.ignore_permissions = True
|
bundle_doc.flags.ignore_permissions = True
|
||||||
bundle_doc.flags.ignore_validate = 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
|
return bundle_doc.name
|
||||||
|
|||||||
@@ -90,12 +90,10 @@ class SerialandBatchBundle(Document):
|
|||||||
self.validate_duplicate_serial_and_batch_no()
|
self.validate_duplicate_serial_and_batch_no()
|
||||||
self.validate_voucher_no()
|
self.validate_voucher_no()
|
||||||
|
|
||||||
if self.docstatus == 0:
|
|
||||||
self.allow_existing_serial_nos()
|
|
||||||
|
|
||||||
if self.type_of_transaction == "Maintenance":
|
if self.type_of_transaction == "Maintenance":
|
||||||
return
|
return
|
||||||
|
|
||||||
|
self.allow_existing_serial_nos()
|
||||||
if not self.flags.ignore_validate_serial_batch or frappe.flags.in_test:
|
if not self.flags.ignore_validate_serial_batch or frappe.flags.in_test:
|
||||||
self.validate_serial_nos_duplicate()
|
self.validate_serial_nos_duplicate()
|
||||||
self.check_future_entries_exists()
|
self.check_future_entries_exists()
|
||||||
@@ -2101,6 +2099,8 @@ def update_available_batches(available_batches, *reserved_batches) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def get_available_batches(kwargs):
|
def get_available_batches(kwargs):
|
||||||
|
from erpnext.stock.utils import get_combine_datetime
|
||||||
|
|
||||||
stock_ledger_entry = frappe.qb.DocType("Stock Ledger Entry")
|
stock_ledger_entry = frappe.qb.DocType("Stock Ledger Entry")
|
||||||
batch_ledger = frappe.qb.DocType("Serial and Batch Entry")
|
batch_ledger = frappe.qb.DocType("Serial and Batch Entry")
|
||||||
batch_table = frappe.qb.DocType("Batch")
|
batch_table = frappe.qb.DocType("Batch")
|
||||||
@@ -2128,9 +2128,9 @@ def get_available_batches(kwargs):
|
|||||||
if kwargs.get("posting_time") is None:
|
if kwargs.get("posting_time") is None:
|
||||||
kwargs.posting_time = nowtime()
|
kwargs.posting_time = nowtime()
|
||||||
|
|
||||||
timestamp_condition = CombineDatetime(
|
timestamp_condition = stock_ledger_entry.posting_datetime <= get_combine_datetime(
|
||||||
stock_ledger_entry.posting_date, stock_ledger_entry.posting_time
|
kwargs.posting_date, kwargs.posting_time
|
||||||
) <= CombineDatetime(kwargs.posting_date, kwargs.posting_time)
|
)
|
||||||
|
|
||||||
query = query.where(timestamp_condition)
|
query = query.where(timestamp_condition)
|
||||||
|
|
||||||
|
|||||||
@@ -725,15 +725,6 @@ class BatchNoValuation(DeprecatedBatchNoValuation):
|
|||||||
stock_value_change = self.batch_avg_rate[batch_no] * ledger.qty
|
stock_value_change = self.batch_avg_rate[batch_no] * ledger.qty
|
||||||
self.stock_value_change += stock_value_change
|
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):
|
def calculate_valuation_rate(self):
|
||||||
if not hasattr(self, "wh_data"):
|
if not hasattr(self, "wh_data"):
|
||||||
return
|
return
|
||||||
@@ -947,12 +938,13 @@ class SerialBatchCreation:
|
|||||||
if self.get("make_bundle_from_sle") and self.type_of_transaction == "Inward":
|
if self.get("make_bundle_from_sle") and self.type_of_transaction == "Inward":
|
||||||
doc.flags.ignore_validate_serial_batch = True
|
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:
|
if not hasattr(self, "do_not_submit") or not self.do_not_submit:
|
||||||
doc.flags.ignore_voucher_validation = True
|
doc.flags.ignore_voucher_validation = True
|
||||||
doc.submit()
|
doc.submit()
|
||||||
|
else:
|
||||||
|
doc.save()
|
||||||
|
|
||||||
|
self.validate_qty(doc)
|
||||||
|
|
||||||
return doc
|
return doc
|
||||||
|
|
||||||
|
|||||||
@@ -989,18 +989,23 @@ class update_entries_after:
|
|||||||
if not frappe.db.exists("Serial and Batch Bundle", sle.serial_and_batch_bundle):
|
if not frappe.db.exists("Serial and Batch Bundle", sle.serial_and_batch_bundle):
|
||||||
return
|
return
|
||||||
|
|
||||||
doc = frappe.get_cached_doc("Serial and Batch Bundle", sle.serial_and_batch_bundle)
|
if self.args.get("sle_id") and sle.actual_qty < 0:
|
||||||
|
doc = frappe.db.get_value(
|
||||||
doc.set_incoming_rate(save=True, allow_negative_stock=self.allow_negative_stock)
|
"Serial and Batch Bundle",
|
||||||
doc.calculate_qty_and_amount(save=True)
|
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)
|
self.wh_data.stock_value = round_off_if_near_zero(self.wh_data.stock_value + doc.total_amount)
|
||||||
|
self.wh_data.qty_after_transaction += flt(doc.total_qty, self.flt_precision)
|
||||||
precision = doc.precision("total_qty")
|
if flt(self.wh_data.qty_after_transaction, self.flt_precision):
|
||||||
self.wh_data.qty_after_transaction += flt(doc.total_qty, precision)
|
self.wh_data.valuation_rate = flt(self.wh_data.stock_value, self.flt_precision) / flt(
|
||||||
if flt(self.wh_data.qty_after_transaction, precision):
|
self.wh_data.qty_after_transaction, self.flt_precision
|
||||||
self.wh_data.valuation_rate = flt(self.wh_data.stock_value, precision) / flt(
|
|
||||||
self.wh_data.qty_after_transaction, precision
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def update_valuation_rate_in_serial_and_batch_bundle(self, sle, valuation_rate):
|
def update_valuation_rate_in_serial_and_batch_bundle(self, sle, valuation_rate):
|
||||||
|
|||||||
Reference in New Issue
Block a user