Esempio n. 1
0
def get_trip_info():
    try:
        # print(request.args.get('trip_id'))
        trip_id = request.args.get('trip_id')
        trip = Trip.find_by_tripid(trip_id)
        return trip.to_json(), 200
    except Exception as e:
        print(e)
        return jsonify(error=f'Server Error: {e.args[0]}'), 500
Esempio n. 2
0
def get_trip_ticket():
    try:
        trip_id = request.args.get('trip_id')
        trip_dict = Trip.find_by_tripid(int(trip_id))
        ticket = Ticket(trip_dict)
        ticket.create_ticket()
        ticket_b64 = ticket.encode_b64()
        return jsonify(ticket_b64=ticket_b64.decode()), 200
    except Exception as e:
        return jsonify(error=str(e)), 400
Esempio n. 3
0
def trips_admin():
    trips = Trip.get_all()
    in_progress_trips = [i for i in trips if i['status'] == 'in_progress']
    finalized_trips = sorted(
        [i for i in trips if i['status'] in ['complete', 'canceled']],
        key=lambda i: i['trip_id'],
        reverse=True)
    return render_template('admin_panel/trips_admin.html',
                           in_progress_trips=in_progress_trips,
                           finalized_trips=finalized_trips)
Esempio n. 4
0
def create_trip():
    trip_dict = {
        'type': request.form.get('trip_type'),
        'truck_id': request.form.get('truck_id'),
        'amount': int(request.form.get('amount')) if request.form.get('amount') else None,
        'material_name': request.form.get('material_name'),
        'origin_name': request.form.get('origin_name'),
        'destination_name': request.form.get('destination_name'),
        'client_name': request.form.get('customer_name'),
        'sender_username': current_user.username,
        'sender_comment': request.form.get('sender_comment'),
        'status': 'in_progress' if request.form.get('trip_type') == "internal" else "complete"
        }
    try:
        # print(trip_dict)
        trip = Trip.create(**trip_dict)
        return jsonify({'trip_id': trip.trip_id}), 200
    except Exception as e:
        print(e)
        return jsonify({'error': str(e)}), 400
Esempio n. 5
0
def receive():
    try:
        trip_id = request.json['trip_id']
        status = request.json['status']
        finalizer_comment = request.json['finalizer_comment']
        if finalizer_comment is None:
            finalizer_comment = ""
        trip = Trip.find_by_tripid(trip_id)
        if trip.status == 'in_progress':
            trip.finalize(current_user.username, status, finalizer_comment)
            if status == 'complete':
                return jsonify(message=f'Viaje #{trip_id} con camión {trip.truck} ha sido RECIBIDO!'), 200
            elif status == 'canceled':
                return jsonify(message=f'Viaje #{trip_id} con camión {trip.truck} ha sido CANCELADO!'), 200
        else:
            status_translation = {'complete': 'COMPLETO', 'canceled': 'CANCELADO'}
            return jsonify(message=f'Viaje #{trip_id} con camión {trip.truck} ya había sido completado con estatus: \
                                    {status_translation[trip.status]}!'), 409
    except Exception as e:
        print(e)
        return jsonify(error=f'Server Error: {e.args[0]}'), 500
Esempio n. 6
0
def receive_dashboard():
    trips = Trip.get_all()
    in_progress_trips = [i for i in trips if i['status'] == 'in_progress']
    return render_template('receive_home.html', in_progress_trips=in_progress_trips)
Esempio n. 7
0
def _get_materials_on_trip():
    trips = Trip.get_all()
    materials_in_progress_l = set([i['material'] for i in trips])
    dict_of_materials = {m: m for m in materials_in_progress_l}
    return json.dumps(dict_of_materials)