Exemple #1
0
def create_order(number=None, basket=None, user=None, shipping_address=None, shipping_method=None,
        billing_address=None, total_incl_tax=None, total_excl_tax=None, **kwargs):
    """
    Helper method for creating an order for testing
    """
    if not basket:
        basket = Basket.objects.create()
        basket.add_product(create_product(price=D('10.00')))
    if not basket.id:
        basket.save()
    if shipping_method is None:
        shipping_method = Free()
    if total_incl_tax is None or total_excl_tax is None:
        calc = OrderTotalCalculator()
        total_incl_tax = calc.order_total_incl_tax(basket, shipping_method)
        total_excl_tax = calc.order_total_excl_tax(basket, shipping_method)
    order = OrderCreator().place_order(
            order_number=number,
            user=user,
            basket=basket,
            shipping_address=shipping_address,
            shipping_method=shipping_method,
            billing_address=billing_address,
            total_incl_tax=total_incl_tax,
            total_excl_tax=total_excl_tax,
            **kwargs
            )
    return order
Exemple #2
0
def create_order(number=None, basket=None, user=None, shipping_address=None, shipping_method=None,
        billing_address=None, total_incl_tax=None, total_excl_tax=None, **kwargs):
    """
    Helper method for creating an order for testing
    """
    if not basket:
        basket = Basket.objects.create()
        basket.add_product(create_product(price=D('10.00')))
    if not basket.id:
        basket.save()
    if shipping_method is None:
        shipping_method = Free()
    if total_incl_tax is None or total_excl_tax is None:
        calc = OrderTotalCalculator()
        total_incl_tax = calc.order_total_incl_tax(basket, shipping_method)
        total_excl_tax = calc.order_total_excl_tax(basket, shipping_method)
    order = OrderCreator().place_order(
            order_number=number,
            user=user,
            basket=basket,
            shipping_address=shipping_address,
            shipping_method=shipping_method,
            billing_address=billing_address,
            total_incl_tax=total_incl_tax,
            total_excl_tax=total_excl_tax,
            **kwargs
            )
    return order
Exemple #3
0
    def test_multiple_payment_events(self):
        basket = factories.create_basket(empty=True)
        user = factories.UserFactory()
        add_product(basket, D('100.00'))
        order_placement = OrderPlacementMixin()
        order_placement.add_payment_event('Gift Card Payment', D('10'))
        order_placement.add_payment_event('Credit Card Payment', D('90'))
        shipping_method = Free()
        shipping_charge = shipping_method.calculate(basket)
        order_total = OrderTotalCalculator().calculate(basket, shipping_charge)

        billing_address = factories.BillingAddressFactory()
        shipping_address = factories.ShippingAddressFactory()
        order_submission_data = {
            'user': user,
            'order_number': '12345',
            'basket': basket,
            'shipping_method': shipping_method,
            'shipping_charge': shipping_charge,
            'order_total': order_total,
            'billing_address': billing_address,
            'shipping_address': shipping_address
        }
        order_placement.place_order(**order_submission_data)
        order1 = Order.objects.get(number='12345')
        self.assertEqual(order1.payment_events.count(), 2)
        event1 = order1.payment_events.all()[0]
        event2 = order1.payment_events.all()[1]
        self.assertEqual(event1.event_type.name, 'Credit Card Payment')
        self.assertEqual(event1.amount, D('90'))
        self.assertEqual(event1.lines.count(), 1)
        self.assertEqual(event2.event_type.name, 'Gift Card Payment')
        self.assertEqual(event2.amount, D('10'))
        self.assertEqual(event2.lines.count(), 1)
    def test_multi_site(self):
        basket = factories.create_basket(empty=True)
        site1 = factories.SiteFactory()
        site2 = factories.SiteFactory()
        request = HttpRequest()
        request.META['SERVER_PORT'] = 80
        request.META['SERVER_NAME'] = site1.domain
        user = factories.UserFactory()
        add_product(basket, D('12.00'))
        shipping_method = Free()
        shipping_charge = shipping_method.calculate(basket)
        order_total = OrderTotalCalculator().calculate(basket, shipping_charge)

        billing_address = factories.BillingAddressFactory()
        shipping_address = factories.ShippingAddressFactory()
        order_submission_data = {'user': user,
                                 'order_number': '12345',
                                 'basket': basket,
                                 'shipping_method': shipping_method,
                                 'shipping_charge': shipping_charge,
                                 'order_total': order_total,
                                 'billing_address': billing_address,
                                 'shipping_address': shipping_address,
                                 'request': request}
        OrderPlacementMixin().place_order(**order_submission_data)
        order1 = Order.objects.get(number='12345')
        self.assertEqual(order1.site, site1)

        add_product(basket, D('12.00'))
        request.META['SERVER_NAME'] = site2.domain
        order_submission_data['order_number'] = '12346'
        order_submission_data['request'] = request
        OrderPlacementMixin().place_order(**order_submission_data)
        order2 = Order.objects.get(number='12346')
        self.assertEqual(order2.site, site2)
    def test_update_address_book(self):
        basket = factories.create_basket(empty=True)
        user = factories.UserFactory()
        add_product(basket, D('12.00'))
        shipping_method = FixedPrice(D('5.00'), D('5.00'))

        billing_address = factories.BillingAddressFactory(
            line1='1 Boardwalk Place',
            line2='Trafalgar Way',
            line3='Tower Hamlets',
            line4='London')
        shipping_address = factories.ShippingAddressFactory(
            line1='Knightsbridge', line2='159', line4='London')
        shipping_charge = shipping_method.calculate(basket)
        order_total = OrderTotalCalculator().calculate(basket, shipping_charge)

        order_submission_data = {
            'user': user,
            'order_number': '12345',
            'basket': basket,
            'shipping_address': shipping_address,
            'shipping_method': shipping_method,
            'shipping_charge': shipping_charge,
            'billing_address': billing_address,
            'order_total': order_total
        }
        OrderPlacementMixin().place_order(**order_submission_data)

        self.assertEqual(
            user.addresses.filter(
                hash=billing_address.generate_hash()).count(), 1)
        self.assertEqual(
            user.addresses.filter(
                hash=shipping_address.generate_hash()).count(), 1)

        user_billing_address = user.addresses.get(
            hash=billing_address.generate_hash())
        user_shipping_address = user.addresses.get(
            hash=shipping_address.generate_hash())
        self.assertEqual(user_billing_address.num_orders_as_billing_address, 1)
        self.assertEqual(user_shipping_address.num_orders_as_shipping_address,
                         1)

        order_submission_data['order_number'] = '12346'

        OrderPlacementMixin().place_order(**order_submission_data)

        user_billing_address = user.addresses.get(
            hash=billing_address.generate_hash())
        user_shipping_address = user.addresses.get(
            hash=shipping_address.generate_hash())
        self.assertEqual(user_billing_address.num_orders_as_billing_address, 2)
        self.assertEqual(user_shipping_address.num_orders_as_shipping_address,
                         2)

        order_submission_data.pop('billing_address', None)
        order_submission_data['order_number'] = '123457'
        OrderPlacementMixin().place_order(**order_submission_data)

        user_billing_address = user.addresses.get(
            hash=billing_address.generate_hash())
        user_shipping_address = user.addresses.get(
            hash=shipping_address.generate_hash())
        self.assertEqual(user_billing_address.num_orders_as_billing_address, 2)
        self.assertEqual(user_shipping_address.num_orders_as_shipping_address,
                         3)

        shipping_address.line2 = '160'
        order_submission_data['billing_address'] = billing_address
        order_submission_data['order_number'] = '123458'
        OrderPlacementMixin().place_order(**order_submission_data)

        user_billing_address = user.addresses.get(
            hash=billing_address.generate_hash())
        user_shipping_address = user.addresses.get(
            hash=shipping_address.generate_hash())
        self.assertEqual(user_billing_address.num_orders_as_billing_address, 3)
        self.assertEqual(user_shipping_address.num_orders_as_shipping_address,
                         1)
Exemple #6
0
 def get_order_totals(self, basket, shipping_charge, **kwargs):
     """
     Returns the total for the order with and without tax
     """
     return OrderTotalCalculator(self).calculate(
         basket, shipping_charge, **kwargs)