feat(workshop): make brand/model required, plate optional, remove VIN
- create_vehicle endpoints now require make and model; plate is optional; VIN is no longer stored. - Updated new-vehicle modal: removed VIN field, plate is optional, brand/model marked required.
This commit is contained in:
@@ -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'),
|
||||
|
||||
@@ -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'),
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<meta name="theme-color" content="#F5A623" />
|
||||
<link rel="shortcut icon" type="image/png" href="/pos/static/pwa/icon-192.png" />
|
||||
|
||||
<link rel="stylesheet" href="/pos/static/css/workshop.css?v=41">
|
||||
<link rel="stylesheet" href="/pos/static/css/workshop.css?v=42">
|
||||
<style>
|
||||
.so-notes-grid { display: grid; grid-template-columns: 120px 1fr; gap: var(--space-2); align-items: start; }
|
||||
.so-notes-grid .form-label { margin: 0; padding-top: var(--space-2); }
|
||||
@@ -348,19 +348,15 @@
|
||||
<div class="modal__body">
|
||||
<form class="form-grid" id="newVehicleForm" onsubmit="return false;">
|
||||
<div class="form-field">
|
||||
<label class="form-label" for="nvPlate">Placa *</label>
|
||||
<input class="form-input" id="nvPlate" placeholder="Ej. ABC-123" />
|
||||
<label class="form-label" for="nvPlate">Placa</label>
|
||||
<input class="form-input" id="nvPlate" placeholder="Ej. ABC-123 (opcional)" />
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<label class="form-label" for="nvVIN">VIN</label>
|
||||
<input class="form-input" id="nvVIN" placeholder="Número de serie" />
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<label class="form-label" for="nvMake">Marca</label>
|
||||
<label class="form-label" for="nvMake">Marca *</label>
|
||||
<input class="form-input" id="nvMake" placeholder="Ej. Nissan" />
|
||||
</div>
|
||||
<div class="form-field">
|
||||
<label class="form-label" for="nvModel">Modelo</label>
|
||||
<label class="form-label" for="nvModel">Modelo *</label>
|
||||
<input class="form-input" id="nvModel" placeholder="Ej. Versa" />
|
||||
</div>
|
||||
<div class="form-field">
|
||||
@@ -487,7 +483,7 @@
|
||||
<script src="/pos/static/js/pos-utils.js?v=33" defer></script>
|
||||
<script src="/pos/static/js/sidebar.js?v=36" defer></script>
|
||||
<script src="/pos/static/js/offline-banner.js" defer></script>
|
||||
<script src="/pos/static/js/workshop.js?v=41" defer></script>
|
||||
<script src="/pos/static/js/workshop.js?v=42" defer></script>
|
||||
<script>if('serviceWorker' in navigator){navigator.serviceWorker.register('/pos/sw.js',{scope:'/pos/'});}</script>
|
||||
<script src="/pos/static/js/pwa-install.js" defer></script>
|
||||
<script src="/pos/static/js/chat.js" defer></script>
|
||||
|
||||
Reference in New Issue
Block a user