def test_product_customer_update_info(client, web2py):
    """
        Test as JSON
        Is the attendance info ajaj backend working?
    """
    populate_workshops_with_activity(web2py)
    populate_customers(web2py, 1)
    web2py.db.workshops_products_customers.insert(workshops_products_id=1,
                                                  auth_customer_id=1001)
    web2py.db.commit()

    url = '/events/ticket_customer_update_info.json'
    data = dict(id='1', WorkshopInfo='on')
    client.post(url, data=data)
    assert client.status == 200
    assert 'success' in client.text

    assert web2py.db.workshops_products_customers(1).WorkshopInfo == True

    # unset info and payment confirmation.
    url = '/events/ticket_customer_update_info.json'
    data = dict(id='1')
    client.post(url, data=data)
    assert client.status == 200
    assert 'success' in client.text

    assert web2py.db.workshops_products_customers(1).WorkshopInfo == False
def test_list_invoices_status_filter(client, web2py):
    """
        Test if the status filter for list_invoices works
    """
    url = '/finance/invoices'
    client.get(url)
    assert client.status == 200

    populate_customers(web2py, 10)
    populate_invoices(web2py)

    # change invoice 1 to paid and set a recognizable description so we can check the list
    description = 'Grapefruit'
    invoice = web2py.db.invoices(1)
    invoice.Description = description
    invoice.Status = 'draft'
    invoice.update_record()

    web2py.db.commit()

    post_url = '/finance/invoices'
    data = {'status': 'draft'}

    client.post(post_url, data=data)
    assert client.status == 200

    assert description in client.text
예제 #3
0
def test_invoice_paid(client, web2py):
    """
        Is a payment added when an invoice is paid?
    """
    url = '/default/user/login'
    client.get(url)
    assert client.status == 200

    populate_customers(web2py, 1)
    populate_invoices(web2py)
    populate_invoices_items(web2py)

    amounts = web2py.db.invoices_amounts(1)
    price = str(amounts.TotalPriceVAT)
    mollie_id = 'tr_test'
    date = '2014-01-01'

    url = '/mollie/test_webhook_invoice_paid?iID=1&payment_amount=' + price + '&payment_date=' + date + '&mollie_payment_id=' + mollie_id
    client.get(url)
    assert client.status == 200

    payment = web2py.db.invoices_payments(1)

    print(payment)

    assert payment.Amount == amounts.TotalPriceVAT
    assert payment.mollie_payment_id == mollie_id
    assert str(payment.PaymentDate) == date
def test_invoice_payment_add_set_status_paid(client, web2py):
    """
        Set status to paid after adding a payment >= invoice amount
    """
    url = '/finance/invoices'
    client.get(url)
    assert client.status == 200

    populate_customers(web2py, 10)
    populate_invoices(web2py)

    amounts = web2py.db.invoices_amounts(1)
    amounts.TotalPrice = 20
    amounts.VAT = 2
    amounts.TotalPriceVAT = 22
    amounts.Paid = 0
    amounts.Balance = 22
    amounts.update_record()

    web2py.db.commit()

    url = '/invoices/payment_add?iID=1'
    client.get(url)
    assert client.status == 200

    data = {
        'invoices_id': 1,
        'Amount': 20,
        'PaymentDate': '2014-01-01',
        'payment_methods_id': 3,
        'Note': 'first payment using bananas'
    }

    client.post(url, data=data)
    assert client.status == 200

    client.get('/invoices/invoice_payments?iID=1')
    assert client.status == 200
    assert data['Note'] in client.text

    invoice = web2py.db.invoices(1)
    assert invoice.Status == 'sent'

    # go back to the page where we want to submit payments
    client.get(url)
    assert client.status == 200

    data = {
        'invoices_id': 1,
        'Amount': 2,
        'PaymentDate': '2014-01-02',
        'payment_methods_id': 3,
        'Note': 'second payment using bananas'
    }

    client.post(url, data=data)
    assert client.status == 200

    invoice = web2py.db.invoices(1)
    assert invoice.Status == 'paid'
def test_customer_bankaccount_delete(client, web2py):
    """
        Is the delete permission for payment info under customers working?
    """
    # get random url to init payment methods in db
    url = '/default/user/login'
    client.get(url)
    assert client.status == 200

    setup_permission_tests(web2py)
    populate_customers(web2py, 1)
    web2py.db.customers_payment_info.insert(
        auth_customer_id   = 1001,
        AccountNumber      ='123456',
        payment_methods_id = 1)

    web2py.auth.add_permission(200, 'read', 'customers_payment_info', 0)
    web2py.auth.add_permission(200, 'read', 'customers_payments', 0)
    web2py.db.commit()

    url = '/customers/bankaccount?cuID=1001'
    client.get(url)
    assert client.status == 200

    assert not 'fa-times' in client.text

    # grant permission and check again
    web2py.auth.add_permission(200, 'delete', 'customers_payment_info', 0)
    web2py.db.commit()

    client.get(url)
    assert client.status == 200

    assert 'fa-times' in client.text
def test_customer_notes_delete(client, web2py):
    """
        Is the delete permission for notes under customers working?
    """
    # get random url to populate db.auth_user with admin
    client.get('/default/user/login')
    assert client.status == 200

    setup_permission_tests(web2py)
    populate_customers(web2py, 1)
    web2py.db.customers_notes.insert(auth_customer_id=1001,
                                     auth_user_id=1,
                                     BackofficeNote=True,
                                     NoteDate='2014-01-01',
                                     NoteTime="12:00",
                                     Note='Strawberry')

    web2py.auth.add_permission(200, 'read', 'customers_notes', 0)
    web2py.auth.add_permission(200, 'read', 'customers_notes_backoffice', 0)
    web2py.db.commit()

    url = '/customers/notes?cuID=1001'
    client.get(url)
    assert client.status == 200

    assert not 'fa-times' in client.text

    # grant permission and check again
    web2py.auth.add_permission(200, 'delete', 'customers_notes', 0)
    web2py.db.commit()

    client.get(url)
    assert client.status == 200

    assert 'Delete</a>' in client.text
def test_invoice_item_delete(client, web2py):
    """
        Can we delete an item from an invoice?
    """
    populate_customers(web2py, 3)

    url = '/customers/invoices?cuID=1001'
    client.get(url)
    assert client.status == 200

    populate_invoices(web2py)
    populate_invoices_items(web2py)

    # Is the confirmation page showing?
    url = '/invoices/item_delete_confirm?iID=1&iiID=1'
    client.get(url)
    assert client.status == 200

    url = '/invoices/item_delete?iID=1&iiID=1'
    client.get(url)
    assert client.status == 200

    assert web2py.db.invoices_items(1) is None

    # check amounts
    amounts = web2py.db.invoices_amounts(1)
    assert amounts.TotalPriceVAT == 0
def test_customer_documents_delete(client, web2py):
    """
        Is the delete permission for documents under customers working?
    """
    setup_permission_tests(web2py)
    populate_customers(web2py, 1)
    web2py.db.customers_documents.insert(auth_customer_id=1001,
                                         Description='test',
                                         DocumentFile='file.txt')

    web2py.auth.add_permission(200, 'read', 'customers_documents', 0)
    web2py.db.commit()

    url = '/customers/documents?cuID=1001'
    client.get(url)
    assert client.status == 200

    assert not 'fa-times' in client.text

    # grant permission and check again
    web2py.auth.add_permission(200, 'delete', 'customers_documents', 0)
    web2py.db.commit()

    client.get(url)
    assert client.status == 200

    assert 'fa-times' in client.text
def test_reports_trialclasses(client, web2py):
    """
        Is the page listing drop in classes for a month working?
    """
    populate_customers(web2py)
    populate_classes(web2py, with_otc=True)

    web2py.db.classes_attendance.insert(
        classes_id=1,
        ClassDate='2014-01-06',
        auth_customer_id=1001,
        AttendanceType=1,
    )

    web2py.db.commit()

    url = '/reports/trialclasses?year=2014&month=1'
    client.get(url)
    assert client.status == 200

    location = web2py.db.school_locations(2).Name.split(' ')[0]
    assert location in client.text

    classtype = web2py.db.school_classtypes(2).Name.split(' ')[0]
    assert classtype in client.text
예제 #10
0
def test_customers_contact_info(client, web2py):
    """
        Check if the customers_info update permission works
    """
    setup_permission_tests(web2py)
    populate_customers(web2py, 1)

    url = '/customers/edit/1001'
    client.get(url)
    assert client.status == 200
    assert "Insufficient privileges" in client.text

    gid = 2

    web2py.auth.add_permission(200, 'read', 'auth_user', 0)
    web2py.auth.add_permission(200, 'update', 'auth_user', 0)
    web2py.db.commit()

    str_check = '<label>Telephone</label>'
    client.get(url)
    assert client.status == 200
    assert not str_check in client.text

    web2py.auth.add_permission(200, 'update', 'customers_contact', 0)
    web2py.db.commit()
    client.get(url)
    assert client.status == 200
    assert str_check in client.text
def test_invoice_add_from_customer(client, web2py):
    """
        Can we add an invoice from a customer?
    """
    populate_customers(web2py, 1)

    url = '/customers/invoices?cuID=1001'
    client.get(url)
    assert client.status == 200

    data = {'invoices_groups_id': 100, 'Description': 'one crate of bananas'}
    client.post(url, data=data)
    assert client.status == 200

    # verify entry of data
    assert data['Description'] in client.text
    assert web2py.db(web2py.db.invoices).count() == 1

    # check setting of enddate and InvoiceID
    invoice = web2py.db.invoices(1)
    today = datetime.date.today()
    delta = datetime.timedelta(days=web2py.db.invoices_groups(100).DueDays)
    due = today + delta

    # verify redirection
    assert invoice.InvoiceID in client.text

    assert invoice.DateCreated == today
    assert invoice.DateDue == due

    assert invoice.InvoiceID == 'INV' + str(today.year) + '1'
def test_osmail_render_sys_notification_order_created(client, web2py):
    """
    Is the order created mail rendered correctly?
    """
    url = '/default/user/login'
    client.get(url)
    assert client.status == 200

    populate_customers(web2py, 10)
    populate_customers_orders(web2py)
    populate_customers_orders_items(web2py)

    url = '/test_os_mail/test_osmail_render_sys_notification?sys_notification=order_created&customers_orders_id=1'
    client.get(url)
    assert client.status == 200

    # Check title
    assert "New order" in client.text

    # Check content
    oi = web2py.db.customers_orders_items(1)
    assert oi.ProductName in client.text
    assert oi.Description in client.text
    assert unicode(oi.TotalPriceVAT).encode('utf8') in client.text

    # Check comments / customer note
    order = web2py.db.customers_orders(1)
    assert order.CustomerNote in client.text
def test_invoice_item_edit(client, web2py):
    """
        Can we edit an item in an invoice?
    """
    populate_customers(web2py, 3)

    url = '/customers/invoices?cuID=1001'
    client.get(url)
    assert client.status == 200

    populate_invoices(web2py)
    populate_invoices_items(web2py)

    url = '/invoices/item_edit?iID=1&iiID=1'
    client.get(url)
    assert client.status == 200

    data = {
        'id'          : 1,
        'ProductName' : 'Cherries'
    }
    client.post(url, data=data)
    assert client.status == 200

    assert data['ProductName'] in client.text
예제 #14
0
def test_customer_direct_debit_extra_delete(client, web2py):
    """
        Is the delete permission for alternative under customers working?
    """
    setup_permission_tests(web2py)
    populate_customers(web2py, 1)
    web2py.db.alternativepayments.insert(auth_customer_id=1001,
                                         PaymentYear=2014,
                                         PaymentMonth=1,
                                         Amount=100,
                                         Description='test')

    web2py.auth.add_permission(200, 'read', 'customers_payment_info', 0)
    web2py.auth.add_permission(200, 'read', 'alternativepayments', 0)
    web2py.db.commit()

    url = '/customers/direct_debit_extra?cuID=1001'
    client.get(url)
    assert client.status == 200

    assert not 'fa-times' in client.text

    # grant permission and check again
    web2py.auth.add_permission(200, 'delete', 'alternativepayments', 0)
    web2py.db.commit()

    client.get(url)
    assert client.status == 200

    assert 'fa-times' in client.text
예제 #15
0
def test_ticket_sell_to_customer_create_invoice_and_cancel_orders_when_sold_out(client, web2py):
    """
        Test if we can sell a ticket to a customer and if an invoice is created
    """
    populate_workshops_with_activity(web2py)
    populate_customers(web2py, 1)
    populate_customers_orders(web2py)
    populate_customers_orders_items(web2py, workshops_products=True)


    url = '/events/ticket_sell_to_customer?cuID=1001&wsID=1&wspID=1'
    client.get(url)
    assert client.status == 200

    assert web2py.db(web2py.db.workshops_products_customers).count() == 1

    assert web2py.db(web2py.db.invoices).count() == 1

    invoice = web2py.db.invoices(1)
    assert invoice.invoices_groups_id == 100

    ii_wsp = web2py.db.invoices_items_workshops_products_customers(1)
    assert ii_wsp.workshops_products_customers_id == 1

    # check invoice amount
    price   = web2py.db.workshops_products(1).Price
    amounts = web2py.db.invoices_amounts(1)
    assert amounts.TotalPriceVAT == price

    # check if all orders get cancelled
    assert web2py.db(web2py.db.customers_orders.Status == 'cancelled').count() > 0

    # Check that a mail is sent (or at least it tried)
    assert web2py.db(web2py.db.messages).count() == 1
    assert web2py.db(web2py.db.customers_messages).count() == 1
def test_invoice_item_add(client, web2py):
    """
        Can we add an item to an invoice?
    """
    populate_customers(web2py, 3)

    url = '/customers/invoices?cuID=1001'
    client.get(url)
    assert client.status == 200

    populate_invoices(web2py)

    url = '/invoices/list_items?iID=1'
    client.get(url)
    assert client.status == 200

    data = {
        'ProductName': 'Fruits',
        'Description': 'Mangoes',
        'Quantity': 10,
        'Price': 1234,
        'tax_rates_id': 1,
    }
    client.post(url, data=data)
    assert client.status == 200

    # Check DB
    assert web2py.db(web2py.db.invoices_items).count() == 1

    # Check updated listing
    assert data['Description'] in client.text

    # Check sorting & prices in item
    item = web2py.db.invoices_items(1)
    # Sorting has no default value from the db, so if we get a 1, it's generating the sorting numbers correctly
    assert item.Sorting == 1

    # calculate total incl. vat
    TotalPriceVAT = data['Quantity'] * data['Price']
    assert item.TotalPriceVAT == TotalPriceVAT

    # calculate vat
    tax_rate = web2py.db.tax_rates(data['tax_rates_id'])
    percentage = tax_rate.Percentage / 100
    VAT = round(TotalPriceVAT - (TotalPriceVAT / (1 + percentage)), 2)
    assert item.VAT == VAT

    # calculate total without vat
    TotalPrice = TotalPriceVAT - VAT
    assert item.TotalPrice == TotalPrice

    # Check amounts in Invoices_amounts
    amounts = web2py.db.invoices_amounts(1)
    assert amounts.TotalPrice == TotalPrice
    assert amounts.VAT == VAT
    assert amounts.TotalPriceVAT == TotalPriceVAT
예제 #17
0
def test_ticket_sell_to_customer_waitinglist(client, web2py):
    """
        Test if we can sell a ticket to a customer
    """
    populate_workshops_with_activity(web2py)
    populate_customers(web2py, 1)

    url = '/events/ticket_sell_to_customer?cuID=1001&wsID=1&wspID=1&waiting=True'
    client.get(url)
    assert client.status == 200

    assert web2py.db.workshops_products_customers(1).Waitinglist == True
def test_customers_inactive_delete(client, web2py):
    """
        Are customers without activity after a given date actually deleted?
    """
    populate_customers(web2py, created_on=datetime.date(2010, 1, 1))

    url = '/reports/customers_inactive_delete'
    data = {'date': datetime.date.today()}
    client.post(url, data=data)
    assert client.status == 200

    count = web2py.db(web2py.db.auth_user.id > 1).count()
    assert count == 0  # Only admin user remaining
    assert 'Deleted 10 customers' in client.text
def test_customers_inactive_dont_list_created_after_date(client, web2py):
    """
        Can we list customers without activity after a given date?
    """
    populate_customers(web2py, created_on=datetime.date(2010, 1, 1))

    url = '/reports/customers_inactive'
    client.get(url)
    assert client.status == 200

    data = {'date': datetime.date(2009, 1, 1)}
    client.post(url, data=data)
    assert client.status == 200

    assert web2py.db.auth_user(1001).first_name not in client.text
예제 #20
0
def test_ticket_list_customers_fullWS(client, web2py):
    """
        Test listing of full workshop customers for a ticket
    """
    populate_workshops_with_activity(web2py)
    populate_customers(web2py, 1)
    web2py.db.workshops_products_customers.insert(workshops_products_id=1,
                                                  auth_customer_id=1001)
    web2py.db.commit()

    url = '/events/tickets_list_customers?wsID=1&wspID=1'
    client.get(url)
    assert client.status == 200

    assert 'Full event' in client.text
def test_teacher_payments(client, web2py):
    """
         Are teacher payment invoices listed correctly?
    """
    url = '/default/user/login'
    client.get(url)
    assert client.status == 200

    populate_customers(web2py)
    populate_invoices(web2py, teacher_fixed_price_invoices=True)

    url = '/finance/teacher_payments_invoices'
    client.get(url)
    assert client.status == 200

    assert 'INV1001' in client.text
예제 #22
0
def test_webhook_invoice_refund(client, web2py):
    """
        Is a payment added when an invoice is paid with chargeback(s)?
    """
    url = '/default/user/login'
    client.get(url)
    assert client.status == 200

    populate_customers(web2py, 1)
    populate_invoices(web2py)
    populate_invoices_items(web2py)

    invoice = web2py.db.invoices(1)
    invoice.Status = 'paid'
    invoice.update_record()
    web2py.db.commit()

    amounts = web2py.db.invoices_amounts(1)
    price = str(amounts.TotalPriceVAT * -1)
    mollie_id = 'tr_test'
    refund_id = 're_test'
    date = '2014-01-01'

    url = '/mollie/test_webhook_invoice_refund?' + \
          'iID=1' +\
          '&refund_amount=' + price + \
          '&refund_date=' + date + \
          '&mollie_payment_id=' + mollie_id + \
          '&refund_id=' + refund_id + \
          '&refund_details=refund'

    client.get(url)
    assert client.status == 200

    payment = web2py.db.invoices_payments(1)

    assert payment.Amount == amounts.TotalPriceVAT * -1
    assert payment.mollie_payment_id == mollie_id
    assert payment.mollie_refund_id == refund_id
    assert str(payment.PaymentDate) == date
    assert payment.Note == 'refund'

    # Check status changes back to 'sent'
    invoice = web2py.db.invoices(1)
    assert invoice.Status == 'sent'
def test_employee_delete(client, web2py):
    """
        Can we remove the employee status from a customer?
    """
    populate_customers(web2py)

    row = web2py.db.auth_user(1001)
    row.employee = True
    row.update_record()

    web2py.db.commit()

    url = '/school_properties/employee_delete?uID=1001'
    client.get(url)
    assert client.status == 200

    row = web2py.db.auth_user(1001)
    assert row.employee == False
def test_teacher_delete(client, web2py):
    """
        Can we remove the teacher status from a customer?
    """
    populate_customers(web2py)

    row = web2py.db.auth_user(1001)
    row.teacher = True
    row.update_record()

    web2py.db.commit()

    url = '/teachers/delete?uID=1001'
    client.get(url)
    assert client.status == 200

    row = web2py.db.auth_user(1001)
    assert row.teacher == False
def test_reports_postcodes(client, web2py):
    """
        Is the stats page counting correct?
    """
    populate_customers(web2py)
    populate_postcode_groups(web2py)

    url = '/reports/postcodes'
    client.get(url)
    assert client.status == 200

    # check that count of groups postcodes is in the page data
    group = web2py.db.postcode_groups(1)
    query = (web2py.db.auth_user.postcode_asint >= group.PostcodeStart_AsInt) & \
            (web2py.db.auth_user.postcode_asint <= group.PostcodeEnd_AsInt)
    count = web2py.db(query).count()

    assert '<td>' + str(count) + '</td>' in client.text
def test_invoice_edit(client, web2py):
    """
        Can we edit an invoice?
    """
    populate_customers(web2py, 3)

    url = '/customers/invoices?cuID=1001'
    client.get(url)
    assert client.status == 200

    populate_invoices(web2py)

    data = {'Description': 'Mangoes'}

    client.post(url, data=data)
    assert client.status == 200

    assert data['Description'] in client.text
def test_customers_inactive_dont_list_with_invoices(client, web2py):
    """
        Customers with invoice after given date
    """
    from populate_os_tables import populate_invoices

    url = '/reports/customers_inactive'
    client.get(url)
    assert client.status == 200

    populate_customers(web2py, created_on=datetime.date(2012, 1, 1))
    populate_invoices(web2py)

    data = {'date': datetime.date(2014, 1, 1)}
    client.post(url, data=data)
    assert client.status == 200

    assert web2py.db.auth_user(1001).first_name not in client.text
def test_invoice_show_duplicate_button(client, web2py):
    """
    Does the Button show and doesn't when it shouldn't
    """
    populate_customers(web2py, 3)

    url = '/customers/invoices?cuID=1001'
    client.get(url)
    assert client.status == 200

    populate_invoices(web2py)

    populate_invoices_items(web2py)

    url = '/invoices/edit?iID=1'
    client.get(url)
    assert client.status == 200

    assert 'Duplicate' in client.text
def test_invoice_dont_show_duplicate_button_teacher_payment(client, web2py):
    """
    DOes the button not show when teacher payment?
    """
    populate_customers(web2py, 3)

    url = '/customers/invoices?cuID=1001'
    client.get(url)
    assert client.status == 200

    populate_invoices(web2py, teacher_fixed_price_invoices=True)

    populate_invoices_items(web2py)

    url = '/invoices/edit?iID=1'
    client.get(url)
    assert client.status == 200

    assert 'Duplicate' not in client.text
def test_invoice_dont_show_duplicate_button_employee_claim(client, web2py):
    """
    Does the Button not show when it is an employee Claim?
    """
    populate_customers(web2py, 3)

    url = '/customers/invoices?cuID=1001'
    client.get(url)
    assert client.status == 200

    populate_invoices(web2py, employee_claim=True)

    populate_invoices_items(web2py)

    url = '/invoices/edit?iID=1'
    client.get(url)
    assert client.status == 200

    assert 'Duplicate' not in client.text