fix(serial_and_batch_bundle_selector): handle CSV attachment properly (backport #53460) (#53461)

Co-authored-by: diptanilsaha <diptanil@frappe.io>
fix(serial_and_batch_bundle_selector): handle CSV attachment properly (#53460)
This commit is contained in:
mergify[bot]
2026-03-15 07:45:00 +00:00
committed by GitHub
parent a6cf31edad
commit 7a7c4a03f0

View File

@@ -1684,17 +1684,34 @@ def upload_csv_file(item_code, file_path):
def get_serial_batch_from_csv(item_code, file_path):
if "private" in file_path:
file_path = frappe.get_site_path() + file_path
else:
file_path = frappe.get_site_path() + "/public" + file_path
from frappe.utils.csvutils import read_csv_content
serial_nos = []
batch_nos = []
with open(file_path) as f:
reader = csv.reader(f)
serial_nos, batch_nos = parse_csv_file_to_get_serial_batch(reader)
if not file_path:
return serial_nos, batch_nos
try:
file = frappe.get_doc("File", {"file_url": file_path})
except frappe.DoesNotExistError:
frappe.msgprint(
_("File '{0}' not found").format(frappe.bold(file_path)),
alert=True,
indicator="red",
raise_exception=FileNotFoundError,
)
if file.file_type != "CSV":
frappe.msgprint(
_("{0} is not a CSV file.").format(frappe.bold(file.file_name)),
alert=True,
indicator="red",
raise_exception=frappe.ValidationError,
)
csv_data = read_csv_content(file.get_content())
serial_nos, batch_nos = parse_csv_file_to_get_serial_batch(csv_data)
if serial_nos:
make_serial_nos(item_code, serial_nos)
@@ -2644,7 +2661,7 @@ def get_auto_batch_nos(kwargs):
)
if kwargs.based_on == "Expiry":
available_batches = sorted(available_batches, key=lambda x: (x.expiry_date or getdate("9999-12-31")))
available_batches = sorted(available_batches, key=lambda x: x.expiry_date or getdate("9999-12-31"))
if not kwargs.get("do_not_check_future_batches") and available_batches and kwargs.get("posting_date"):
filter_zero_near_batches(available_batches, kwargs)