SekiPOS server sync

This commit is contained in:
2026-06-23 15:20:14 -04:00
parent 5704980dbd
commit ccd1836d38
15 changed files with 1063 additions and 149 deletions

View File

@@ -38,16 +38,22 @@ def upsert():
cache_dir = current_app.config['CACHE_DIR']
final_image_path = download_image(image_url, barcode, cache_dir)
from datetime import datetime, timezone
now = datetime.now(timezone.utc).isoformat()
instance_id = current_app.config.get('INSTANCE_ID', '')
with get_db_connection() as conn:
conn.execute('''INSERT INTO products (barcode, name, price, image_url, stock, unit_type)
VALUES (?,?,?,?,?,?)
conn.execute('''INSERT INTO products (barcode, name, price, image_url, stock, unit_type, updated_at, updated_by)
VALUES (?,?,?,?,?,?,?,?)
ON CONFLICT(barcode) DO UPDATE SET
name=excluded.name,
price=excluded.price,
image_url=excluded.image_url,
stock=excluded.stock,
unit_type=excluded.unit_type''',
(barcode, name, price, final_image_path, stock, unit_type))
unit_type=excluded.unit_type,
updated_at=excluded.updated_at,
updated_by=excluded.updated_by''',
(barcode, name, price, final_image_path, stock, unit_type, now, instance_id))
conn.commit()
return redirect(url_for('inventory.inventory'))
@@ -102,9 +108,12 @@ def bulk_price_update():
return jsonify({"error": "Missing data"}), 400
try:
from datetime import datetime, timezone
now = datetime.now(timezone.utc).isoformat()
instance_id = current_app.config.get('INSTANCE_ID', '')
with get_db_connection() as conn:
params = [(float(new_price), b) for b in barcodes]
conn.executemany('UPDATE products SET price = ? WHERE barcode = ?', params)
params = [(float(new_price), now, instance_id, b) for b in barcodes]
conn.executemany('UPDATE products SET price = ?, updated_at = ?, updated_by = ? WHERE barcode = ?', params)
conn.commit()
return jsonify({"status": "success"}), 200
except Exception as e: