Beispiel #1
0
def delete_customer(customer_id):
    '''delete a customer by id.'''
    try:
        with DB.atomic():
            delete_query = Customer.delete().where(Customer.customer_id == customer_id)
            delete_query.execute()
    except IntegrityError:
        LOGGER.warning("Customer ID %s not found.", customer_id)
def delete_customer(delete_name):
    '''delete a customer by id.'''
    try:
        with DB.atomic():
            Customer.delete().where(Customer.name == delete_name).execute()
            result = f'Succesfully deleted {delete_name}'
    except IntegrityError:
        result = f'{delete_name} does not exist'
    return result
Beispiel #3
0
def update_customer_credit(customer_id, credit_limit):
    """Update an existing customer's credit limit"""
    try:
        with DB.atomic():
            customer = Customer.get(Customer.customer_id == customer_id)
            customer.credit_limit = credit_limit
            customer.save()
    except pw.DoesNotExist:
        LOGGER.error("Failed to update ID '%s': not found in database",
                     customer_id)
        raise ValueError
def add_customer(name, lastname, home_address, phone_number, email_address,
                 status, poverty_score):
    '''atomic() is easier than transaction()'''
    try:
        with DB.atomic():
            Customer.create(name=name,
                            lastname=lastname,
                            home_address=home_address,
                            phone_number=phone_number,
                            email_address=email_address,
                            status=status,
                            credit_limit=poverty_score)
    except IntegrityError:
        LOGGER.warning("Name %s is already taken.", name)
def add_customer(customer_id, name, lastname, home_address, phone_number,
                 email_address, status, credit_limit):
    '''add new customer function.'''
    try:
        with DB.atomic():
            Customer.create(customer_id=customer_id,
                            name=name,
                            lastname=lastname,
                            home_address=home_address,
                            phone_number=phone_number,
                            email_address=email_address,
                            status=status,
                            credit_limit=credit_limit)
        LOGGER.info("Adding customer %s to database.", customer_id)
    except IntegrityError:
        LOGGER.warning("Customer ID %s is already taken.", customer_id)
Beispiel #6
0
def add_customer(customer_id, name, lastname, home_address, phone_number,
                 email_address, status, credit_limit):
    #pylint: disable=too-many-arguments
    '''
    This function adds a customer and its data to the customer database
    '''
    logging.debug('Attempting to add customer %s to database', customer_id)
    with DB.atomic():
        try:
            added_customer = Customer.create(customer_id=customer_id,
                                             name=name,
                                             lastname=lastname,
                                             home_address=home_address,
                                             phone_number=phone_number,
                                             email_address=email_address,
                                             status=status,
                                             credit_limit=credit_limit)
            added_customer.save()
            logging.debug('Successfully added customer %s to database',
                          customer_id)
        except p.DatabaseError:
            logging.error('Could not add customer %s to database', customer_id)