From 31b533f9f91b18502d519d7df37a5a271665c64b Mon Sep 17 00:00:00 2001 From: consultoria-as Date: Thu, 2 Jul 2026 22:49:39 +0000 Subject: [PATCH] fix(inventory): support cp1252/latin-1 CSV encodings in bulk import --- pos/blueprints/inventory_bp.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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: