Exemple #1
0
def add_unpaid_reservation(_, info, **kwargs):
    print("kwargs>>", kwargs)
    print("info.context['user']>>>", info.context['user'])
    current_price = 0
    vehicle = Vehicle.objects(id=kwargs['vehicle_id']).first()
    user = User.objects(id=info.context['user'].id).first()
    parameter_list = ParameterInfo.objects()

    base_price = vehicle.default_hourly_rate

    start_time = dateutil.parser.parse(kwargs['start_time'])
    end_time = dateutil.parser.parse(kwargs['end_time'])
    delta = end_time - start_time

    if (delta.days >= 3):
        #front end reject.
        print("reject")
    elif (delta.days >= 1 and delta.days <= 2):
        current_price += delta.days * 24 * base_price
        current_price += math.ceil(delta.seconds / 3600) * base_price
        current_price *= (ParameterInfo.objects(
            description="24h to 72h").first()).rate

    elif (delta.days < 1 and math.ceil(delta.seconds / 3600) >= 11):
        current_price += math.ceil(delta.seconds / 3600) * base_price
        current_price *= (ParameterInfo.objects(
            description="11h to 24h").first()).rate

    elif (delta.days < 1 and math.ceil(delta.seconds / 3600) >= 6):
        current_price += math.ceil(delta.seconds / 3600) * base_price
        current_price *= (ParameterInfo.objects(
            description="6h to 10h").first()).rate

    elif (delta.days < 1 and math.ceil(delta.seconds / 3600) <= 5):
        current_price += math.ceil(delta.seconds / 3600) * base_price
        current_price *= (ParameterInfo.objects(
            description="below 5h").first()).rate

    current_price *= vehicle.vehicle_type.hourly_rate

    new_reservation_dict = {
        "vehicle": vehicle,
        "user": user,
        "start_time": kwargs['start_time'],
        "end_time": kwargs['end_time'],
        "actual_start_time": None,
        "actual_end_time": None,
        "normal_price": current_price,
        "penalty_fee": 0,
        "status": "unpaid"
    }
    newreservation = Reservation(**new_reservation_dict)
    newreservation.save()

    return newreservation
Exemple #2
0
def user_return_car(_, info, id, actual_end_time, comment):
    current_reservation = Reservation.objects(id=id).first()
    real_end_time = pytz.utc.localize(
        datetime.datetime.strptime(actual_end_time, "%Y-%m-%dT%H:%M:%S.%fZ"))
    original_end_time = pytz.utc.localize(current_reservation.end_time)
    delta = real_end_time - original_end_time
    if (delta.seconds / 3600 < 0.1 and delta.days == 0):
        current_reservation.update(set__status="returned",
                                   set__comment=comment,
                                   actual_end_time=actual_end_time)
        return current_reservation
    else:
        current_reservation.update(set__status="returned",
                                   set__comment=comment,
                                   actual_end_time=actual_end_time)
        vehicle = current_reservation.vehicle
        fee = vehicle.default_hourly_rate * math.ceil(delta.seconds / 3600) + (
            ParameterInfo.objects(description="24h to 72h").first()).rate
        current_reservation.update(set__penalty_fee=fee)
        return current_reservation
Exemple #3
0
# 8 elements
parameter_description = [
    'below 5h', '6h to 10h', '11h to 24h', '24h to 72h',
    '6 month membership fee', 'overdue fee'
]
# 8 numbers
parameter_number = [1, 0.95, 0.9, 0.8, 100, 50]

# script params
parser = argparse.ArgumentParser(description='Ingest all parameter')
parser.add_argument('--mongo_db',
                    default='car_rent',
                    help='mongodb db to connect to')
parser.add_argument('--mongo_url',
                    default='mongodb://localhost/car_rent',
                    help='mongodb url to connect to')
args = parser.parse_args()

connect(args.mongo_db, host=args.mongo_url, alias='db1')

parameter_pair = []
for x in range(6):
    one_pair = ParameterInfo(description=parameter_description[x],
                             rate=parameter_number[x])
    parameter_pair.append(one_pair)

ParameterInfo.objects.insert(parameter_pair)

disconnect(alias='db1')
Exemple #4
0
def getParameter(_, info, description):
    parameterInfo = ParameterInfo.objects(description=description).first()  # pylint: disable=maybe-no-member
    if (parameterInfo == None):
        raise Exception("Parameter not found")
    return parameterInfo
Exemple #5
0
def updateParameterInfo(_, info, id, **kwargs):
    parameter_info = ParameterInfo.objects(id=id).first()
    parameter_info.update(**kwargs)
    parameter_info.reload()
    return parameter_info
Exemple #6
0
def getParameterInfo(_, info, id):
    parameter_info = ParameterInfo.objects(id=id).first()
    return parameter_info
Exemple #7
0
def getAllParameterInfos(_, info):
    parameter_infos = ParameterInfo.objects()
    return parameter_infos