예제 #1
0
def list_active_customers():
    """
    :return:
    :rtype:
    """
    query = Customer.select().where(Customer.status == True).count()
    return query
예제 #2
0
def display_all_customers():
    """

    :return:
    """
    customer_query = Customer.select()
    LOGGER.info('Displaying all the customers: ')
    customer_list = [(customer.customer_last_name + ',' +
                      customer.customer_name) for customer in customer_query]
    return customer_list
예제 #3
0
def delete_customer(customer_id):
    """

    :param customer_id:
    :type customer_id:
    :return:
    :rtype:
    """
    LOGGER.info('Deleting customer with id {}'.format(customer_id))

    try:
        customer = Customer.get(Customer.customer_id == customer_id)
        customer.delete_instance()
    except IndexError:
        LOGGER.info("Customer with id {} doesn't exist".format(customer_id))
예제 #4
0
def update_customer_credit(customer_id, credit_limit):
    """
    :param customer_id:
    :type customer_id:
    :param credit_limit:
    :type credit_limit:
    :return:
    :rtype:
    """

    customer = Customer.get(Customer.customer_id == customer_id)
    LOGGER.info('Credit limit before the change is {}'.format(customer.credit_limit))
    customer.credit_limit = int(credit_limit)
    customer.save()
    LOGGER.info('New credit limit is {}'.format(customer.credit_limit))
예제 #5
0
def search_customer(customer_id):
    """

    :param customer_id:
    :type customer_id:
    :return:
    :rtype:
    """
    try:
        customer = Customer.get(Customer.customer_id == customer_id)
        LOGGER.info('Found customer with id {} '.format(customer_id))
        customer_info = {'name': customer.customer_name,
                         'last_name': customer.customer_last_name,
                         'email_address': customer.email_address,
                         'phone_number': customer.phone_number}
        return customer_info
    except Customer.DoesNotExist as error:
        LOGGER.info("Could not find customer with id {}".format(customer_id))
        LOGGER.info(error)
        return {}
예제 #6
0
def add_customer(customer_id, name, last_name, home_address, phone_number,
                 email_address, status, credit_limit):
    """
    :param customer_id:
    :type customer_id:
    :param name:
    :type name:
    :param last_name:
    :type last_name:
    :param home_address:
    :type home_address:
    :param phone_number:
    :type phone_number:
    :param email_address:
    :type email_address:
    :param status:
    :type status:
    :param credit_limit:
    :type credit_limit:
    :return:
    :rtype:
    """
    try:
        new_customer = Customer.create(customer_id=customer_id,
                                       customer_name=name,
                                       customer_last_name=last_name,
                                       home_address=home_address,
                                       phone_number=phone_number,
                                       email_address=email_address,
                                       status=status,
                                       credit_limit=int(credit_limit))
        new_customer.save()
        LOGGER.info('Added a new customer')

    except peewee.IntegrityError as error:
        LOGGER.info(
            'Customer with ID {} could not be created, check all inputs'.
            format(customer_id))
        LOGGER.info(error)