diff --git a/pos/blueprints/fleet_bp.py b/pos/blueprints/fleet_bp.py index faad711..694c8e4 100644 --- a/pos/blueprints/fleet_bp.py +++ b/pos/blueprints/fleet_bp.py @@ -269,11 +269,12 @@ def list_all_history(): def create_vehicle(): """Create a fleet vehicle. - Body: {customer_id, plate, vin, make, model, year, current_mileage, fuel_type, color, owner_name, notes} + Body: {customer_id, plate, make, model, year, current_mileage, fuel_type, color, owner_name, notes} + Brand and model are required; plate is optional; VIN is not used. """ data = request.get_json() or {} - if not data.get('plate') and not data.get('vin'): - return jsonify({'error': 'plate or vin is required'}), 400 + if not data.get('make') or not data.get('model'): + return jsonify({'error': 'Marca y modelo son obligatorios'}), 400 if not data.get('customer_id'): return jsonify({'error': 'El vehiculo debe estar asignado a un cliente'}), 400 @@ -291,12 +292,12 @@ def create_vehicle(): cur.execute(""" INSERT INTO fleet_vehicles - (branch_id, customer_id, plate, vin, make, model, year, + (branch_id, customer_id, plate, make, model, year, current_mileage, fuel_type, color, owner_name, notes) - VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) + VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) RETURNING id """, ( - branch_id, data['customer_id'], data.get('plate'), data.get('vin'), + branch_id, data['customer_id'], data.get('plate'), data.get('make'), data.get('model'), data.get('year'), data.get('current_mileage', 0), data.get('fuel_type', 'gasolina'), data.get('color'), data.get('owner_name') or cust[0], data.get('notes'), diff --git a/pos/blueprints/service_order_bp.py b/pos/blueprints/service_order_bp.py index ff468ee..586585c 100644 --- a/pos/blueprints/service_order_bp.py +++ b/pos/blueprints/service_order_bp.py @@ -415,11 +415,12 @@ def create_customer_for_workshop(): def create_vehicle_for_workshop(): """Create a fleet vehicle directly from the workshop flow. - Vehicles must be assigned to a customer. + Vehicles must be assigned to a customer. Brand and model are required; + plate is optional and VIN is not used. """ data = request.get_json() or {} - if not data.get('plate') and not data.get('vin'): - return jsonify({'error': 'Se requiere placa o VIN'}), 400 + if not data.get('make') or not data.get('model'): + return jsonify({'error': 'Marca y modelo son obligatorios'}), 400 if not data.get('customer_id'): return jsonify({'error': 'El vehiculo debe estar asignado a un cliente'}), 400 @@ -434,12 +435,12 @@ def create_vehicle_for_workshop(): cur.execute(""" INSERT INTO fleet_vehicles - (branch_id, customer_id, plate, vin, make, model, year, + (branch_id, customer_id, plate, make, model, year, current_mileage, fuel_type, color, owner_name, notes) - VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) + VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) RETURNING id """, ( - data.get('branch_id', g.branch_id), data['customer_id'], data.get('plate'), data.get('vin'), + data.get('branch_id', g.branch_id), data['customer_id'], data.get('plate'), data.get('make'), data.get('model'), data.get('year'), data.get('current_mileage', 0), data.get('fuel_type', 'gasolina'), data.get('color'), cust[0], data.get('notes'), diff --git a/pos/static/js/workshop.js b/pos/static/js/workshop.js index 856b747..124b9a7 100644 --- a/pos/static/js/workshop.js +++ b/pos/static/js/workshop.js @@ -726,7 +726,6 @@ var Workshop = (function() { document.getElementById('nvCustomerName').value = customerName; document.getElementById('newVehicleModal').classList.add('is-open'); document.getElementById('nvPlate').value = ''; - document.getElementById('nvVIN').value = ''; document.getElementById('nvMake').value = ''; document.getElementById('nvModel').value = ''; document.getElementById('nvYear').value = ''; @@ -743,10 +742,11 @@ var Workshop = (function() { async function saveNewVehicle() { var plate = document.getElementById('nvPlate').value.trim(); - var vin = document.getElementById('nvVIN').value.trim(); + var make = document.getElementById('nvMake').value.trim(); + var model = document.getElementById('nvModel').value.trim(); var customerId = parseInt(document.getElementById('nvCustomerId').value, 10) || null; - if (!plate && !vin) { - alert('Se requiere al menos placa o VIN'); + if (!make || !model) { + alert('Marca y modelo son obligatorios'); return; } if (!customerId) { @@ -755,17 +755,16 @@ var Workshop = (function() { } var payload = { plate: plate, - vin: vin, customer_id: customerId, - make: document.getElementById('nvMake').value.trim() || null, - model: document.getElementById('nvModel').value.trim() || null, + make: make, + model: model, year: document.getElementById('nvYear').value ? parseInt(document.getElementById('nvYear').value, 10) : null, color: document.getElementById('nvColor').value.trim() || null, branch_id: (currentOrder ? currentOrder.branch_id : null) || (window.POS_USER ? window.POS_USER.branch_id : null) }; try { var res = await api('POST', '/vehicles', payload); - var label = plate + (payload.make ? ' · ' + payload.make : '') + (payload.model ? ' ' + payload.model : ''); + var label = [payload.make, payload.model, payload.year, plate].filter(Boolean).join(' · '); if (newVehicleContext === 'new') { var sel = document.getElementById('noVehicle'); var opt = document.createElement('option'); diff --git a/pos/templates/workshop.html b/pos/templates/workshop.html index 4086004..cd5d2bb 100644 --- a/pos/templates/workshop.html +++ b/pos/templates/workshop.html @@ -15,7 +15,7 @@ - +