mirror of
https://github.com/frappe/erpnext.git
synced 2026-03-24 05:32:46 +01:00
fix(serial_and_batch_bundle_selector): handle CSV attachment properly (#53460)
This commit is contained in:
@@ -1715,17 +1715,34 @@ def upload_csv_file(item_code: str, file_path: str):
|
||||
|
||||
|
||||
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)
|
||||
@@ -2823,7 +2840,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_datetime"):
|
||||
filter_zero_near_batches(available_batches, kwargs)
|
||||
|
||||
Reference in New Issue
Block a user