def test_reports_subscriptions_overview_customers_location_filter(
        client, web2py):
    """
        Does the filter actually ... filter?
    """
    url = '/default/user/login'
    client.get(url)
    assert client.status == 200

    populate_customers_with_subscriptions(web2py, 10)

    web2py.db.sys_properties.insert(Property='Customer_ShowLocation',
                                    PropertyValue='on')

    web2py.db.commit()

    url = '/reports/subscriptions_overview_customers?school_locations_id=2&ssuID=1&year=2014&month=1'
    client.get(url)
    assert client.status == 200

    customer_2 = web2py.db.auth_user(1002)
    assert customer_2.display_name not in client.text

    customer_7 = web2py.db.auth_user(1007)
    assert customer_7.display_name in client.text
Ejemplo n.º 2
0
def test_customer_subscription_delete(client, web2py):
    """
        Is the delete permission for a customer subscription 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_with_subscriptions(web2py, 2)

    web2py.auth.add_permission(200, 'read', 'customers_subscriptions', 0)

    web2py.db.commit()

    url = '/customers/subscriptions?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_subscriptions', 0)
    web2py.db.commit()

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

    assert 'fa-times' in client.text
Ejemplo n.º 3
0
def test_subscriptions_display_credits_unlimited(client, web2py):
    """
        Is the list of subscriptions showing?
    """
    # get the url, for some reason the customers_subscriptions table is empty if not when asserting
    url = '/profile/subscriptions'
    client.get(url)
    assert client.status == 200

    setup_profile_tests(web2py)

    populate_customers_with_subscriptions(web2py, credits=True)

    ssu = web2py.db.school_subscriptions(1)
    ssu.Unlimited = True
    ssu.update_record()

    cs = web2py.db.customers_subscriptions(1)
    cs.auth_customer_id = 300
    cs.update_record()

    web2py.db.commit()

    url = '/profile/subscriptions'
    client.get(url)
    assert client.status == 200

    ss = web2py.db.school_subscriptions(1)
    assert ss.Name in client.text
    assert str(cs.Startdate) in client.text
    assert 'Unlimited' in client.text  # check if number of credits is displayed
def test_create_monthly_invoices_inv_date_first_of_month(client, web2py):
    """
        Can we create subscription invoices for a month?
    """
    # Get random url to initialize OpenStudio environment
    url = '/default/user/login'

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

    populate_customers_with_subscriptions(web2py, 10)


    url = '/test_automation_customer_subscriptions/' + \
          'test_create_invoices' + \
          '?month=1&year=2014&description=Subscription_Jan&invoice_date=first_of_month'
    client.get(url)
    assert client.status == 200

    # print web2py.db().select(web2py.db.invoices_items.ALL)
    # print web2py.db().select(web2py.db.invoices_items_customers_subscriptions.ALL)

    # check the created invoices
    ig_100 = web2py.db.invoices_groups(100)
    invoice = web2py.db.invoices(1)
    assert invoice.DateCreated == datetime.date(2014, 1, 1)
Ejemplo n.º 5
0
def test_subscription_unlimited_credits_profile_home(client, web2py):
    """
        Check if subscription credits are displayed on the home page of a profile
    """
    setup_profile_tests(web2py)

    # get the url, for some reason the customers_subscriptions table is empty if not when asserting
    url = '/profile/index'
    client.get(url)
    assert client.status == 200

    populate_customers_with_subscriptions(web2py, credits=True)

    ssu = web2py.db.school_subscriptions(1)
    ssu.Unlimited = True
    ssu.update_record()

    cs = web2py.db.customers_subscriptions(1)
    cs.auth_customer_id = 300
    cs.update_record()

    web2py.db.commit()

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

    assert 'Unlimited' in client.text  # check if number of credits is displayed
Ejemplo n.º 6
0
def test_add_batch_invoices_with_zero_lines(client, web2py):
    """
        Check whether we can add a default batch and items are generated
        propery and check whether lines with amount 0 are included
    """
    url = '/finance/batch_add?export=collection&what=invoices'
    client.get(url)
    assert client.status == 200

    populate_customers_with_subscriptions(web2py, 10)

    # create invoices
    inv_url = '/invoices/subscriptions_create_invoices?month=1&year=2014'
    client.get(inv_url)
    assert client.status == 200

    data = {'description': 'Default invoice description'}
    client.post(inv_url, data=data)
    assert client.status == 200

    # remove the amount for 1 invoice
    amount = web2py.db.invoices_amounts(1)
    amount.TotalPriceVAT = 0
    amount.update_record()
    web2py.db.commit()

    # go back to the page where we have to submit the data for the new batch
    client.get(url)
    assert client.status == 200

    # Add a batch
    data = {
        'Name': 'Test export',
        'Description': 'Cherry shake',
        'Exdate': '2014-02-01',
        'Note': 'Who loves bananas? Gorilla does!',
        'IncludeZero': 'on'
    }

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

    # check note
    assert 'Gorilla' in client.text

    # check amount total
    sum = web2py.db.invoices_amounts.TotalPriceVAT.sum()
    amount = web2py.db().select(sum).first()[sum]
    assert unicode(amount) in client.text.decode('utf-8')

    # check batch item text
    acc_holder = web2py.db.customers_payment_info(1).AccountHolder.split(
        ' ')[0]
    assert acc_holder in client.text

    ## check batch total items
    # customer2's subscription is paused
    # customer10's subscription has price 0, so no invoice was created

    assert web2py.db(web2py.db.payment_batches_items).count() == 6
def test_reports_subscriptions_online(client, web2py):
    """
    Test listing of new online subscriptions
    """
    url = "/default/user/login"
    client.get(url)
    assert client.status == 200

    populate_payment_methods(web2py)
    populate_customers_with_subscriptions(web2py, nr_of_customers=2)

    today = datetime.date.today()

    cs = web2py.db.customers_subscriptions(1)
    cs.Startdate = today
    cs.payment_methods_id = 3
    cs.Origin = "SHOP"
    cs.Verified = True
    cs.update_record()
    web2py.db.commit()

    url = "/reports/subscriptions_online?year=%s&month=%s" % (today.year,
                                                              today.month)
    client.get(url)
    assert client.status == 200

    # Check label display
    assert "Verified" in client.text

    # Check subscription name display
    ssu = web2py.db.school_subscriptions(cs.school_subscriptions_id)
    assert ssu.Name in client.text
def test_reports_subscriptions_alt_prices(client, web2py):
    """
        Is the list of alt. prices for subscriptions being shown correctly?
    """
    url = '/default/user/login'
    client.get(url)
    assert client.status == 200

    populate_customers_with_subscriptions(web2py, 2)

    today = datetime.date.today()

    description = 'Red grapes'

    web2py.db.customers_subscriptions_alt_prices.insert(
        customers_subscriptions_id=1,
        SubscriptionMonth=today.month,
        SubscriptionYear=today.year,
        Amount=200,
        Description=description,
    )

    web2py.db.commit()

    url = '/reports/subscriptions_alt_prices'
    client.get(url)
    assert client.status == 200
    assert description in client.text
def test_invoices_batch_set_status_sent_to_bank_add_payments(client, web2py):
    """
        Check if payments are added to invoices when the status of a batch
        becomes 'sent to bank'
    """
    url = '/finance/batch_add?export=collection&what=invoices'
    client.get(url)
    assert client.status == 200

    populate_customers_with_subscriptions(web2py, 10)

    # create invoices
    inv_url = '/test_automation_customer_subscriptions/' + \
                  'test_create_invoices' + \
                  '?month=1&year=2014&description=Subscription_Jan'
    client.get(inv_url)
    assert client.status == 200

    data = {'description': 'Default invoice description'}
    client.post(inv_url, data=data)
    assert client.status == 200

    # go back to the page where we have to submit the data for the new batch
    client.get(url)
    assert client.status == 200

    # Add a batch
    data = {
        'Name': 'Test export',
        'Description': 'Cherry shake',
        'Exdate': '2014-02-01',
        'Note': 'Who loves bananas? Gorilla does!'
    }

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

    # check note
    assert 'Gorilla' in client.text

    # check setting of status 'sent_to_bank'
    url = '/finance/batch_content_set_status?pbID=1&status=sent_to_bank'
    client.get(url)
    assert client.status == 200

    # check if 6 payments have been added
    assert web2py.db(web2py.db.invoices_payments.id > 0).count() == 6

    ip = web2py.db.invoices_payments(1)
    assert ip.payment_methods_id == 3

    # check payment amounts
    sum = web2py.db.invoices_amounts.TotalPriceVAT.sum()
    invoices_amount = web2py.db().select(sum).first()[sum]

    sum = web2py.db.invoices_payments.Amount.sum()
    payments_amount = web2py.db().select(sum).first()[sum]

    assert invoices_amount == payments_amount
def test_invoice_add_from_customer_subscription(client, web2py):
    """
        Can we add a subscription from an invoice and does it set the
        cusotmers_subscriptions_id, year and month correctly
    """
    # get random URL to initialize OpenStudio environment
    url = '/default/user/login'
    client.get(url)
    assert client.status == 200

    populate_customers_with_subscriptions(web2py, 2)

    url = '/customers/subscription_invoices?cuID=1001&csID=1'
    client.get(url)
    assert client.status == 200

    data = {
        'invoices_groups_id': 100,
        'SubscriptionMonth': 1,
        'SubscriptionYear': 2014,
        'Description': 'Cherry blossom'
    }

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

    # verify display of some values on the page
    assert data['Description'] in client.text

    # Check invoice terms & footer
    ig_1 = web2py.db.invoices_groups(100)
    invoice = web2py.db.invoices(1)

    assert invoice.SubscriptionYear == 2014
    assert invoice.SubscriptionMonth == 1
    assert invoice.Terms == ig_1.Terms
    assert invoice.Footer == ig_1.Footer
    assert invoice.SubscriptionYear == 2014
    assert invoice.SubscriptionMonth == 1

    # Verify linking of invoice to customer and subscription
    ic = web2py.db.invoices_customers(1)
    assert ic.invoices_id == 1
    assert ic.auth_customer_id == 1001
    iics = web2py.db.invoices_items_customers_subscriptions(1)
    assert iics.invoices_items_id == 1
    assert iics.customers_subscriptions_id == 1
    # verify redirection
    assert invoice.InvoiceID in client.text

    # check default invoice group
    query = (
        web2py.db.invoices_groups_product_types.ProductType == 'subscription')
    row = web2py.db(query).select(
        web2py.db.invoices_groups_product_types.ALL).first()
    igptID = row.invoices_groups_id

    assert invoice.invoices_groups_id == igptID
def test_create_monthly_invoices_inv_date_today(client, web2py):
    """
        Can we create subscription invoices for a month?
    """
    # Get random url to initialize OpenStudio environment
    url = '/default/user/login'

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

    populate_customers_with_subscriptions(web2py, 10)


    url = '/test_automation_customer_subscriptions/' + \
          'test_create_invoices' + \
          '?month=1&year=2014&description=Subscription_Jan&invoice_date=today'
    client.get(url)
    assert client.status == 200

    # print web2py.db().select(web2py.db.invoices_items.ALL)
    # print web2py.db().select(web2py.db.invoices_items_customers_subscriptions.ALL)

    # check the created invoices
    ig_100 = web2py.db.invoices_groups(100)
    invoice = web2py.db.invoices(1)
    assert invoice.DateCreated == datetime.date.today()
    assert invoice.Status == 'sent'
    assert invoice.InvoiceID == 'INV' + unicode(
        datetime.date.today().year) + '1'
    assert ig_100.Terms == invoice.Terms
    assert ig_100.Footer == invoice.Footer

    iics = web2py.db.invoices_items_customers_subscriptions(1)
    assert iics.invoices_items_id == 1
    assert iics.customers_subscriptions_id == 1

    # Check that an invoice is created for the paused subscription
    iics = web2py.db.invoices_items_customers_subscriptions(2)
    print iics
    assert iics.invoices_items_id == 2
    assert iics.customers_subscriptions_id == 2

    ## check created invoice items
    ssup = web2py.db.school_subscriptions_price(1)
    # alt. Price subscription item (first subscription gets a different price)
    altp = web2py.db.customers_subscriptions_alt_prices(1)
    item = web2py.db.invoices_items(1)
    assert altp.Amount == item.Price
    assert altp.Description == item.Description

    # paused item
    item = web2py.db.invoices_items(2)
    assert item.Price < ssup.Price

    # regular item
    item = web2py.db.invoices_items(3)
    assert item.Price == ssup.Price
Ejemplo n.º 12
0
def test_add_batch_invoices_without_zero_lines(client, web2py):
    """
        Check whether we can add a default batch and items are generated
        propery
    """
    url = '/finance/batch_add?export=collection&what=invoices'
    client.get(url)
    assert client.status == 200

    populate_customers_with_subscriptions(web2py, 10)

    # create invoices
    inv_url = '/test_automation_customer_subscriptions/' + \
              'test_create_invoices' + \
              '?month=1&year=2014&description=Subscription_Jan'
    client.get(inv_url)
    assert client.status == 200

    data = {'description': 'Default invoice description'}
    client.post(inv_url, data=data)
    assert client.status == 200

    # go back to the page where we have to submit the data for the new batch
    client.get(url)
    assert client.status == 200

    # Add a batch
    data = {
        'Name': 'Test export',
        'Description': 'Cherry shake',
        'Exdate': '2014-02-01',
        'Note': 'Who loves bananas? Gorilla does!'
    }

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

    # check note
    assert 'Gorilla' in client.text

    # check amount total
    sum = web2py.db.invoices_amounts.TotalPriceVAT.sum()
    amount = web2py.db().select(sum).first()[sum]
    assert unicode(amount) in client.text.decode('utf-8')

    # check batch item text
    acc_holder = web2py.db.customers_payment_info(1).AccountHolder.split(
        ' ')[0]
    assert acc_holder in client.text

    ## check batch total items
    # customer2's subscription is paused
    # Customer 8 & 9's subscription don't have an invoice
    # customer10's subscription has price 0, so should be skipped

    assert web2py.db(web2py.db.payment_batches_items).count() == 6
def test_subscriptions_create_montly_invoices(client, web2py):
    """
        Can we create subscription invoices for a month?
    """
    # Get random url to initialize OpenStudio environment
    url = '/default/user/login'

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

    populate_customers_with_subscriptions(web2py, 10)

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

    data = {'description': 'Default invoice description'}
    client.post(url, data=data)
    assert client.status == 200

    #print web2py.db().select(web2py.db.invoices.ALL)

    # Verify that the confirmation message is showing
    assert 'Created invoices' in client.text

    # check the created invoices
    ig_100 = web2py.db.invoices_groups(100)
    invoice = web2py.db.invoices(1)
    assert invoice.Status == 'sent'
    assert invoice.InvoiceID == 'INV' + unicode(
        datetime.date.today().year) + '1'
    assert ig_100.Terms == invoice.Terms
    assert ig_100.Footer == invoice.Footer

    ics = web2py.db.invoices_customers_subscriptions(1)
    assert ics.invoices_id == 1
    assert ics.customers_subscriptions_id == 1

    # make sure the 2nd customer (1002) doesn't have an invoice, the subscription is paused
    assert web2py.db(
        web2py.db.invoices_customers.auth_customer_id == 1002).count() == 0

    ## check created invoice items
    # alt. Price subscription item (first subscription gets a different price)
    altp = web2py.db.customers_subscriptions_alt_prices(1)
    item = web2py.db.invoices_items(1)
    assert altp.Amount == item.Price
    assert altp.Description == item.Description

    # regular item
    ssup = web2py.db.school_subscriptions_price(1)
    item = web2py.db.invoices_items(2)
    assert item.Price == ssup.Price
def test_invoice_dont_show_duplicate_button_subscription(client, web2py):
    """
    Does the Button not show when it is a subscription?
    """
    url = '/default/user/login'
    client.get(url)
    assert client.status == 200

    populate_customers_with_subscriptions(web2py, 3, invoices=True)

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

    assert 'Duplicate' not in client.text
def test_customers_inactive_dont_list_with_subscription(client, web2py):
    """
        Customers with a subscription after given date
    """
    url = '/reports/customers_inactive'
    client.get(url)
    assert client.status == 200

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

    assert web2py.db.auth_user(1001).first_name not in client.text
def test_automation_customers_memberships_renew_expired(client, web2py):
    """
        Can we create subscription invoices for a month?
    """
    from populate_os_tables import populate_customers_with_memberships
    import datetime

    # from openstudio/os_customer_membership import CustomerMembership
    # Get random url to initialize OpenStudio environment
    url = '/default/user/login'
    client.get(url)
    assert client.status == 200

    populate_customers_with_subscriptions(web2py, 1)
    populate_customers_with_memberships(web2py, customers_populated=True)

    memberships_count = web2py.db(web2py.db.customers_memberships).count()

    url = '/test_automation_customer_memberships/' + \
          'test_memberships_renew_expired' + \
          '?month=1&year=2014'
    client.get(url)
    assert client.status == 200

    # Get membership
    previous_membership = web2py.db.customers_memberships(1)
    new_id = memberships_count + 1
    new_membership = web2py.db.customers_memberships(new_id)

    # Check membership
    assert new_membership.Startdate == previous_membership.Enddate + datetime.timedelta(
        days=1)
    assert new_membership.Note == 'Renewal for membership 1'

    # Check invoice
    invcm = web2py.db.invoices_customers_memberships(
        customers_memberships_id=new_id)
    invoice = web2py.db.invoices(invcm.invoices_id)

    assert invoice.Status == 'sent'

    query = (web2py.db.invoices_items.invoices_id == invoice.id)
    rows = web2py.db(query).select(web2py.db.invoices_items.ALL)
    for row in rows:
        assert "Membership" in row.ProductName
        assert unicode(new_membership.Startdate) in row.Description
        assert unicode(new_membership.Enddate) in row.Description
def test_invoice_add_from_customer_subscription_with_registration_fee(
        client, web2py):
    """
        Can we add a subscription from an invoice and does it set the
        cusotmers_subscriptions_id, year and month correctly
    """
    # get random URL to initialize OpenStudio environment
    url = '/default/user/login'
    client.get(url)
    assert client.status == 200

    populate_customers_with_subscriptions(web2py, 2)

    # Update first school subscription to have a registration fee
    web2py.db.school_subscriptions[1] = dict(RegistrationFee=25.00)
    web2py.db.commit()
    url = '/customers/subscription_invoices?cuID=1001&csID=1'
    client.get(url)
    assert client.status == 200

    data = {
        'invoices_groups_id': 100,
        'SubscriptionMonth': 1,
        'SubscriptionYear': 2014,
        'Description': 'Cherry blossom',
    }

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

    url = '/customers/subscription_invoices?cuID=1001&csID=1'
    client.get(url)
    assert client.status == 200
    data = {
        'invoices_groups_id': 100,
        'SubscriptionMonth': 2,
        'SubscriptionYear': 2014,
        'Description': 'Cherry blossom',
    }

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

    # verify if registration fee is added
    assert web2py.db(web2py.db.invoices_items.ProductName ==
                     'Registration fee').count() == 1
    assert web2py.db(web2py.db.invoices.id > 0).count() == 2
Ejemplo n.º 18
0
def test_create_monthly_invoices(client, web2py):
    """
        Can we create subscription invoices for a month?
    """
    # Get random url to initialize OpenStudio environment
    url = '/default/user/login'

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

    populate_customers_with_subscriptions(web2py, 10)

    url = '/test_automation_customer_subscriptions/' + \
          'test_create_invoices' + \
          '?month=1&year=2014&description=Subscription_Jan'
    client.get(url)
    assert client.status == 200

    # check the created invoices
    ig_100 = web2py.db.invoices_groups(100)
    invoice = web2py.db.invoices(1)
    assert invoice.Status == 'sent'
    assert invoice.InvoiceID == 'INV' + unicode(
        datetime.date.today().year) + '1'
    assert ig_100.Terms == invoice.Terms
    assert ig_100.Footer == invoice.Footer

    ics = web2py.db.invoices_customers_subscriptions(1)
    assert ics.invoices_id == 1
    assert ics.customers_subscriptions_id == 1

    # make sure the 2nd customer (1002) doesn't have an invoice, the subscription is paused
    assert web2py.db(
        web2py.db.invoices_customers.auth_customer_id == 1002).count() == 0

    ## check created invoice items
    # alt. Price subscription item (first subscription gets a different price)
    altp = web2py.db.customers_subscriptions_alt_prices(1)
    item = web2py.db.invoices_items(1)
    assert altp.Amount == item.Price
    assert altp.Description == item.Description

    # regular item
    ssup = web2py.db.school_subscriptions_price(1)
    item = web2py.db.invoices_items(2)
    assert item.Price == ssup.Price
def test_add_batch_category_without_zero_lines(client, web2py):
    """
        Check if a batch for a direct debit extra category is exported correctly
    """
    url = '/finance/batch_add?export=collection&what=category'
    client.get(url)
    assert client.status == 200

    populate_customers_with_subscriptions(web2py, 10)

    web2py.db.payment_categories.insert(
        Name         = 'Papaya',
        CategoryType = 0 )

    alt_amount_1 = 200
    alt_desc_1 = 'Papaya'
    web2py.db.alternativepayments.insert(
        auth_customer_id       = 1001,
        PaymentYear            = 2014,
        PaymentMonth           = 1,
        Amount                 = alt_amount_1,
        Description            = alt_desc_1,
        payment_categories_id  = 1)

    alt_amount_2 = 2009
    alt_desc_2 = 'Pineapple'
    web2py.db.alternativepayments.insert(
        auth_customer_id       = 1002,
        PaymentYear            = 2014,
        PaymentMonth           = 1,
        Amount                 = alt_amount_2,
        Description            = alt_desc_2,
        payment_categories_id  = 1)

    alt_amount_3 = 0
    alt_desc_3 = 'Mango'
    web2py.db.alternativepayments.insert(
        auth_customer_id       = 1003,
        PaymentYear            = 2014,
        PaymentMonth           = 1,
        Amount                 = alt_amount_3,
        Description            = alt_desc_3,
        payment_categories_id  = 1)

    web2py.db.commit()

    #print web2py.db().select(web2py.db.customers_payment_info.ALL)

    data = {'Name'                  : 'Test export',
            'Description'           : 'Cherry shake',
            'ColYear'               : '2014',
            'ColMonth'              : '1',
            'Exdate'                : '2014-02-01',
            'Note'                  : 'Who loves bananas? Gorilla does!',
            'payment_categories_id' : '1'}

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

    ## check amount total
    amount = 0
    rows = web2py.db().select(web2py.db.alternativepayments.ALL)
    for row in rows:
        amount += row.Amount
    assert unicode(amount) in client.text.decode('utf-8')

    # check batch total items
    assert web2py.db(web2py.db.payment_batches_items).count() == 2

    # check description
    assert alt_desc_2 in client.text

    # check ignore zero lines
    assert not alt_desc_3 in client.text
def test_add_batch_invoices_location(client, web2py):
    """
        Check whether we can add an invoice based batch and items are generated
        propery for a selected location
    """
    client.get('/default/user/login')
    assert client.status == 200
    ## set sys_property
    # without this, the form doesn't accept 'school_locations_id'
    web2py.db.sys_properties.insert(
        Property='Customer_ShowLocation',
        PropertyValue='on'
        )
    web2py.db.commit()

    school_locations_id = 1

    url = '/finance/batch_add?export=collection&what=invoices'
    client.get(url)
    assert client.status == 200

    populate_customers_with_subscriptions(web2py, 10)

    # create invoices
    inv_url = '/test_automation_customer_subscriptions/' + \
              'test_create_invoices' + \
              '?month=1&year=2014&description=Subscription_Jan'
    client.get(inv_url)
    assert client.status == 200

    # back to the place where we want to be to create a batch
    client.get(url)
    assert client.status == 200

    data = {'Name'                : 'Test export',
            'Description'         : 'Cherry shake',
            'Exdate'              : '2014-02-01',
            'school_locations_id' : school_locations_id,
            'Note'                : 'Who loves bananas? Gorilla does!'}

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

    # check redirection
    assert 'Added batch' in client.text

    # check note
    assert 'Gorilla' in client.text

    # count customers
    query = (web2py.db.auth_user.school_locations_id == school_locations_id)
    customers_count = web2py.db(query).count() # all customers should have an invoice
    # check amount total
    left = [ web2py.db.invoices.on(web2py.db.invoices.id ==
                web2py.db.invoices_amounts.invoices_id),
             web2py.db.invoices_customers.on(
                 web2py.db.invoices_customers.invoices_id ==
                 web2py.db.invoices.id
             ),
             web2py.db.auth_user.on(web2py.db.auth_user.id ==
                web2py.db.invoices_customers.auth_customer_id)
           ]

    sum = web2py.db.invoices_amounts.TotalPriceVAT.sum()
    query = (web2py.db.auth_user.school_locations_id == school_locations_id)
    amount = web2py.db(query).select(sum, left=left).first()[sum]
    assert unicode(amount) in client.text.decode('utf-8')

    # check batch item text (first 5 customers get school_locations_id 1)
    payinfo = web2py.db.customers_payment_info(1) # check that the first customer is in the batch
    acc_holder = payinfo.AccountHolder.split(' ')[0]
    assert acc_holder in client.text

    # nr of batches should be equal to nr of customers with locations_id 1
    query = (web2py.db.auth_user.school_locations_id == 1)

    items_count = web2py.db(web2py.db.payment_batches_items).count()
    assert customers_count == items_count