Example #1
0
def get_line_taxes_for(order_line):
    get_default_tax()  # Creates the Tax and TaxRule
    tax_module = DefaultTaxModule()
    tax_ctx = tax_module.get_context_from_order_source(order_line.order)
    product = order_line.product
    price = order_line.price
    taxed_price = tax_module.get_taxed_price_for(tax_ctx, product, price)
    return taxed_price.taxes
Example #2
0
def get_line_taxes_for(order_line):
    get_default_tax()  # Creates the Tax and TaxRule
    tax_module = DefaultTaxModule()
    tax_ctx = tax_module.get_context_from_order_source(order_line.order)
    product = order_line.product
    price = order_line.price
    taxed_price = tax_module.get_taxed_price_for(tax_ctx, product, price)
    return taxed_price.taxes
Example #3
0
def create_order(request, creator, customer, product):
    billing_address = get_address()
    shipping_address = get_address(name="Shippy Doge")
    shipping_address.save()
    order = Order(creator=creator,
                  customer=customer,
                  shop=get_default_shop(),
                  payment_method=get_default_payment_method(),
                  shipping_method=get_default_shipping_method(),
                  billing_address=billing_address,
                  shipping_address=shipping_address,
                  order_date=now(),
                  status=get_initial_order_status())
    order.full_clean()
    order.save()
    supplier = get_default_supplier()
    product_order_line = OrderLine(order=order)
    update_order_line_from_product(order_line=product_order_line,
                                   product=product,
                                   request=request,
                                   quantity=5,
                                   supplier=supplier)
    product_order_line.unit_price = TaxlessPrice(100)
    assert product_order_line.taxful_total_price.amount > 0
    product_order_line.save()
    product_order_line.taxes.add(
        OrderLineTax.from_tax(get_default_tax(),
                              product_order_line.taxless_total_price))

    discount_order_line = OrderLine(order=order,
                                    quantity=1,
                                    type=OrderLineType.OTHER)
    discount_order_line.total_discount = TaxfulPrice(30)
    assert discount_order_line.taxful_total_discount.amount == 30
    assert discount_order_line.taxful_total_price.amount == -30
    assert discount_order_line.taxful_unit_price.amount == 0
    discount_order_line.save()

    order.cache_prices()
    order.check_all_verified()
    order.save()
    base_amount = 5 * 100
    tax_value = get_default_tax().calculate_amount(base_amount)
    assert order.taxful_total_price == base_amount + tax_value - 30, "Math works"

    shipment = order.create_shipment_of_all_products(supplier=supplier)
    assert shipment.total_products == 5, "All products were shipped"
    assert shipment.weight == product.net_weight * 5, "Gravity works"
    assert not order.get_unshipped_products(
    ), "Nothing was left in the warehouse"

    order.create_payment(order.taxful_total_price)
    assert order.is_paid()
    assert Order.objects.paid().filter(
        pk=order.pk).exists(), "It was paid! Honestly!"
Example #4
0
def create_order(request, creator, customer, product):
    billing_address = get_address()
    shipping_address = get_address(name="Shippy Doge")
    shipping_address.save()
    order = Order(
        creator=creator,
        customer=customer,
        shop=get_default_shop(),
        payment_method=get_default_payment_method(),
        shipping_method=get_default_shipping_method(),
        billing_address=billing_address,
        shipping_address=shipping_address,
        order_date=now(),
        status=get_initial_order_status()
    )
    order.full_clean()
    order.save()
    supplier = get_default_supplier()
    product_order_line = OrderLine(order=order)
    update_order_line_from_product(order_line=product_order_line, product=product, request=request, quantity=5, supplier=supplier)
    product_order_line.unit_price = TaxlessPrice(100)
    assert product_order_line.taxful_total_price.amount > 0
    product_order_line.save()
    product_order_line.taxes.add(OrderLineTax.from_tax(get_default_tax(), product_order_line.taxless_total_price))

    discount_order_line = OrderLine(order=order, quantity=1, type=OrderLineType.OTHER)
    discount_order_line.total_discount = TaxfulPrice(30)
    assert discount_order_line.taxful_total_discount.amount == 30
    assert discount_order_line.taxful_total_price.amount == -30
    assert discount_order_line.taxful_unit_price.amount == 0
    discount_order_line.save()

    order.cache_prices()
    order.check_all_verified()
    order.save()
    base_amount = 5 * 100
    tax_value = get_default_tax().calculate_amount(base_amount)
    assert order.taxful_total_price == base_amount + tax_value - 30, "Math works"

    shipment = order.create_shipment_of_all_products(supplier=supplier)
    assert shipment.total_products == 5, "All products were shipped"
    assert shipment.weight == product.net_weight * 5, "Gravity works"
    assert not order.get_unshipped_products(), "Nothing was left in the warehouse"

    order.create_payment(order.taxful_total_price)
    assert order.is_paid()
    assert Order.objects.paid().filter(pk=order.pk).exists(), "It was paid! Honestly!"
Example #5
0
def test_line_discount():
    order = create_empty_order(prices_include_tax=False)
    order.save()
    currency = order.shop.currency
    ol = OrderLine(order=order, type=OrderLineType.OTHER, quantity=5, text="Thing")
    ol.discount_amount = order.shop.create_price(50)
    ol.base_unit_price = order.shop.create_price(40)
    ol.save()
    ol.taxes.add(OrderLineTax.from_tax(get_default_tax(), ol.taxless_price.amount, order_line=ol))
    assert ol.taxless_discount_amount == order.shop.create_price(50)
    assert ol.taxful_discount_amount == TaxfulPrice(75, currency)
    assert ol.taxless_price == order.shop.create_price(150)
    assert ol.taxful_price == TaxfulPrice(150 + 75, currency)
    assert ol.taxless_base_unit_price == order.shop.create_price(40)
    assert ol.taxful_base_unit_price == TaxfulPrice(60, currency)
    assert "Thing" in six.text_type(ol)
Example #6
0
def test_line_discount_more():
    order = create_empty_order()
    order.save()
    ol = OrderLine(order=order, type=OrderLineType.OTHER)
    ol.quantity = 5
    ol.unit_price = TaxlessPrice(30)
    ol.total_discount = TaxlessPrice(50)
    ol.save()
    assert ol.taxless_unit_price == TaxlessPrice(30)
    assert ol.taxless_total_discount == TaxlessPrice(50)
    assert ol.taxless_total_price == TaxlessPrice(5 * 30 - 50)
    ol.taxes.add(OrderLineTax.from_tax(get_default_tax(), ol.taxless_total_price))
    assert ol.taxless_total_discount == TaxlessPrice(50)
    assert ol.taxful_total_discount == TaxfulPrice(75)
    assert ol.taxless_total_price == TaxlessPrice(100)
    assert ol.taxful_total_price == TaxfulPrice(150)
    assert ol.taxless_unit_price == TaxlessPrice(30)
    assert ol.taxful_unit_price == TaxfulPrice(45)
Example #7
0
def test_line_discount_more():
    order = create_empty_order()
    order.save()
    ol = OrderLine(order=order, type=OrderLineType.OTHER)
    ol.quantity = 5
    ol.base_unit_price = order.shop.create_price(30)
    ol.discount_amount = order.shop.create_price(50)
    ol.save()
    currency = order.shop.currency
    assert ol.taxless_base_unit_price == TaxlessPrice(30, currency)
    assert ol.taxless_discount_amount == TaxlessPrice(50, currency)
    assert ol.taxless_price == TaxlessPrice(5 * 30 - 50, currency)
    ol.taxes.add(OrderLineTax.from_tax(get_default_tax(), ol.taxless_price.amount, order_line=ol))
    assert ol.taxless_discount_amount == TaxlessPrice(50, currency)
    assert ol.taxful_discount_amount == TaxfulPrice(75, currency)
    assert ol.taxless_price == TaxlessPrice(100, currency)
    assert ol.taxful_price == TaxfulPrice(150, currency)
    assert ol.taxless_base_unit_price == TaxlessPrice(30, currency)
    assert ol.taxful_base_unit_price == TaxfulPrice(45, currency)
Example #8
0
def test_line_discount():
    order = create_empty_order()
    order.save()
    ol = OrderLine(
        order=order,
        type=OrderLineType.OTHER,
        quantity=5,
        text="Thing"
    )
    ol.total_discount = TaxlessPrice(50)
    ol.unit_price = TaxlessPrice(40)
    ol.save()
    ol.taxes.add(OrderLineTax.from_tax(get_default_tax(), ol.taxless_total_price))
    assert ol.taxless_total_discount == TaxlessPrice(50)
    assert ol.taxful_total_discount == TaxfulPrice(75)
    assert ol.taxless_total_price == TaxlessPrice(150)
    assert ol.taxful_total_price == TaxfulPrice(150 + 75)
    assert ol.taxless_unit_price == TaxlessPrice(40)
    assert ol.taxful_unit_price == TaxfulPrice(60)
    assert "Thing" in six.text_type(ol)
Example #9
0
def test_line_discount_more():
    order = create_empty_order()
    order.save()
    ol = OrderLine(order=order, type=OrderLineType.OTHER)
    ol.quantity = 5
    ol.base_unit_price = order.shop.create_price(30)
    ol.discount_amount = order.shop.create_price(50)
    ol.save()
    currency = order.shop.currency
    assert ol.taxless_base_unit_price == TaxlessPrice(30, currency)
    assert ol.taxless_discount_amount == TaxlessPrice(50, currency)
    assert ol.taxless_price == TaxlessPrice(5 * 30 - 50, currency)
    ol.taxes.add(OrderLineTax.from_tax(
        get_default_tax(), ol.taxless_price.amount, order_line=ol))
    assert ol.taxless_discount_amount == TaxlessPrice(50, currency)
    assert ol.taxful_discount_amount == TaxfulPrice(75, currency)
    assert ol.taxless_price == TaxlessPrice(100, currency)
    assert ol.taxful_price == TaxfulPrice(150, currency)
    assert ol.taxless_base_unit_price == TaxlessPrice(30, currency)
    assert ol.taxful_base_unit_price == TaxfulPrice(45, currency)
Example #10
0
def test_line_discount():
    order = create_empty_order(prices_include_tax=False)
    order.save()
    currency = order.shop.currency
    ol = OrderLine(order=order,
                   type=OrderLineType.OTHER,
                   quantity=5,
                   text="Thing")
    ol.discount_amount = order.shop.create_price(50)
    ol.base_unit_price = order.shop.create_price(40)
    ol.save()
    ol.taxes.add(
        OrderLineTax.from_tax(get_default_tax(),
                              ol.taxless_price.amount,
                              order_line=ol))
    assert ol.taxless_discount_amount == order.shop.create_price(50)
    assert ol.taxful_discount_amount == TaxfulPrice(75, currency)
    assert ol.taxless_price == order.shop.create_price(150)
    assert ol.taxful_price == TaxfulPrice(150 + 75, currency)
    assert ol.taxless_base_unit_price == order.shop.create_price(40)
    assert ol.taxful_base_unit_price == TaxfulPrice(60, currency)
    assert "Thing" in six.text_type(ol)