diff --git a/pos/blueprints/inventory_bp.py b/pos/blueprints/inventory_bp.py index 7d0e48e..881a5a8 100644 --- a/pos/blueprints/inventory_bp.py +++ b/pos/blueprints/inventory_bp.py @@ -450,8 +450,17 @@ def bulk_import_items(): try: ext = os.path.splitext(file.filename)[1].lower() if ext == '.csv': - stream = io.TextIOWrapper(file.stream, encoding='utf-8-sig') - reader = csv.DictReader(stream) + raw = file.stream.read() + decoded = None + for enc in ('utf-8-sig', 'cp1252', 'latin-1'): + try: + decoded = raw.decode(enc) + break + except UnicodeDecodeError: + continue + if decoded is None: + return jsonify({'error': 'Unable to detect CSV encoding. Please save the file as UTF-8.'}), 400 + reader = csv.DictReader(io.StringIO(decoded)) rows = list(reader) elif ext in ('.xls', '.xlsx', '.xlsm'): try: