From 2a1aee4ee48c3b0624ac8dcf0feea08318bbaffd Mon Sep 17 00:00:00 2001 From: consultoria-as Date: Tue, 31 Mar 2026 03:33:58 +0000 Subject: [PATCH] =?UTF-8?q?feat(pos):=20add=20v1.1=20migration=20=E2=80=94?= =?UTF-8?q?=20sale=5Fpayments,=20layaway=5Fitems,=20customer=5Fpayments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pos/migrations/runner.py | 2 +- pos/migrations/v1.1_pos_tables.sql | 55 ++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 pos/migrations/v1.1_pos_tables.sql diff --git a/pos/migrations/runner.py b/pos/migrations/runner.py index 4e6aee1..8249d60 100755 --- a/pos/migrations/runner.py +++ b/pos/migrations/runner.py @@ -13,7 +13,7 @@ MIGRATIONS_DIR = os.path.dirname(os.path.abspath(__file__)) # Migration registry: version -> filename MIGRATIONS = { 'v1.0': 'v1.0_initial.sql', - # Future: 'v1.1': 'v1.1_add_xyz.sql', + 'v1.1': 'v1.1_pos_tables.sql', } diff --git a/pos/migrations/v1.1_pos_tables.sql b/pos/migrations/v1.1_pos_tables.sql new file mode 100644 index 0000000..ef3eedc --- /dev/null +++ b/pos/migrations/v1.1_pos_tables.sql @@ -0,0 +1,55 @@ +-- /home/Autopartes/pos/migrations/v1.1_pos_tables.sql +-- POS Plan 3: Additional tables for sale payments and layaway items. +-- Run against each tenant DB. + +-- Sale payments: tracks individual payment methods for a sale (especially mixed payments) +CREATE TABLE IF NOT EXISTS sale_payments ( + id SERIAL PRIMARY KEY, + sale_id INTEGER REFERENCES sales(id), + register_id INTEGER REFERENCES cash_registers(id), + method VARCHAR(20) NOT NULL, -- efectivo, transferencia, tarjeta + amount NUMERIC(12,2) NOT NULL, + reference VARCHAR(100), -- transaction ref for non-cash + created_at TIMESTAMPTZ DEFAULT NOW() +); + +CREATE INDEX IF NOT EXISTS idx_sale_payments_sale ON sale_payments(sale_id); + +-- Customer payments: tracks credit payments (abonos) against customer balance +CREATE TABLE IF NOT EXISTS customer_payments ( + id SERIAL PRIMARY KEY, + customer_id INTEGER REFERENCES customers(id), + amount NUMERIC(12,2) NOT NULL, + payment_method VARCHAR(20) NOT NULL DEFAULT 'efectivo', + reference VARCHAR(100), + employee_id INTEGER REFERENCES employees(id), + register_id INTEGER REFERENCES cash_registers(id), + created_at TIMESTAMPTZ DEFAULT NOW() +); + +CREATE INDEX IF NOT EXISTS idx_customer_payments_customer ON customer_payments(customer_id); + +-- Layaway items: line items for a layaway (mirrors quotation_items structure) +CREATE TABLE IF NOT EXISTS layaway_items ( + id SERIAL PRIMARY KEY, + layaway_id INTEGER REFERENCES layaways(id), + inventory_id INTEGER REFERENCES inventory(id), + part_number VARCHAR(100), + name VARCHAR(300), + quantity INTEGER NOT NULL, + unit_price NUMERIC(12,2) NOT NULL, + discount_pct NUMERIC(5,2) DEFAULT 0, + tax_rate NUMERIC(5,4) DEFAULT 0.16, + subtotal NUMERIC(12,2) NOT NULL +); + +CREATE INDEX IF NOT EXISTS idx_layaway_items_layaway ON layaway_items(layaway_id); + +-- Additional indexes for POS query performance +CREATE INDEX IF NOT EXISTS idx_sales_register ON sales(register_id) WHERE status = 'completed'; +CREATE INDEX IF NOT EXISTS idx_sales_customer ON sales(customer_id); +CREATE INDEX IF NOT EXISTS idx_sales_created ON sales(created_at DESC); +CREATE INDEX IF NOT EXISTS idx_sales_branch_date ON sales(branch_id, created_at DESC); +CREATE INDEX IF NOT EXISTS idx_quotations_customer ON quotations(customer_id); +CREATE INDEX IF NOT EXISTS idx_layaways_customer ON layaways(customer_id); +CREATE INDEX IF NOT EXISTS idx_cash_registers_employee ON cash_registers(employee_id) WHERE status = 'open';