Exemple #1
0
 def make_sale():
     """
     Make a sale of product to customer.
     """
     Customer.print_all()
     customer_id = input("\nCustomer id:\n")
     Product.print_all()
     product_id = input("\nProduct id:\n")
     quantity = input("\nQuantity\n")
     try:
         customer = Customer.get_by_id(customer_id)
         check = customer.purchase(product_id, quantity)
         bcolors.print_success(check)
     except ValueError as e:
         bcolors.print_fail(str(e))
Exemple #2
0
def add_customer():
    """Adds a new customer"""
    security.authorize(request)

    data = request.get_json()
    if data is None:
        raise InvalidUsage('Invalid data')

    check_customer_input(data)

    has_contract_end_date = 'contractEndDate' in data and data[
        'contractEndDate']
    contract_end_date = data[
        'contractEndDate'] if has_contract_end_date else None
    customer = Customer(id=uuid4(),
                        name=data['name'],
                        address=data['address'] if 'address' in data else '',
                        contract_end_date=contract_end_date,
                        applications=[Application.query.get(id) for id in data['applications']] \
                                     if 'applications' in data else [],
                        active=data['active'])
    db.session.add(customer)
    db.session.commit()

    return ('', 204)
Exemple #3
0
 def test_customer_creation(self):
     """
     Test customer creation.
     """
     customer = Customer('John', 20, 'UAH')
     assert customer.name == 'John'
     assert customer.discount == 20
     assert customer.currency == 'UAH'
Exemple #4
0
 def test_customer_creation_exception(self):
     """
     Test customer creation raises exception when entered discount  is not between 0 and 100.
     """
     try:
         customer = Customer('John', 105, 'UAH')
         self.assertFail()
     except Exception as inst:
         self.assertEqual(str(inst),
                          'Discount should be between 0 and 100.')
Exemple #5
0
 def test_check_creation(self):
     """
     Test check creation.
     """
     customer = Customer('Lili', 10, 'EUR')
     product = Product('Chocolate', 50, 100, 15)
     buy = Buy(customer, product.id, 1)
     check = Check.print_check(buy.id, customer.currency)
     self.assertEqual(
         check,
         """1 Chocolate purchased for 3.00EUR\nDiscount amount: 0.33EUR""")
Exemple #6
0
 def add_customer():
     """
     Add new customer.
     """
     name = input("\nCustomer name:\n")
     discount = input("\nCustomer discount:\n")
     currency = input("\nCustomer currency:\n")
     try:
         customer = Customer(name, discount, currency)
         bcolors.print_success(
             '{} was successfully added to customer list!'.format(
                 customer.name))
     except ValueError as e:
         bcolors.print_fail(str(e))
 def post(self):
     body = request.get_json()
     name = body.get("name")
     address = body.get("address")
     if name and address:
         newCustomer = Customer(name, address)
         db.session.add(newCustomer)
         db.session.commit()
         return serializeCustomer(newCustomer)
     return {
         "response": {
             "ok": False,
             "Error": "Something went wrong with sending the data"
         }
     }, 500
Exemple #8
0
 def test_buy_creation(self):
     """
     Test buy creation.
     """
     customer = Customer('Nancy', 20, 'EUR')
     product = Product('Chocolate', 50, 100, 15)
     buy = Buy(customer, product.id, 2)
     assert buy.total_weight == 30
     assert buy.total_amount == 160
     assert buy.discount_amount == 40
     self.assertEqual(
         buy.total_amount_in_currency,
         decimal.Decimal(5.33).quantize(decimal.Decimal('.01'),
                                        rounding=decimal.ROUND_DOWN))
     assert Buy.get_by_id(buy.id).customer.id == customer.id
     assert Buy.get_by_id(buy.id).product_id == product.id
def customer(g,s):
    all_customers = Customer.objects(gender = g, Status = s)
    top_10 = all_customers[0:10]
    return render_template('customer.html',all_customers=top_10)
Exemple #10
0
 def test_customer_get_by_id(self):
     """
     Test Customer method get_by_id.
     """
     customer = Customer('Mark', 10, 'EUR')
     assert Customer.get_by_id(customer.id).name == 'Mark'
Exemple #11
0
 def customer_list():
     """
     List all entered customers.
     """
     Customer.print_all()
def customer():
    all_customer = Customer.objects(gender=1, status=True).limit(10)
    return render_template('customer.html', all_customer=all_customer)
from models.customers import Customer
import mlab
from faker import Faker
from random import randint, choice

mlab.connect()

fake = Faker()

for i in range(50):
    print("saving service", i + 1, ".......")
    a = randint(1990, 2000)
    b = fake.name()
    new_customer = Customer(name=b,
                            yob=a,
                            gender=randint(0, 1),
                            height=randint(150, 190),
                            phone=fake.phone_number(),
                            address=fake.address(),
                            Status=choice([1, 0]),
                            email=b.replace(" ", "") + str(a % 100) +
                            "@gmail.com",
                            job=fake.job(),
                            company=fake.company())

    new_customer.save()