diff --git a/blueprints/auth.py b/blueprints/auth.py index 44a0f86..0e78fc3 100644 --- a/blueprints/auth.py +++ b/blueprints/auth.py @@ -104,15 +104,19 @@ def trigger_sync(): try: db_file = current_app.config.get('DB_FILE', '') instance_id = current_app.config.get('INSTANCE_ID', '') - server_url = current_app.config.get('SERVER_URL', '') + server_url = '' + display_name = '' sync_secret = '' if db_file: instance_file = os.path.join(os.path.dirname(db_file), 'instance.json') if os.path.exists(instance_file): with open(instance_file) as f: - sync_secret = json.load(f).get('sync_secret', '') + cfg = json.load(f) + server_url = cfg.get('server_url', '') + display_name = cfg.get('display_name', 'Caja Principal') + sync_secret = cfg.get('sync_secret', '') if server_url: - sm = SyncManager(db_file, instance_id, server_url, current_app.config.get('DISPLAY_NAME', ''), sync_secret) + sm = SyncManager(db_file, instance_id, server_url, display_name, sync_secret) sm._push() sm._pull() return jsonify({"status": "ok"}) diff --git a/blueprints/finance.py b/blueprints/finance.py index 50f0bc1..8c447ca 100644 --- a/blueprints/finance.py +++ b/blueprints/finance.py @@ -182,15 +182,6 @@ def gastos(): with get_db_connection() as conn: cur = conn.cursor() - cur.execute(''' - CREATE TABLE IF NOT EXISTS expenses ( - id INTEGER PRIMARY KEY AUTOINCREMENT, - date TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - description TEXT NOT NULL, - amount INTEGER NOT NULL - ) - ''') - sales_total = cur.execute("SELECT SUM(total) FROM sales WHERE strftime('%Y-%m', date, 'localtime') = ?", (selected_month,)).fetchone()[0] or 0 expenses_total = cur.execute("SELECT SUM(amount) FROM expenses WHERE strftime('%Y-%m', date, 'localtime') = ?", (selected_month,)).fetchone()[0] or 0 diff --git a/core/db.py b/core/db.py index 77aed1f..b280fc3 100644 --- a/core/db.py +++ b/core/db.py @@ -66,6 +66,12 @@ def init_db(db_file): subtotal REAL, FOREIGN KEY(ticket_id) REFERENCES debtor_tickets(id) ON DELETE CASCADE)''') + conn.execute('''CREATE TABLE IF NOT EXISTS expenses + (id INTEGER PRIMARY KEY AUTOINCREMENT, + date TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + description TEXT NOT NULL, + amount INTEGER NOT NULL)''') + conn.execute('''CREATE TABLE IF NOT EXISTS sync_deletions (id INTEGER PRIMARY KEY AUTOINCREMENT, entity_type TEXT NOT NULL,