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_customers_orders_delete(client, web2py):
    """
        Is the delete permission for customers_orders working?
    """
    setup_permission_tests(web2py)

    populate_customers_orders(web2py)
    populate_customers_orders_items(web2py)

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

    url = '/orders/index'
    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_orders', 0)
    web2py.db.commit()

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

    assert 'fa-times' in client.text
def test_deliver(client, web2py):
    """
        Are orders delivered and unpaid invoices created correctly?
    """
    url = '/user/login'
    client.get(url)
    assert client.status == 200

    setup_profile_tests(web2py)
    populate_customers_orders(web2py)
    populate_customers_orders_items(web2py)

    url = '/orders/deliver?coID=2'
    client.get(url)
    assert client.status == 200
    assert 'Delivered order' in client.text

    ##
    # Check whether order status was changed
    ##
    order = web2py.db.customers_orders(2)
    assert order.Status == 'delivered'

    ##
    # Check whether an invoice was created
    ##
    assert web2py.db(web2py.db.invoices).count() == 1

    # print web2py.db().select(web2py.db.customers_orders.ALL)
    # print web2py.db().select(web2py.db.customers_orders_items.ALL)
    # print web2py.db().select(web2py.db.invoices.ALL)
    # print web2py.db().select(web2py.db.invoices_items.ALL)
Beispiel #4
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
Beispiel #5
0
def test_orders(client, web2py):
    """
        Is the list of orders showing?
    """
    setup_profile_tests(web2py)

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

    populate_customers_orders(web2py)
    populate_customers_orders_items(web2py)

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

    # check all invoices link
    assert 'All invoices' in client.text

    order = web2py.db.customers_orders(2)

    # Check display of ID
    assert str(order.id) in client.text

    # check display of status
    assert 'Awaiting payment' in client.text

    # check time
    import pytz
    dc = pytz.utc.localize(order.DateCreated)
    tz = pytz.timezone('Europe/Amsterdam')
    local_dc = dc.astimezone(tz)
    assert str(
        local_dc
    )[:
      -9] in client.text  #[:-3] removes seconds, they are not displayed by default

    # check items display
    query = (web2py.db.customers_orders_items.customers_orders_id == 2)
    rows = web2py.db(query).select(web2py.db.customers_orders_items.ALL)
    for row in rows:
        assert row.Description in client.text

    # Check total amount
    ord_amounts = web2py.db.customers_orders_amounts(2)
    assert format(ord_amounts.TotalPriceVAT, '.2f') in client.text

    # check cancel button display
    assert 'Cancel' in client.text
    assert '/profile/order_cancel?coID=2' in client.text

    # check payment button
    assert 'Pay now' in client.text
    assert '/mollie/order_pay?coID=2' in client.text
def test_customers_inactive_dont_list_with_orders(client, web2py):
    """
        Customers with order after given date
    """
    from populate_os_tables import populate_customers_orders

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

    populate_customers(web2py, created_on=datetime.date(2012, 1, 1))
    populate_customers_orders(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
Beispiel #7
0
def test_order_cancel(client, web2py):
    """
        Can we actually cancel an order?
    """
    setup_profile_tests(web2py)

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

    populate_customers_orders(web2py)
    populate_customers_orders_items(web2py)

    url = '/profile/order_cancel?coID=2'
    client.get(url)
    assert client.status == 200
    assert 'Orders' in client.text  # Verify redirection to orders page

    order = web2py.db.customers_orders(2)
    assert order.Status == 'cancelled'
def test_osmail_render_order_delivered(client, web2py):
    """
        Is the order delivered mail rendering correctly?
    """
    # get a random url to init OpenStudio environment
    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_template?email_template=order_delivered&customers_orders_id=1'
    client.get(url)
    assert client.status == 200

    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
def test_edit(client, web2py):
    '''
        Can we update the order status?
    '''
    url = '/user/login'
    client.get(url)
    assert client.status == 200

    setup_profile_tests(web2py)
    populate_customers_orders(web2py)
    populate_customers_orders_items(web2py)

    url = '/orders/edit?coID=2'
    client.get(url)
    assert client.status == 200

    data = {'Status':'cancelled',
            'id': 2}

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

    order = web2py.db.customers_orders(2)
    assert order.Status == 'cancelled'
def test_ticket_sell_to_customer_AutoSendInfoMail_False(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)

    ws = web2py.db.workshops(1)
    ws.AutoSendInfoMail = False
    ws.update_record()

    web2py.db.commit()

    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

    # Check that a mail is not sent
    assert web2py.db(web2py.db.messages).count() == 0
    assert web2py.db(web2py.db.customers_messages).count() == 0
Beispiel #11
0
def test_order_paid_delivery_invoice(client, web2py):
    """
        Is the order delivered after it's paid and is an invoice created?
    """
    setup_profile_tests(web2py)

    url = '/default/user/login'
    client.get(url)
    assert client.status == 200

    populate_customers(
        web2py, 1)  # so we have 2 orders, one for admin, one for a customer
    populate_customers_orders(web2py)
    populate_customers_orders_items(web2py, classcards=True)
    populate_customers_orders_items(web2py, subscriptions=True)
    populate_customers_orders_items(web2py, memberships=True)
    populate_customers_orders_items(web2py, workshops_products=True)
    populate_customers_orders_items(web2py, classes=True)
    populate_customers_orders_items(web2py, donation=True)

    web2py.db.sys_properties.insert(Property='shop_donations_tax_rates_id',
                                    PropertyValue='1')
    web2py.db.sys_properties.insert(Property='shop_donations_create_invoice',
                                    PropertyValue='on')

    web2py.db.commit()

    scd = web2py.db.school_classcards(1)
    wsp = web2py.db.workshops_products(1)
    class_price = web2py.db.classes_price(1)
    ssu = web2py.db.school_subscriptions(1)
    ssu_price = web2py.db.school_subscriptions_price(1)
    sm = web2py.db.school_memberships(1)
    donation_price = 100  # 100 for the donation is fixed in the population of the tables

    period_start = datetime.date.today()
    period_end = get_last_day_month(period_start)

    delta = period_end - period_start
    days = delta.days + 1
    total_days = period_end.day
    ssu_calculated_price = round(
        float(days) / float(total_days) * float(ssu_price.Price), 2)

    price = round(
        scd.Price + wsp.Price + class_price.Dropin + ssu_calculated_price +
        sm.Price + donation_price, 2)

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

    url = '/mollie/test_webhook_order_paid?coID=1&payment_amount=' + str(
        price) + '&payment_date=2014-01-01&mollie_payment_id=tr_test'
    client.get(url)
    assert client.status == 200

    # check class card delivery
    assert web2py.db(web2py.db.customers_classcards).count() == 1

    # check workshop product delivery
    assert web2py.db(web2py.db.workshops_products_customers).count() == 1

    # check drop in class delivery
    query = (web2py.db.classes_attendance.auth_customer_id == 1) & \
            (web2py.db.classes_attendance.ClassDate == '2099-01-01') & \
            (web2py.db.classes_attendance.classes_id == 1)
    assert web2py.db(query).count() == 1

    ## check invoice
    # invoice creation
    invoice = web2py.db.invoices(1)
    assert invoice.Status == 'paid'

    ## invoice items
    # classcard
    assert web2py.db(web2py.db.invoices_items).count() == 6
    ii_1 = web2py.db.invoices_items(1)
    assert scd.Name in ii_1.Description
    assert ii_1.Price == scd.Price
    assert ii_1.Quantity == 1
    # subscription
    ii_2 = web2py.db.invoices_items(2)
    assert ssu.Name in ii_2.Description
    # assert ii_2.Price == ssu_price.Price #TODO: calculate broken period price
    assert ii_2.Quantity == 1
    # membership
    ii_3 = web2py.db.invoices_items(3)
    assert sm.Name in ii_3.Description
    assert ii_3.Price == sm.Price
    assert ii_3.Quantity == 1
    # Event
    ii_4 = web2py.db.invoices_items(4)
    assert wsp.Name in ii_4.Description
    assert ii_4.Price == wsp.Price
    assert ii_4.Quantity == 1
    # Class
    ii_5 = web2py.db.invoices_items(5)
    assert ii_5.Description == 'Bananas'
    assert ii_5.Price == class_price.Dropin
    assert ii_5.Quantity == 1
    # Donation
    ii_6 = web2py.db.invoices_items(6)
    assert ii_6.Description == 'Bananas'
    assert ii_6.Price == donation_price
    assert ii_6.Quantity == 1
    assert not ii_6.tax_rates_id is None

    # invoice links
    assert web2py.db(
        web2py.db.invoices_items_customers_classcards).count() == 1
    assert web2py.db(
        web2py.db.invoices_items_customers_subscriptions).count() == 1
    assert web2py.db(
        web2py.db.invoices_items_customers_memberships).count() == 1
    assert web2py.db(web2py.db.invoices_items_classes_attendance).count() == 1
    assert web2py.db(
        web2py.db.invoices_items_workshops_products_customers).count() == 1

    # invoice amounts
    amounts = web2py.db.invoices_amounts(1)
    assert amounts.TotalPriceVAT == price

    # invoice footer & terms
    ig_100 = web2py.db.invoices_groups(100)
    assert ig_100.Terms == invoice.Terms
    assert ig_100.Footer == invoice.Footer

    # Check order status
    order = web2py.db.customers_orders(1)
    assert order.Status == 'delivered'

    # Check if all other orders have been cancelled. There should only be one space, which is filled after delivery
    assert web2py.db(
        web2py.db.customers_orders.Status == 'cancelled').count() == 2