diff --git a/erpnext/stock/serial_batch_bundle.py b/erpnext/stock/serial_batch_bundle.py index 890899c7343..db9cf422b5f 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, now, nowtime, today @@ -1334,8 +1334,16 @@ class SerialBatchCreation: if self.get("voucher_no"): voucher_no = self.get("voucher_no") + 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}" + 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( ( @@ -1376,6 +1384,8 @@ class SerialBatchCreation: frappe.db.bulk_insert("Serial No", fields=fields, values=set(serial_nos_details)) + obj.update_counter(current_value) + return sr_nos