Beispiel #1
0
    def owner_suitsfor_trip(self, owId):

        area = OwnerModel().get_area(owId)

        trip_by_area = TripPlanModel().trip_detailsbyArea(area)

        trip_plan_json = trips_plan_schema.dump(trip_by_area)

        return_data = []

        for trip in trip_plan_json:
            trip_details = self.get_tripDetails(trip['trip_id'])

            for details in trip_details:
                if (VehicleModel().driver_has_vehicle_byLoad(
                        owId, details['no_of_passengers'])
                        or VehicleModel().driver_has_vehicle_byAC(
                            owId, details['ac_condition'])
                        and VehicleModel().driver_has_vehicle_byType(
                            owId, details['vehicle_type'])):

                    return_data.append({
                        'is_ok': True,
                        'trip': trip['trip_id']
                    })
                    break
                else:
                    return_data.append({
                        'is_ok': False,
                        'trip': trip['trip_id']
                    })
                    break

        return return_data
Beispiel #2
0
    def get(self, trip_id):

        bid_details = []

        for ts in trip_status_schema.dump(
                TripStatusModel.find_by_tripId(trip_id)):
            print(ts)
            for owner in owner_schema.dump(OwnerModel().find_by_id(
                    ts['owner_id'])):
                print(ts['owner_id'], ts['assigned_driver'])

                for vehicle in vehicle_schema.dump(
                        VehicleModel().vehicle_detailsby_id(
                            ts['assigned_driver'])):
                    print(vehicle['vehicle_type'])

                    bid_details.append({
                        'ts_id': ts['ts_id'],
                        'company_name': owner['company_name'],
                        'area': owner['area'],
                        'contact': owner['contact_num'],
                        'budget': ts['trip_budget'],
                        'v_type': vehicle['vehicle_type'],
                        'v_brand': vehicle['vehicle_brand'],
                        'driver': ts['assigned_driver']
                    })
        print(bid_details)
        return bid_details
Beispiel #3
0
    def get(self, owId):

        return_data = []

        if not driver_schema.dump(DriverModel().get_driversby_ownerId(owId)):
            return {'message': 'no drivers available this moment'}

        for driver in driver_schema.dump(
                DriverModel().get_driversby_ownerId(owId)):

            for vehicle in vehicle_schema.dump(
                    VehicleModel().vehicle_detailby_driver(driver['dr_id'])):
                return_data.append({
                    'driver':
                    driver['dr_id'],
                    'no_of_passengers':
                    vehicle['no_of_passengers'],
                    'v_type':
                    vehicle['vehicle_type'],
                    'ac_condition':
                    vehicle['ac_condition'],
                    'availability':
                    vehicle['is_ontrip']
                })

        return return_data
Beispiel #4
0
 def get(self, tsId, drId):
     print('finish trip shit')
     if (TripStatusModel().set_trip_status(tsId, False, True)
             and DriverModel().set_isOnTrip(drId, False, True)
             and VehicleModel().set_isOnTrip(drId, False, True)):
         return True
     else:
         return False
Beispiel #5
0
    def get(self, tsId, drId):
        if TripStatusModel().trip_is_confirmed(tsId):
            if (DriverModel().set_isOnTrip(drId, True, False)
                    and VehicleModel().set_isOnTrip(drId, True, False)
                    and TripStatusModel().driver_confirmed(tsId)):

                return True
            else:
                return False
        else:
            return False
Beispiel #6
0
    def post(self):
        data = request.get_json(force=True)

        if not data:
            return {'message': 'No data provided'}, 400

        if VehicleModel.find_by_vehicle_reg_number(data['vehicle_reg']):
            return {
                'message':
                'Vehicle {} already exists'.format(data['vehicle_reg'])
            }

        new_vehicle = VehicleModel(
            vehicle_reg_number=data['vehicle_reg'],
            owner_id=data['owner_id'],
            driver_id=data['driver_id'],
            ac_condition=data['ac_condition'],
            vehicle_brand=data['v_brand'],
            vehicle_type=data['v_type'],
            no_of_passengers=data['capacity'],
            insurance_data=data['insurance'],
            is_ontrip=0,
            vehicle_insu_pic=data['vehicle_insu_pic'],
            vehicle_incomdoc_pic=data['vehicle_incomdoc_pic'],
            vehicle_front_pic=data['vehicle_front_pic'],
            vehicle_rear_pic=data['vehicle_rear_pic'],
            vehicle_inside_pic=data['vehicle_inside_pic'])

        try:
            new_vehicle.save_to_db()
            return {
                'message': 'Vehicle {} created'.format(data['vehicle_reg'])
            }
        except Exception as e:
            return {
                'message': 'Something went wrong',
                'error': e,
                'data': new_vehicle
            }, 500
Beispiel #7
0
def add_vehicle_model():
    data = request.get_json(force=True)
    make_id = data["make_id"]
    year = data["year"]
    price = data["price"]
    vehicle_name = data["name"]
    description = data["description"]

    add_make = VehicleModel(
        make_id=make_id,
        name=vehicle_name,
        year=year,
        price=price,
        description=description,
    )
    db.session.add(add_make)
    db.session.commit()
    return jsonify({"response": "Added new Vehicle Model"}), 201
Beispiel #8
0
 def get(self, owId):
     data = vehicle_schema.dump(
         VehicleModel().vehicle_detailsby_owner(owId))
     return data
Beispiel #9
0
 def get(self):
     d1 = VehicleModel().return_all()
     print(d1)
     res = vehicle_schema.dump(d1)
     return {'vehicle': res}
Beispiel #10
0
def retract_getsome(fraction_id,source_fraction_id,product_id,unit_id):
    """Hit the retraction Table
    date is handled over session-cookie
    first get the entrie in the acquire data from that retour what you want
    we could restrict boxes ID  to acquire data but the user could retour in
    boxes of another date, years ago.
    """
    fraction = FractionModel(fraction_id)
    source_fraction = FractionModel(source_fraction_id)
    product = ProductModel(product_id, source_fraction_id)
    product_entries = product.get_data()
    unit = UnitModel(product_entries['unit_set_id'])
    box = BoxModel(product_entries['boxes_set_id'])
    vehicle = VehicleModel()
    transaction_model = TransactionModel(fraction_id,source_fraction_id)
    #Do I repeat myself?
    
    if request.args.get('acquiredate'):
        session['acquiredate']= request.args.get('acquiredate')
        
    if 'acquiredate' in session:
        the_date = str(session.get('acquiredate'))
    #
    acquire_data = transaction_model.acquisitions_get_summary_by_date_product_unit(the_date,product_id,unit_id)

    form = Acquisition_Retraction_Form()
    
    form.unit_id.choices = unit.get_wtform_choices()
    form.vehicle_id.choices = vehicle.get_wtform_choices()
    form.box_id.choices = box.get_wtform_choices()
    form.alternate_unit_id.choices = unit.get_wtform_choices()
    
    #prefill formdata
    form.aq_date.data = datetime.strptime(the_date,form.aq_date.format).date()
    form.product_id.data = product_id
    form.fraction_id.data = fraction_id
    form.source_fraction_id.data = source_fraction_id
    form.unit_id.data = acquire_data['unit_id']
    form.unit_id.render_kw={"disabled":"disabled"}
    
    form.box_id.data = acquire_data['box_id']
    #form.box_id.render_kw={"disabled":"disabled"}
    
    if acquire_data['alternatesum'] and acquire_data['alternate_unit_id'] in [item[0] for item in form.alternate_unit_id.choices] :
        form.alternate_unit_id.data = acquire_data['alternate_unit_id']
    else:
        form.alternate_unit_id.data = 1 #defaults to KG (Datenmüll)
    
    if form.validate_on_submit():
        
        result = transaction_model.retraction_insert(form)
        if type(result) is str:
            flash(result, 'alert')
        elif result:
            flash(u'Übernommen!','success')
            
            return redirect(url_for('.retract_twopack', fraction_id=fraction_id,
                                    source_fraction_id=source_fraction_id))
        else:
            abort(500)
            
    if form.csrf_token.errors:
        flash(u'Zeitüberschreitung. Das Formular wird nach einer Stunde warten ungültig. Nichts gespeichert. Gleich nochmal versuchen.','warning')
        
        
    return render_template('transaction/retraction.html',
                            fraction=fraction,
                            source_fraction=source_fraction,
                            product_entries=product_entries,
                            acquire_data=acquire_data,
                            form=form
                            )
Beispiel #11
0
def acquire_getsome(fraction_id, source_fraction_id, product_id):
    """ GET ready to fire a POST to the acquisitions table
    the flow is: from source_fraction to fraction
    
    WHAT happens IF fraction_id is to drive the boxes and units,
    like DEPOT wants to have 264' boxes in Pounds of a product???
    
    """
    #init destination fractions
    fraction = FractionModel(fraction_id)
    #init source fraction
    source_fraction = FractionModel(source_fraction_id)

    product = ProductModel(product_id, source_fraction_id)
    #dict of product spec data (one db row)
    product_entries = product.get_data()
    unit = UnitModel(product_entries['unit_set_id'])
    box = BoxModel(product_entries['boxes_set_id'])
    vehicle = VehicleModel()
    transactions = TransactionModel(fraction_id, source_fraction_id)
    #the latest entries in acquisitions table
    #TODO variable count
    history_entries = transactions.acqusitions_get_last_inserts(12)    
    
    form = Acquisition_Retraction_Form()
    #print('dateFORMAT:'+str(form.aq_date.format))
    #print('Session::acquiredate:'+str(session.get('acquiredate')))
    
        
        #form.aq_date.data = session.get('acquiredate')
        
    #before validating wtf choises (<option>) must be given 
    form.unit_id.choices = unit.get_wtform_choices()
    form.vehicle_id.choices = vehicle.get_wtform_choices()
    form.box_id.choices = box.get_wtform_choices()

    #with boxes we css-style <options> in the template (render_kw?)
    boxset = box.get_set_by_id(product_entries['boxes_set_id'])

    form.alternate_unit_id.choices = unit.get_wtform_choices()
    
    if form.validate_on_submit():
        session['acquiredate'] = str(form.aq_date.data)
        
        #print('form-data:'+str(form.aq_date.data))
        #print('sessionACQUIREdate:'+str(session.get('acquiredate')))
        
        result = transactions.acqusition_insert(form)
        
        #print('>>>>>>>>>aqcuisition_insert_result: '+ str(result))
        if type(result) is str:
            flash(result, 'alert')
        elif result:
            flash(u'Die Angaben und Werte wurden erfolgreich übernommen und gespeichert.','success')
 
            return redirect(url_for('.acquire_getsome', fraction_id=fraction_id,
                     source_fraction_id=source_fraction_id,
                     product_id=product_id))
        else:
            abort(500)

    if form.csrf_token.errors:
        flash(u'Zeitüberschreitung. Das Formular wird nach einer Stunde warten ungültig. Nichts gespeichert. Gleich nochmal versuchen.','warning')
    
    #manualy set wtform.data initial_preselected
    if not form.is_submitted():
        #print("FORM SUBMIT!")
        if 'acquiredate' in session:
            set_date = datetime.strptime(session.get('acquiredate'),form.aq_date.format).date()
            form.aq_date.data = set_date
            
        form.fraction_id.data = fraction.fraction_id
        form.source_fraction_id.data = source_fraction.fraction_id
        form.product_id.data = product_entries['product_id']
        if  request.args.get('unit_id',''):
            #print('UNIT_ID!!!!'+str(request.args.get('unit_id',''))+str(type(request.args.get('unit_id',''))))
            if int(request.args.get('unit_id','')) in[item[0] for item in form.unit_id.choices]:
                form.unit_id.data=int(request.args.get('unit_id',''))
        else:
            form.unit_id.data = product_entries['unit_pivot_id']
        form.box_id.data = product_entries['box_pivot_id']
        form.box_count.data = 0
        form.vehicle_count.data = 0
    

    return render_template('transaction/acquisition.html',
                           fraction=fraction,
                           source_fraction=source_fraction,
                           product_entries=product_entries,
                           boxset=boxset,
                           history_entries=history_entries,
                           form=form)