Beispiel #1
0
 def setUp(self):
     ExpenseTest.setUp(self)
     other_expense_type = ExpenseType(name="Other Type")
     other_expense_type.add()
     self.other_expense = Expense(concept="Other Expense",
                                  type_id=other_expense_type.id)
     self.other_expense.add()
Beispiel #2
0
 def setUp(self):
     Test.setUp(self)
     self.expense_type = ExpenseType(
         name="Test Type"
     )
     self.expense_type.add()
     self.expense = Expense(
         concept="Test Expense",
         type_id=self.expense_type.id
     )
     self.expense.add()
Beispiel #3
0
    def test_should_not_add_expense_given_invalid_expense_input_and_LUHP(self):
        self.login_user(self.dev_user)
        expense_input = dict(concept="Some Expense",
                             type_id=self.expense_type.id,
                             cost=10,
                             unit="pz",
                             quantity="")
        with self.client as client:
            client.post(url_for('expense.add'), data=expense_input)

        self.assertEqual(len(Expense.search_all('Some Expense')), 0)
Beispiel #4
0
class TestFilterExpensesByType(ExpenseTest):
    def setUp(self):
        ExpenseTest.setUp(self)
        other_expense_type = ExpenseType(name="Other Type")
        other_expense_type.add()
        self.other_expense = Expense(concept="Other Expense",
                                     type_id=other_expense_type.id)
        self.other_expense.add()

    def test_should_return_list_of_expenses_of_the_same_type_given_type_obj(
            self):
        all_expenses = Expense.query.all()
        expenses = filter_expenses_by_type(all_expenses, self.expense_type.id)

        self.assertEqual(expenses, [self.expense])

    def test_should_return_all_expenses_given_expense_type_id_is_0(self):
        all_expenses = Expense.query.all()
        expenses = filter_expenses_by_type(all_expenses, 0)

        self.assertEqual(expenses, all_expenses)
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
Beispiel #6
0
def add_expense(id):
    warehouse = Warehouse.query.get(id)
    expense_types = ExpenseType.query.all()
    if request.method == "POST":
        expense = Expense(concept=request.form["concept"],
                          type_id=request.form['type_id'],
                          cost=request.form['cost'],
                          unit=request.form['unit'],
                          quantity=request.form['quantity'])
        error = expense.request.add()
        if not error:
            warehouse.add_expense(expense)
            return redirect(url_for('warehouse.inventory', id=warehouse.id))
        flash(error)

    return render_template("expense/add.html",
                           expense_heads=expense_heads,
                           expense_types=expense_types,
                           form=request.form)
Beispiel #7
0
    def test_should_add_expense(self):
        expense = Expense(concept="Some Expense", type_id=self.expense_type.id)
        expense.add()

        self.assertIn(expense, self.db.session)
Beispiel #8
0
    def test_should_return_expense_given_valid_search_term(self):
        expenses = Expense.search_all(self.expense.concept)

        self.assertEqual(expenses, [self.expense])
Beispiel #9
0
    def test_should_return_all_expenses(self):
        expenses = Expense.get_all()

        self.assertEqual(expenses, [self.expense])
Beispiel #10
0
    def test_should_return_expense_given_valid_id(self):
        expense = Expense.get(self.expense.id)

        self.assertEqual(expense, self.expense)
    def test_should_add_expense_given_valid_expense(self):
        expense = Expense(concept="Valid Name", type_id=self.expense_type.id)
        expense.request.add()

        self.assertIn(expense, self.db.session)
Beispiel #12
0
    def test_should_not_delete_given_LUHNP(self):
        self.login_user(self.normal_user)
        with self.client as client:
            client.get(url_for('expense.delete', id=self.expense.id))

        self.assertTrue(Expense.get(self.expense.id))
Beispiel #13
0
    def test_should_delete_expense_given_LUHP(self):
        self.login_user(self.dev_user)
        with self.client as client:
            client.get(url_for('expense.delete', id=self.expense.id))

        self.assertFalse(Expense.get(self.expense.id))