perf: huge number of serial no creation (backport #42522) (#42544)

perf: huge number of serial no creation (#42522)

(cherry picked from commit 1c7f7c8d1a)

Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
This commit is contained in:
mergify[bot]
2024-07-30 17:01:43 +05:30
committed by GitHub
parent 61280e6072
commit 6840f6cb26
3 changed files with 27 additions and 5 deletions

View File

@@ -92,8 +92,10 @@ class SerialandBatchBundle(Document):
if self.type_of_transaction == "Maintenance":
return
self.validate_serial_nos_duplicate()
self.check_future_entries_exists()
if not self.flags.ignore_validate_serial_batch or frappe.flags.in_test:
self.validate_serial_nos_duplicate()
self.check_future_entries_exists()
self.set_is_outward()
self.calculate_total_qty()
self.set_warehouse()
@@ -340,6 +342,9 @@ class SerialandBatchBundle(Document):
rate = frappe.db.get_value(child_table, self.voucher_detail_no, valuation_field)
for d in self.entries:
if (d.incoming_rate == rate) and d.qty and d.stock_value_difference:
continue
d.incoming_rate = flt(rate, precision)
if d.qty:
d.stock_value_difference = flt(d.qty) * flt(d.incoming_rate)
@@ -841,6 +846,9 @@ class SerialandBatchBundle(Document):
self.validate_serial_nos_inventory()
def set_purchase_document_no(self):
if self.flags.ignore_validate_serial_batch:
return
if not self.has_serial_no:
return

View File

@@ -434,7 +434,6 @@
},
{
"default": "1",
"depends_on": "use_serial_batch_fields",
"description": "If enabled, do not update serial / batch values in the stock transactions on creation of auto Serial \n / Batch Bundle. ",
"fieldname": "do_not_update_serial_batch_on_creation_of_auto_bundle",
"fieldtype": "Check",
@@ -460,7 +459,7 @@
"index_web_pages_for_search": 1,
"issingle": 1,
"links": [],
"modified": "2024-07-15 17:18:23.872161",
"modified": "2024-07-29 14:55:19.093508",
"modified_by": "Administrator",
"module": "Stock",
"name": "Stock Settings",

View File

@@ -110,6 +110,7 @@ class SerialBatchBundle:
"type_of_transaction": "Inward" if self.sle.actual_qty > 0 else "Outward",
"company": self.company,
"is_rejected": self.is_rejected_entry(),
"make_bundle_from_sle": 1,
}
).make_serial_and_batch_bundle()
@@ -160,12 +161,13 @@ class SerialBatchBundle:
if msg:
error_msg = (
f"Serial and Batch Bundle not set for item {self.item_code} in warehouse {self.warehouse}."
f"Serial and Batch Bundle not set for item {self.item_code} in warehouse {self.warehouse}"
+ msg
)
frappe.throw(_(error_msg))
def set_serial_and_batch_bundle(self, sn_doc):
self.sle.auto_created_serial_and_batch_bundle = 1
self.sle.db_set({"serial_and_batch_bundle": sn_doc.name, "auto_created_serial_and_batch_bundle": 1})
if sn_doc.is_rejected:
@@ -324,6 +326,9 @@ class SerialBatchBundle:
def set_warehouse_and_status_in_serial_nos(self):
from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos as get_parsed_serial_nos
if self.sle.auto_created_serial_and_batch_bundle and self.sle.actual_qty > 0:
return
serial_nos = get_serial_nos(self.sle.serial_and_batch_bundle)
if not self.sle.serial_and_batch_bundle and self.sle.serial_no:
serial_nos = get_parsed_serial_nos(self.sle.serial_no)
@@ -928,6 +933,10 @@ class SerialBatchCreation:
if doc.voucher_no and frappe.get_cached_value(doc.voucher_type, doc.voucher_no, "docstatus") == 2:
doc.voucher_no = ""
doc.flags.ignore_validate_serial_batch = False
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)
@@ -1120,6 +1129,10 @@ class SerialBatchCreation:
msg = f"Please set Serial No Series in the item {self.item_code} or create Serial and Batch Bundle manually."
frappe.throw(_(msg))
voucher_no = ""
if self.get("voucher_no"):
voucher_no = self.get("voucher_no")
for _i in range(abs(cint(self.actual_qty))):
serial_no = make_autoname(self.serial_no_series, "Serial No")
sr_nos.append(serial_no)
@@ -1137,6 +1150,7 @@ class SerialBatchCreation:
self.item_name,
self.description,
"Active",
voucher_no,
self.batch_no,
)
)
@@ -1155,6 +1169,7 @@ class SerialBatchCreation:
"item_name",
"description",
"status",
"purchase_document_no",
"batch_no",
]