mirror of
https://github.com/frappe/erpnext.git
synced 2026-04-14 20:35:09 +00:00
Co-authored-by: diptanilsaha <diptanil@frappe.io> fix(serial_and_batch_bundle_selector): handle CSV attachment properly (#53460)
This commit is contained in:
@@ -1684,17 +1684,34 @@ def upload_csv_file(item_code, file_path):
|
|||||||
|
|
||||||
|
|
||||||
def get_serial_batch_from_csv(item_code, file_path):
|
def get_serial_batch_from_csv(item_code, file_path):
|
||||||
if "private" in file_path:
|
from frappe.utils.csvutils import read_csv_content
|
||||||
file_path = frappe.get_site_path() + file_path
|
|
||||||
else:
|
|
||||||
file_path = frappe.get_site_path() + "/public" + file_path
|
|
||||||
|
|
||||||
serial_nos = []
|
serial_nos = []
|
||||||
batch_nos = []
|
batch_nos = []
|
||||||
|
|
||||||
with open(file_path) as f:
|
if not file_path:
|
||||||
reader = csv.reader(f)
|
return serial_nos, batch_nos
|
||||||
serial_nos, batch_nos = parse_csv_file_to_get_serial_batch(reader)
|
|
||||||
|
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:
|
if serial_nos:
|
||||||
make_serial_nos(item_code, serial_nos)
|
make_serial_nos(item_code, serial_nos)
|
||||||
@@ -2644,7 +2661,7 @@ def get_auto_batch_nos(kwargs):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if kwargs.based_on == "Expiry":
|
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"):
|
if not kwargs.get("do_not_check_future_batches") and available_batches and kwargs.get("posting_date"):
|
||||||
filter_zero_near_batches(available_batches, kwargs)
|
filter_zero_near_batches(available_batches, kwargs)
|
||||||
|
|||||||
Reference in New Issue
Block a user