diff --git a/erpnext/stock/serial_batch_bundle.py b/erpnext/stock/serial_batch_bundle.py index a1dd0a5af07..e7cbc8bceed 100644 --- a/erpnext/stock/serial_batch_bundle.py +++ b/erpnext/stock/serial_batch_bundle.py @@ -2,7 +2,7 @@ from collections import defaultdict import frappe from frappe import _, bold -from frappe.model.naming import make_autoname +from frappe.model.naming import NamingSeries, make_autoname, parse_naming_series from frappe.query_builder import Case from frappe.query_builder.functions import CombineDatetime, Sum, Timestamp from frappe.utils import add_days, cint, cstr, flt, get_link_to_form, getdate, now, nowtime, today @@ -1374,6 +1374,12 @@ class SerialBatchCreation: if self.get("voucher_type"): voucher_type = self.get("voucher_type") + obj = NamingSeries(self.serial_no_series) + current_value = obj.get_current_value() + + def get_series(partial_series, digits): + return f"{current_value:0{digits}d}" + posting_date = frappe.db.get_value( voucher_type, voucher_no, @@ -1381,7 +1387,9 @@ class SerialBatchCreation: ) for _i in range(abs(cint(self.actual_qty))): - serial_no = make_autoname(self.serial_no_series, "Serial No") + current_value += 1 + serial_no = parse_naming_series(self.serial_no_series, number_generator=get_series) + sr_nos.append(serial_no) serial_nos_details.append( ( @@ -1426,6 +1434,8 @@ class SerialBatchCreation: frappe.db.bulk_insert("Serial No", fields=fields, values=set(serial_nos_details)) + obj.update_counter(current_value) + return sr_nos