feat(workshop): add new customer from new order modal
- Added POST /pos/api/service-orders/customers endpoint for workshop.edit users. - Added 'Nuevo cliente' modal reachable from the new service order form. - After creation the customer is automatically selected in the order.
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
Prefix: /pos/api/service-orders
|
||||
"""
|
||||
|
||||
import json
|
||||
|
||||
from flask import Blueprint, g, jsonify, request
|
||||
from middleware import require_auth
|
||||
from services.service_order_engine import (
|
||||
@@ -374,6 +376,40 @@ def assign_mechanic_endpoint(so_id):
|
||||
conn.close()
|
||||
|
||||
|
||||
@service_order_bp.route('/customers', methods=['POST'])
|
||||
@require_auth('workshop.edit')
|
||||
def create_customer_for_workshop():
|
||||
"""Create a customer directly from the workshop flow."""
|
||||
data = request.get_json() or {}
|
||||
if not data.get('name'):
|
||||
return jsonify({'error': 'El nombre es obligatorio'}), 400
|
||||
|
||||
conn = get_tenant_conn(g.tenant_id)
|
||||
cur = conn.cursor()
|
||||
try:
|
||||
cur.execute("""
|
||||
INSERT INTO customers
|
||||
(branch_id, name, rfc, razon_social, regimen_fiscal, uso_cfdi,
|
||||
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
|
||||
""", (
|
||||
data.get('branch_id', g.branch_id), data['name'], data.get('rfc'),
|
||||
data.get('razon_social'), data.get('regimen_fiscal'), data.get('uso_cfdi', 'G03'),
|
||||
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]
|
||||
conn.commit()
|
||||
cur.close(); conn.close()
|
||||
return jsonify({'id': customer_id, 'message': 'Cliente creado'}), 201
|
||||
except Exception as e:
|
||||
conn.rollback()
|
||||
cur.close(); conn.close()
|
||||
return jsonify({'error': str(e)}), 500
|
||||
|
||||
|
||||
@service_order_bp.route('/vehicles', methods=['POST'])
|
||||
@require_auth('workshop.edit')
|
||||
def create_vehicle_for_workshop():
|
||||
|
||||
Reference in New Issue
Block a user