diff --git a/pos/blueprints/customers_bp.py b/pos/blueprints/customers_bp.py index bd00503..2a43ba3 100644 --- a/pos/blueprints/customers_bp.py +++ b/pos/blueprints/customers_bp.py @@ -161,8 +161,9 @@ def create_customer(): cur.execute(""" INSERT INTO customers (branch_id, name, rfc, razon_social, regimen_fiscal, uso_cfdi, - cp, email, phone, address, price_tier, credit_limit, vehicle_info) - VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) + cp, email, phone, address, price_tier, credit_limit, + max_discount_pct, vehicle_info) + VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) RETURNING id """, ( branch_id, data['name'], data.get('rfc'), data.get('razon_social'), @@ -170,6 +171,7 @@ def create_customer(): data.get('cp'), data.get('email'), data.get('phone'), data.get('address'), data.get('price_tier', 1), data.get('credit_limit', 0), + data.get('max_discount_pct', 0), json.dumps(data['vehicle_info']) if data.get('vehicle_info') else None )) customer_id = cur.fetchone()[0] diff --git a/pos/migrations/runner.py b/pos/migrations/runner.py index 14863f4..9044273 100755 --- a/pos/migrations/runner.py +++ b/pos/migrations/runner.py @@ -51,6 +51,7 @@ MIGRATIONS = { "v4.2": "v4.2_meli_sync_queue.sql", "v4.3": "v4.3_facturapi.sql", "v4.4": "v4.4_workshop.sql", + "v4.5": "v4.5_customer_max_discount.sql", } diff --git a/pos/migrations/v4.5_customer_max_discount.sql b/pos/migrations/v4.5_customer_max_discount.sql new file mode 100644 index 0000000..22bc602 --- /dev/null +++ b/pos/migrations/v4.5_customer_max_discount.sql @@ -0,0 +1,5 @@ +-- /home/Autopartes/pos/migrations/v4.5_customer_max_discount.sql +-- Tenant DB schema v4.5 — add per-customer maximum discount percentage. + +ALTER TABLE customers + ADD COLUMN IF NOT EXISTS max_discount_pct NUMERIC(5,2) DEFAULT 0; diff --git a/pos/services/catalog_service.py b/pos/services/catalog_service.py index b74037a..a82b64f 100644 --- a/pos/services/catalog_service.py +++ b/pos/services/catalog_service.py @@ -349,11 +349,28 @@ def get_engines(master_conn, model_id, year_id, mye_ids=None): FROM model_year_engine mye JOIN engines e ON e.id_engine = mye.engine_id WHERE mye.model_id = ANY(%s) AND mye.year_id = %s{mye_filter} - ORDER BY e.name_engine, mye.trim_level + ORDER BY e.name_engine, mye.trim_level, mye.id_mye """, tuple(params)) rows = cur.fetchall() cur.close() - return [{'id_mye': r[0], 'name_engine': r[1], 'trim_level': r[2] or ''} for r in rows] + + def _clean_engine_name(name): + if not name or name.strip().upper() in ('N/A', 'RUEDA', ''): + return 'Sin especificar' + return name.strip() + + # Deduplicate identical (name, trim) entries so the user doesn't see + # multiple indistinguishable "Sin especificar" options. + seen = set() + results = [] + for id_mye, name_engine, trim_level in rows: + clean_name = _clean_engine_name(name_engine) + key = (clean_name, trim_level or '') + if key in seen: + continue + seen.add(key) + results.append({'id_mye': id_mye, 'name_engine': clean_name, 'trim_level': key[1]}) + return results def get_categories(master_conn, mye_id, allowed_brands=None): diff --git a/pos/static/js/brand-catalog.js b/pos/static/js/brand-catalog.js index 2ca59f9..8b32ade 100644 --- a/pos/static/js/brand-catalog.js +++ b/pos/static/js/brand-catalog.js @@ -14,6 +14,7 @@ brandId: null, model: null, modelId: null, + modelVariantIds: null, // array of TecDoc model ids for grouped variants year: null, yearId: null, engine: null, @@ -63,7 +64,7 @@ reset: function() { this.state = 'brands'; - this.nav = { brand: null, brandId: null, model: null, modelId: null, year: null, yearId: null, engine: null, myeId: null, category: null, categoryId: null }; + this.nav = { brand: null, brandId: null, model: null, modelId: null, modelVariantIds: null, year: null, yearId: null, engine: null, myeId: null, category: null, categoryId: null }; this._allBrands = []; this._lastItems = []; this._offset = 0; @@ -96,7 +97,7 @@ parts.push('' + escapeHtml(this.nav.brand) + ''); } if (this.nav.model) { - parts.push('' + escapeHtml(this.nav.model) + ''); + parts.push('' + escapeHtml(this.nav.model) + ''); } if (this.nav.year) { parts.push('' + this.nav.year + ''); @@ -202,7 +203,8 @@ renderModelList: function(models) { var html = '