Пример #1
0
def validate_booking_dict(bookingdict, new=True):
    validation = {}
    validation['status'] = True
    validation['message'] = "Valid booking"
    required_keys = []
    if new is True:
        required_keys = [
            "cust_id", "product_id", "passenger_detail", "pickup_timestamp",
            "pickup_location", "booking_channel"
        ]
    string_keys = [
        "cust_id", "product_id", "passenger_detail", "passenger_mobile",
        "remarks"
    ]
    mobile_nums = ["passenger_mobile"]
    validation = utils.validate_dict(bookingdict,
                                     required_keys=required_keys,
                                     string_keys=string_keys,
                                     mobile_nums=mobile_nums)
    if "cust_id" in bookingdict.keys():
        if bookingdict['cust_id'] == "retail":
            if not bookingdict['passenger_mobile'] or bookingdict[
                    'passenger_mobile'] is None:
                validation[
                    'message'] = "Passenger Mobile Must be provided for retail bookings"
                validation['status'] = False
    if validation['status'] is True:
        sakhacabsxpal.logger.info("bookingdict: " + validation['message'])
    else:
        sakhacabsxpal.logger.error("bookingdict: " + validation['message'])
    return validation
Пример #2
0
def validate_invoice_dict(invoicedict, new=True):
    validation = {}
    validation['status'] = True
    validation['message'] = "Valid vehicle"
    required_keys = []
    if new is True:
        required_keys = ["invoicelines", "cust_id", "invoice_date"]
    validation = utils.validate_dict(invoicedict, required_keys=required_keys)
    if validation['status'] is True:
        sakhacabsxpal.logger.info("invoicedict: " + validation['message'])
    else:
        sakhacabsxpal.logger.error("invoicedict: " + validation['message'])
    return validation
Пример #3
0
def validate_dutyslip_dict(dutyslipdict, new=True):
    validation = {}
    validation['status'] = True
    validation['message'] = "Valid dutyslip"
    required_keys = []
    if new is True:
        required_keys = ["driver", "assignment"]
    string_keys = ["driver", "vehicle", "remarks"]
    dates = ['open_time', 'close_time']
    numbers = [
        'open_kms', 'close_kms', 'parking_charges', 'toll_charges', 'amount'
    ]
    validation = utils.validate_dict(dutyslipdict,
                                     required_keys=required_keys,
                                     string_keys=string_keys,
                                     dates=dates,
                                     numbers=numbers)

    try:
        if datetime.datetime.strptime(
                dutyslipdict['open_time'],
                "%Y-%m-%d %H:%M:%S") > datetime.datetime.strptime(
                    dutyslipdict['close_time'], "%Y-%m-%d %H:%M:%S"):
            validation['status'] = False
            validation['message'] = "Open time cant be after close time"
    except Exception as e:
        validation['status'] = False
        validation['message'] = "ERROR IN TIME VALIDATION " + str(e)

    try:
        if float(dutyslipdict['open_kms']) > float(dutyslipdict['close_kms']):
            validation['status'] = False
            validation['message'] = "Open kms cant be more than close kms"
    except Exception as e:
        validation['status'] = False
        validation['message'] = "ERROR IN DIST VALIDATION " + str(e)
    try:
        if "vehicle" in dutyslipdict.keys() and dutyslipdict['vehicle'] != "":
            if len(
                    documents.Vehicle.objects(
                        vehicle_id=dutyslipdict['vehicle'])) == 0:
                validation['status'] = False
                validation['message'] = "Unknown vehicle id"
    except Exception as e:
        validation['status'] = False
        validation['message'] = "ERROR IN VEHICLE VALIDATION " + str(e)
    if validation['status'] is True:
        sakhacabsxpal.logger.info("dutyslipdict: " + validation['message'])
    else:
        sakhacabsxpal.logger.error("dutyslipdict: " + validation['message'])
    return validation
Пример #4
0
def validate_locupdate_dict(locupdatedict, new=True):
    validation = {}
    validation['status'] = True
    validation['message'] = "Valid location update"
    required_keys = []
    if new is True:
        required_keys = ["driver_id", "timestamp"]
    string_keys = ["driver_id"]
    validation = utils.validate_dict(locupdatedict,
                                     required_keys=required_keys,
                                     string_keys=string_keys)
    if validation['status'] is True:
        sakhacabsxpal.logger.info("locupdatedict: " + validation['message'])
    else:
        sakhacabsxpal.logger.error("locupdatedict: " + validation['message'])
    return validation
Пример #5
0
def validate_vehicle_dict(vehicledict, new=True):
    validation = {}
    validation['status'] = True
    validation['message'] = "Valid vehicle"
    required_keys = []
    if new is True:
        required_keys = ["vehicle_id"]
    string_keys = ["vehicle_id"]
    validation = utils.validate_dict(vehicledict,
                                     required_keys=required_keys,
                                     string_keys=string_keys)
    if validation['status'] is True:
        sakhacabsxpal.logger.info("vehicledict: " + validation['message'])
    else:
        sakhacabsxpal.logger.error("vehicledict: " + validation['message'])
    return validation
Пример #6
0
def validate_customer_dict(customerdict, new=True):
    validation = {}
    validation['status'] = True
    validation['message'] = "Valid customer"
    required_keys = []
    if new is True:
        required_keys = ["cust_id", "mobile_num"]
    string_keys = ["cust_id"]
    mobile_nums = ["mobile_num"]
    validation = utils.validate_dict(customerdict,
                                     required_keys=required_keys,
                                     string_keys=string_keys,
                                     mobile_nums=mobile_nums)
    if validation['status'] is True:
        sakhacabsxpal.logger.info("customerdict: " + validation['message'])
    else:
        sakhacabsxpal.logger.error("customerdict: " + validation['message'])
    return validation
Пример #7
0
def validate_product_dict(productdict, new=True):
    validation = {}
    validation['status'] = True
    validation['message'] = "Valid product"
    required_keys = []
    if new is True:
        required_keys = ["product_id"]
    string_keys = ["product_id"]
    numbers = [
        "included_hrs", "included_kms", "extra_hrs_rate", "extra_kms_rate"
    ]  # CHANGELOG #11 - AV - For #261
    validation = utils.validate_dict(productdict,
                                     required_keys=required_keys,
                                     string_keys=string_keys,
                                     numbers=numbers)
    if validation['status'] is True:
        sakhacabsxpal.logger.info("productdict: " + validation['message'])
    else:
        sakhacabsxpal.logger.error("productdict: " + validation['message'])
    return validation