mirror of
https://github.com/frappe/erpnext.git
synced 2026-04-22 16:18:30 +00:00
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:
@@ -92,8 +92,10 @@ class SerialandBatchBundle(Document):
|
|||||||
if self.type_of_transaction == "Maintenance":
|
if self.type_of_transaction == "Maintenance":
|
||||||
return
|
return
|
||||||
|
|
||||||
self.validate_serial_nos_duplicate()
|
if not self.flags.ignore_validate_serial_batch or frappe.flags.in_test:
|
||||||
self.check_future_entries_exists()
|
self.validate_serial_nos_duplicate()
|
||||||
|
self.check_future_entries_exists()
|
||||||
|
|
||||||
self.set_is_outward()
|
self.set_is_outward()
|
||||||
self.calculate_total_qty()
|
self.calculate_total_qty()
|
||||||
self.set_warehouse()
|
self.set_warehouse()
|
||||||
@@ -340,6 +342,9 @@ class SerialandBatchBundle(Document):
|
|||||||
rate = frappe.db.get_value(child_table, self.voucher_detail_no, valuation_field)
|
rate = frappe.db.get_value(child_table, self.voucher_detail_no, valuation_field)
|
||||||
|
|
||||||
for d in self.entries:
|
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)
|
d.incoming_rate = flt(rate, precision)
|
||||||
if d.qty:
|
if d.qty:
|
||||||
d.stock_value_difference = flt(d.qty) * flt(d.incoming_rate)
|
d.stock_value_difference = flt(d.qty) * flt(d.incoming_rate)
|
||||||
@@ -841,6 +846,9 @@ class SerialandBatchBundle(Document):
|
|||||||
self.validate_serial_nos_inventory()
|
self.validate_serial_nos_inventory()
|
||||||
|
|
||||||
def set_purchase_document_no(self):
|
def set_purchase_document_no(self):
|
||||||
|
if self.flags.ignore_validate_serial_batch:
|
||||||
|
return
|
||||||
|
|
||||||
if not self.has_serial_no:
|
if not self.has_serial_no:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@@ -434,7 +434,6 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"default": "1",
|
"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. ",
|
"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",
|
"fieldname": "do_not_update_serial_batch_on_creation_of_auto_bundle",
|
||||||
"fieldtype": "Check",
|
"fieldtype": "Check",
|
||||||
@@ -460,7 +459,7 @@
|
|||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"issingle": 1,
|
"issingle": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2024-07-15 17:18:23.872161",
|
"modified": "2024-07-29 14:55:19.093508",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Stock",
|
"module": "Stock",
|
||||||
"name": "Stock Settings",
|
"name": "Stock Settings",
|
||||||
|
|||||||
@@ -110,6 +110,7 @@ class SerialBatchBundle:
|
|||||||
"type_of_transaction": "Inward" if self.sle.actual_qty > 0 else "Outward",
|
"type_of_transaction": "Inward" if self.sle.actual_qty > 0 else "Outward",
|
||||||
"company": self.company,
|
"company": self.company,
|
||||||
"is_rejected": self.is_rejected_entry(),
|
"is_rejected": self.is_rejected_entry(),
|
||||||
|
"make_bundle_from_sle": 1,
|
||||||
}
|
}
|
||||||
).make_serial_and_batch_bundle()
|
).make_serial_and_batch_bundle()
|
||||||
|
|
||||||
@@ -160,12 +161,13 @@ class SerialBatchBundle:
|
|||||||
|
|
||||||
if msg:
|
if msg:
|
||||||
error_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
|
+ msg
|
||||||
)
|
)
|
||||||
frappe.throw(_(error_msg))
|
frappe.throw(_(error_msg))
|
||||||
|
|
||||||
def set_serial_and_batch_bundle(self, sn_doc):
|
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})
|
self.sle.db_set({"serial_and_batch_bundle": sn_doc.name, "auto_created_serial_and_batch_bundle": 1})
|
||||||
|
|
||||||
if sn_doc.is_rejected:
|
if sn_doc.is_rejected:
|
||||||
@@ -324,6 +326,9 @@ class SerialBatchBundle:
|
|||||||
def set_warehouse_and_status_in_serial_nos(self):
|
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
|
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)
|
serial_nos = get_serial_nos(self.sle.serial_and_batch_bundle)
|
||||||
if not self.sle.serial_and_batch_bundle and self.sle.serial_no:
|
if not self.sle.serial_and_batch_bundle and self.sle.serial_no:
|
||||||
serial_nos = get_parsed_serial_nos(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:
|
if doc.voucher_no and frappe.get_cached_value(doc.voucher_type, doc.voucher_no, "docstatus") == 2:
|
||||||
doc.voucher_no = ""
|
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()
|
doc.save()
|
||||||
self.validate_qty(doc)
|
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."
|
msg = f"Please set Serial No Series in the item {self.item_code} or create Serial and Batch Bundle manually."
|
||||||
frappe.throw(_(msg))
|
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))):
|
for _i in range(abs(cint(self.actual_qty))):
|
||||||
serial_no = make_autoname(self.serial_no_series, "Serial No")
|
serial_no = make_autoname(self.serial_no_series, "Serial No")
|
||||||
sr_nos.append(serial_no)
|
sr_nos.append(serial_no)
|
||||||
@@ -1137,6 +1150,7 @@ class SerialBatchCreation:
|
|||||||
self.item_name,
|
self.item_name,
|
||||||
self.description,
|
self.description,
|
||||||
"Active",
|
"Active",
|
||||||
|
voucher_no,
|
||||||
self.batch_no,
|
self.batch_no,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -1155,6 +1169,7 @@ class SerialBatchCreation:
|
|||||||
"item_name",
|
"item_name",
|
||||||
"description",
|
"description",
|
||||||
"status",
|
"status",
|
||||||
|
"purchase_document_no",
|
||||||
"batch_no",
|
"batch_no",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user