From 6eecf0701e1db119cf3ecaa43d3e6233068743a1 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Fri, 5 Jun 2026 18:45:46 +0530 Subject: [PATCH 1/2] fix: naming series issue (cherry picked from commit 3a50056968fe266325a794786b836c7da24650f8) # Conflicts: # erpnext/stock/doctype/batch/batch.py --- erpnext/stock/doctype/batch/batch.py | 8 +++++--- erpnext/stock/doctype/batch/test_batch.py | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/erpnext/stock/doctype/batch/batch.py b/erpnext/stock/doctype/batch/batch.py index c67060a8699..5c40b6051f7 100644 --- a/erpnext/stock/doctype/batch/batch.py +++ b/erpnext/stock/doctype/batch/batch.py @@ -10,8 +10,12 @@ from frappe.model.document import Document from frappe.model.naming import make_autoname, revert_series_if_last from frappe.query_builder.functions import CurDate, Sum from frappe.utils import cint, flt, get_link_to_form +<<<<<<< HEAD from frappe.utils.data import add_days from frappe.utils.jinja import render_template +======= +from frappe.utils.data import DateTimeLikeObject, add_days +>>>>>>> 3a50056968 (fix: naming series issue) class UnableToSelectBatchError(frappe.ValidationError): @@ -225,10 +229,8 @@ class Batch(Document): :return: The string that was generated. """ naming_series_prefix = _get_batch_prefix() - # validate_template(naming_series_prefix) - naming_series_prefix = render_template(str(naming_series_prefix), self.__dict__) key = _make_naming_series_key(naming_series_prefix) - name = make_autoname(key) + name = make_autoname(key, doc=self) return name diff --git a/erpnext/stock/doctype/batch/test_batch.py b/erpnext/stock/doctype/batch/test_batch.py index ed4a8c5509c..984de5c32dd 100644 --- a/erpnext/stock/doctype/batch/test_batch.py +++ b/erpnext/stock/doctype/batch/test_batch.py @@ -498,6 +498,24 @@ class TestBatch(ERPNextTestSuite): if not use_naming_series: frappe.set_value("Stock Settings", "Stock Settings", "use_naming_series", 0) + def test_naming_series_prefix_is_not_rendered_as_jinja(self): + from frappe.model.naming import InvalidNamingSeriesError + + stock_settings = frappe.get_single("Stock Settings") + use_naming_series = cint(stock_settings.use_naming_series) + original_prefix = stock_settings.naming_series_prefix + + frappe.set_value("Stock Settings", "Stock Settings", "use_naming_series", 1) + frappe.set_value("Stock Settings", "Stock Settings", "naming_series_prefix", "{{ 7*7 }}") + + try: + self.assertRaises( + InvalidNamingSeriesError, self.make_new_batch, "_Test Stock Item For Batch SSTI" + ) + finally: + frappe.set_value("Stock Settings", "Stock Settings", "naming_series_prefix", original_prefix) + frappe.set_value("Stock Settings", "Stock Settings", "use_naming_series", use_naming_series) + def make_new_batch(self, item_name=None, batch_id=None, do_not_insert=0): batch = frappe.new_doc("Batch") item = self.make_batch_item(item_name) From 7c46298fb687d0624cc9e2c28c33457071996920 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Fri, 5 Jun 2026 20:46:59 +0530 Subject: [PATCH 2/2] chore: fix conflicts Removed unused import of DateTimeLikeObject from frappe.utils.data. --- erpnext/stock/doctype/batch/batch.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/erpnext/stock/doctype/batch/batch.py b/erpnext/stock/doctype/batch/batch.py index 5c40b6051f7..40b1ac9d29e 100644 --- a/erpnext/stock/doctype/batch/batch.py +++ b/erpnext/stock/doctype/batch/batch.py @@ -10,12 +10,7 @@ from frappe.model.document import Document from frappe.model.naming import make_autoname, revert_series_if_last from frappe.query_builder.functions import CurDate, Sum from frappe.utils import cint, flt, get_link_to_form -<<<<<<< HEAD from frappe.utils.data import add_days -from frappe.utils.jinja import render_template -======= -from frappe.utils.data import DateTimeLikeObject, add_days ->>>>>>> 3a50056968 (fix: naming series issue) class UnableToSelectBatchError(frappe.ValidationError):