Exemplo n.º 1
0
    def test_should_add_customer(self):
        customer = Customer(customer_name="Test Customer",
                            address="Test dirección",
                            rfc="Opcional RFC")
        customer.add()

        self.assertIn(customer, self.db.session)
Exemplo n.º 2
0
class CustomerTest(Test):
    def setUp(self):
        Test.setUp(self)
        self.customer = Customer(customer_name="Test Name",
                                 address="Test Address",
                                 rfc="Test RFC")
        self.customer.add()
Exemplo n.º 3
0
def customers():
    customers = Customer.get_all()
    if request.method == "POST":
        customers = Customer.search_all(request.form["search_term"])

    return render_template('customer/customers.html',
                           customer_heads=customer_heads,
                           customers=customers)
Exemplo n.º 4
0
 def setUp(self):
     CustomerTest.setUp(self)
     self.customer2 = Customer(
         customer_name="Name Two",
         address="Address Two",
         rfc="RFC Two"
     )
     self.customer2.add()
Exemplo n.º 5
0
 def setUp(self):
     ReceiptTest.setUp(self)
     customer2 = Customer(
         customer_name="Name Two",
         address="Address Two",
         rfc=""
     )
     customer2.add()
     self.create_test_users()
Exemplo n.º 6
0
 def setUp(self):
     Test.setUp(self)
     self.customer = Customer(customer_name="Test Name",
                              address="Test Address",
                              rfc="Test RFC")
     self.customer.add()
     self.product_1 = Product(warehouse_id=1, code="Code 1", price=10)
     self.product_1.add()
     self.product_2 = Product(warehouse_id=1, code="Code 2", price=10)
     self.product_2.add()
     self.receipt = Receipt(customer_id=self.customer.id)
     self.receipt.add()
Exemplo n.º 7
0
    def test_should_not_return_error_given_valid_phone(self):
        customer = Customer(customer_name="Test Name",
                            address="Test Address",
                            phone="+442 303 2121")
        error = customer.validation.validate_phone()

        self.assertEqual(error, None)
Exemplo n.º 8
0
    def test_should_not_return_error_given_unique_name(self):
        customer = Customer(customer_name="Unique Name",
                            address="Test Address",
                            rfc="TESTRFC 123")
        error = customer.validation.validate_unique_value("customer_name")

        self.assertEqual(error, None)
Exemplo n.º 9
0
    def test_should_return_error_given_empty_name(self):
        customer = Customer(customer_name="",
                            address="Test Address",
                            rfc="TESTRFC 123")
        error = customer.validation.validate_empty_values()

        self.assertNotEqual(error, None)
Exemplo n.º 10
0
    def test_should_not_return_error_given_empty_rfc(self):
        customer = Customer(customer_name="Test Name",
                            address="Test Address",
                            rfc="")
        error = customer.validation.validate_empty_values()

        self.assertEqual(error, None)
Exemplo n.º 11
0
    def test_should_return_error_given_repeated_rfc(self):
        customer = Customer(customer_name="Test Name",
                            address="Test Address",
                            rfc="Test RFC")
        error = customer.validation.validate_unique_values()

        self.assertNotEqual(error, None)
Exemplo n.º 12
0
    def test_should_return_error_given_invalid_phone(self):
        customer = Customer(customer_name="Test Name",
                            address="Test Address",
                            phone="invalid phone")
        error = customer.validation.validate_phone()

        self.assertNotEqual(error, None)
Exemplo n.º 13
0
    def test_should_not_return_error_given_valid_customer(self):
        customer = Customer(customer_name="Test Name",
                            address="Test Address",
                            rfc="Unique RFC")
        error = customer.validation.validate()

        self.assertEqual(error, None)
Exemplo n.º 14
0
    def test_should_add_customer_given_valid_customer(self):
        customer = Customer(
            customer_name="Valid Name",
            address="Valid Address",
            rfc="Valid RFC"
        )
        customer.request.add()

        self.assertIn(customer, self.db.session)
Exemplo n.º 15
0
    def test_should_not_return_error_given_two_customers_with_empty_rfc(self):
        self.customer.rfc = ""
        self.customer.update()
        customer = Customer(customer_name="Valid Name",
                            address="Valid Address",
                            rfc="")
        error = customer.validation.validate_unique_values()

        self.assertEqual(error, None)
Exemplo n.º 16
0
    def test_should_add_customer_given_valid_customer_data_and_LUHP(self):
        self.login_user(self.admin_user)
        customer_data = dict(customer_name="Valid Name",
                             address="Valid Address",
                             phone="+123 456 7890",
                             rfc="")
        with self.client as client:
            client.post(url_for('customer.add'), data=customer_data)

        self.assertEqual(len(Customer.get_all()), 2)
Exemplo n.º 17
0
    def test_should_not_return_error_given_two_customers_with_empty_name(self):
        self.customer.customer_name = ""
        self.customer.update()
        customer = Customer(customer_name="",
                            address="Valid Address",
                            rfc="Test RFC")
        error = customer.validation.validate_optional_unique_value(
            'customer_name')

        self.assertEqual(error, None)
Exemplo n.º 18
0
def update(id):
    customer = Customer.get(id)
    if request.method == "POST":
        update_obj_attrs(customer, customer_heads)
        error = customer.request.update()
        if not error:
            return redirect(url_for('customer.customers'))
        flash(error)

    return render_template('customer/update.html',
                           customer_heads=customer_heads,
                           customer=customer)
Exemplo n.º 19
0
def receipts(id):
    selected_date_str = ""
    customer = Customer.get(id)
    receipts = customer.receipts
    if request.method == "POST":
        selected_date_str = request.form["selected_date"]
        selected_date = datetime.strptime(selected_date_str, "%Y-%m-%d")
        receipts = filter_receipts_by_date(receipts, selected_date)

    return render_template('customer/receipts.html',
                           receipt_heads=receipt_heads,
                           selected_date=selected_date_str,
                           customer=customer,
                           receipts=receipts)
Exemplo n.º 20
0
class TestUpdate(CustomerTest):

    def setUp(self):
        CustomerTest.setUp(self)
        self.customer2 = Customer(
            customer_name="Name Two",
            address="Address Two",
            rfc="RFC Two"
        )
        self.customer2.add()

    def test_should_update_customer_given_valid_change(self):
        self.customer.customer_name = "New Name"
        self.customer.request.update()
        self.db.session.rollback()

        self.assertEqual(self.customer.customer_name, "New Name")

    def test_should_not_update_customer_given_invalid_change(self):
        self.customer2.rfc = "Test RFC"
        self.customer2.request.update()
        self.db.session.rollback()

        self.assertNotEqual(self.customer2.rfc, "Test RFC")
Exemplo n.º 21
0
def get_autocomplete_data(group, attribute):
    groups = dict(
        users=User.get_all(),
        products=Product.get_all(),
        customers = Customer.get_all(),
        expenses=Expense.get_all(),
        warehouses=Warehouse.get_all()
    )
    data = []
    for obj in groups[group]:
        value = getattr(obj, attribute)
        if value not in set(data):
            data.append(value)
    
    return data
Exemplo n.º 22
0
def add():
    form = get_form(customer_heads)
    if request.method == 'POST':
        customer = Customer(customer_name=request.form['customer_name'],
                            address=request.form['address'],
                            phone=request.form['phone'],
                            rfc=request.form['rfc'])
        error = customer.request.add()
        if not error:
            return redirect(url_for('customer.customers'))
        flash(error)

    return render_template('customer/add.html',
                           customer_heads=customer_heads,
                           form=form)
Exemplo n.º 23
0
 def test_should_add_receipt_and_new_customer_given_valid_customer_data_and_LUHP(self):
     self.login_user(self.admin_user)
     customer_data = dict(
         customer_name="Valid New Name",
         address="Valid Address",
         phone="+123 456 7890"
     )
     prev_receipts = Receipt.get_all()
     with self.client as client:
         client.post(
             url_for('receipt.add'),
             data=customer_data
         )
     
     self.assertNotEqual(len(Receipt.get_all()), len(prev_receipts))
     self.assertEqual(len(Customer.search_all('Valid New Name')), 1)
Exemplo n.º 24
0
def search_bar():
    search_term = request.form['search_term']
    try:
        customer = Customer.search_all(search_term)[0]
    except IndexError:
        customer = None
    if customer:
        return redirect(
            url_for("customer.update", id=customer.id)
        )
    user = User.search(search_term)
    if user:
        return redirect(
            url_for("user.profile", id=user.id)
        )
    product = Product.search(search_term)
    if product:
        return redirect(
            url_for("product.update", id=product.id)
        )

    return redirect(
        request.referrer
    )
Exemplo n.º 25
0
def delete(id):
    customer = Customer.get(id)
    customer.delete()

    return redirect(url_for('customer.customers'))
Exemplo n.º 26
0
    def test_should_return_customer_given_valid_id(self):
        customer = Customer.get(self.customer.id)

        self.assertEqual(customer, self.customer)
Exemplo n.º 27
0
    def test_should_return_none_given_invalid_id(self):
        customer = Customer.get(2)

        self.assertEqual(customer, None)
Exemplo n.º 28
0
    def test_should_return_list_of_all_customers(self):
        customers = Customer.get_all()

        self.assertEqual(customers, [self.customer])
Exemplo n.º 29
0
    def test_should_return_list_of_customers_given_valid_rfc(self):
        customers = Customer.search_all(self.customer.rfc)

        self.assertEqual(customers, [self.customer])
Exemplo n.º 30
0
    def test_should_return_empty_list_given_invalid_search_term(self):
        customer = Customer.search_all("invalid search term")

        self.assertEqual(customer, [])