Exemplo n.º 1
0
def create_order_with_product(product,
                              supplier,
                              quantity,
                              taxless_base_unit_price,
                              tax_rate=0,
                              n_lines=1,
                              shop=None):
    order = create_empty_order(shop=shop)
    order.full_clean()
    order.save()

    request = apply_request_middleware(RequestFactory().get("/"))
    request.shop = order.shop

    for x in range(n_lines):
        product_order_line = OrderLine(order=order)
        update_order_line_from_product(request=request,
                                       order_line=product_order_line,
                                       product=product,
                                       quantity=quantity,
                                       supplier=supplier)
        product_order_line.base_unit_price = order.shop.create_price(
            taxless_base_unit_price)
        product_order_line.save()
        product_order_line.taxes.add(
            OrderLineTax.from_tax(
                get_test_tax(tax_rate),
                product_order_line.taxless_total_price.amount,
                order_line=product_order_line,
            ))
    assert order.get_product_ids_and_quantities()[product.pk] == (
        quantity * n_lines), "Things got added"
    return order
Exemplo n.º 2
0
def create_order_with_product(product,
                              supplier,
                              quantity,
                              taxless_base_unit_price,
                              tax_rate=0,
                              n_lines=1,
                              shop=None):
    order = create_empty_order(shop=shop)
    order.full_clean()
    order.save()

    pricing_context = _get_pricing_context(order.shop, order.customer)

    for x in range(n_lines):
        product_order_line = OrderLine(order=order)
        update_order_line_from_product(pricing_context,
                                       order_line=product_order_line,
                                       product=product,
                                       quantity=quantity,
                                       supplier=supplier)
        product_order_line.base_unit_price = order.shop.create_price(
            taxless_base_unit_price)
        product_order_line.save()
        product_order_line.taxes.add(
            OrderLineTax.from_tax(
                get_test_tax(tax_rate),
                product_order_line.taxless_price.amount,
                order_line=product_order_line,
            ))
    assert order.get_product_ids_and_quantities()[product.pk] == (
        quantity * n_lines), "Things got added"
    return order
Exemplo n.º 3
0
def create_order_with_product(
        product, supplier, quantity, taxless_base_unit_price, tax_rate=0, n_lines=1,
        shop=None):
    order = create_empty_order(shop=shop)
    order.full_clean()
    order.save()

    request = apply_request_middleware(RequestFactory().get("/"))
    request.shop = order.shop

    for x in range(n_lines):
        product_order_line = OrderLine(order=order)
        update_order_line_from_product(pricing_context=request,
                                       order_line=product_order_line,
                                       product=product, quantity=quantity,
                                       supplier=supplier)
        product_order_line.base_unit_price = order.shop.create_price(taxless_base_unit_price)
        product_order_line.save()
        product_order_line.taxes.add(OrderLineTax.from_tax(
            get_test_tax(tax_rate),
            product_order_line.taxless_price.amount,
            order_line=product_order_line,
        ))
    assert order.get_product_ids_and_quantities()[product.pk] == (quantity * n_lines), "Things got added"
    return order
Exemplo n.º 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!"
Exemplo n.º 5
0
def create_order_with_product(product, supplier, quantity, taxless_unit_price, tax_rate=0, n_lines=1):
    order = create_empty_order()
    order.full_clean()
    order.save()
    for x in range(n_lines):
        product_order_line = OrderLine(order=order)
        update_order_line_from_product(request=None, order_line=product_order_line, product=product, quantity=quantity,
                                       supplier=supplier)
        product_order_line.unit_price = TaxlessPrice(taxless_unit_price)
        product_order_line.save()
        product_order_line.taxes.add(
            OrderLineTax.from_tax(get_test_tax(tax_rate), product_order_line.taxless_total_price)
        )
    assert order.get_product_ids_and_quantities()[product.pk] == (quantity * n_lines), "Things got added"
    return order
Exemplo n.º 6
0
def add_product_to_order(order, supplier, product, quantity, taxless_base_unit_price, tax_rate=0, pricing_context=None):
    if not pricing_context:
        pricing_context = _get_pricing_context(order.shop, order.customer)
    product_order_line = OrderLine(order=order)
    update_order_line_from_product(pricing_context,
                                   order_line=product_order_line,
                                   product=product, quantity=quantity,
                                   supplier=supplier)
    product_order_line.base_unit_price = order.shop.create_price(taxless_base_unit_price)
    product_order_line.save()
    product_order_line.taxes.add(OrderLineTax.from_tax(
        get_test_tax(tax_rate),
        product_order_line.taxless_price.amount,
        order_line=product_order_line,
    ))
Exemplo n.º 7
0
def add_product_to_order(order, supplier, product, quantity, taxless_base_unit_price, tax_rate=0, pricing_context=None):
    if not pricing_context:
        pricing_context = _get_pricing_context(order.shop, order.customer)
    product_order_line = OrderLine(order=order)
    update_order_line_from_product(pricing_context,
                                   order_line=product_order_line,
                                   product=product, quantity=quantity,
                                   supplier=supplier)
    product_order_line.base_unit_price = order.shop.create_price(taxless_base_unit_price)
    product_order_line.save()
    product_order_line.taxes.add(OrderLineTax.from_tax(
        get_test_tax(tax_rate),
        product_order_line.taxless_price.amount,
        order_line=product_order_line,
    ))
Exemplo n.º 8
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!"
Exemplo n.º 9
0
 def create_package_children(self, order_line):
     order = order_line.order
     if order_line.product and order_line.product.mode == ProductMode.PACKAGE_PARENT:
         for child_product, child_quantity in six.iteritems(order_line.product.get_package_child_to_quantity_map()):
             child_order_line = OrderLine(order=order, parent_line=order_line)
             update_order_line_from_product(
                 request=self.request,
                 order_line=child_order_line,
                 product=child_product,
                 quantity=(order_line.quantity * child_quantity),
             )
             # Package children are free
             assert child_order_line.unit_price.amount == 0
             child_order_line.source_line = order_line.source_line
             child_order_line.supplier = order_line.supplier
             self._check_orderability(child_order_line)
             yield child_order_line
Exemplo n.º 10
0
 def create_package_children(self, order_line):
     order = order_line.order
     if order_line.product and order_line.product.mode == ProductMode.PACKAGE_PARENT:
         for child_product, child_quantity in six.iteritems(
                 order_line.product.get_package_child_to_quantity_map()):
             child_order_line = OrderLine(order=order,
                                          parent_line=order_line)
             update_order_line_from_product(
                 request=self.request,
                 order_line=child_order_line,
                 product=child_product,
                 quantity=(order_line.quantity * child_quantity),
             )
             # Package children are free
             assert child_order_line.unit_price.amount == 0
             child_order_line.source_line = order_line.source_line
             child_order_line.supplier = order_line.supplier
             self._check_orderability(child_order_line)
             yield child_order_line
Exemplo n.º 11
0
    def create_package_children(self, order_line):
        order = order_line.order
        parent_product = order_line.product
        # :type parent_product: shoop.core.models.Product
        if not (parent_product and parent_product.is_package_parent()):
            return

        for child_product, child_quantity in six.iteritems(parent_product.get_package_child_to_quantity_map()):
            child_order_line = OrderLine(order=order, parent_line=order_line)
            update_order_line_from_product(
                pricing_context=self.request,
                order_line=child_order_line,
                product=child_product,
                quantity=(order_line.quantity * child_quantity),
            )
            # Package children are free
            assert child_order_line.base_unit_price.value == 0
            child_order_line.source_line = order_line.source_line
            child_order_line.supplier = order_line.supplier
            self._check_orderability(child_order_line)
            yield child_order_line
Exemplo n.º 12
0
    def create_package_children(self, order_line):
        order = order_line.order
        parent_product = order_line.product
        # :type parent_product: shoop.core.models.Product
        if not (parent_product and parent_product.is_package_parent()):
            return

        for child_product, child_quantity in six.iteritems(parent_product.get_package_child_to_quantity_map()):
            child_order_line = OrderLine(order=order, parent_line=order_line)
            update_order_line_from_product(
                request=self.request,
                order_line=child_order_line,
                product=child_product,
                quantity=(order_line.quantity * child_quantity),
            )
            # Package children are free
            assert child_order_line.unit_price.amount == 0
            child_order_line.source_line = order_line.source_line
            child_order_line.supplier = order_line.supplier
            self._check_orderability(child_order_line)
            yield child_order_line
Exemplo n.º 13
0
    def create_package_children(self, order_line):
        order = order_line.order
        parent_product = order_line.product
        # :type parent_product: shoop.core.models.Product
        if not (parent_product and parent_product.is_package_parent()):
            return

        child_to_quantity = parent_product.get_package_child_to_quantity_map()
        for (child_product, child_quantity) in child_to_quantity.items():
            child_order_line = OrderLine(order=order, parent_line=order_line)
            update_order_line_from_product(
                pricing_context=None,  # Will use zero price
                order_line=child_order_line,
                product=child_product,
                quantity=(order_line.quantity * child_quantity),
            )
            # Package children are free
            assert child_order_line.base_unit_price.value == 0
            child_order_line.source_line = None
            child_order_line.parent_source_line = order_line.source_line
            child_order_line.supplier = order_line.supplier
            self._check_orderability(child_order_line)
            yield child_order_line
Exemplo n.º 14
0
def create_order_with_product(product,
                              supplier,
                              quantity,
                              taxless_unit_price,
                              tax_rate=0,
                              n_lines=1):
    order = create_empty_order()
    order.full_clean()
    order.save()
    for x in range(n_lines):
        product_order_line = OrderLine(order=order)
        update_order_line_from_product(request=None,
                                       order_line=product_order_line,
                                       product=product,
                                       quantity=quantity,
                                       supplier=supplier)
        product_order_line.unit_price = TaxlessPrice(taxless_unit_price)
        product_order_line.save()
        product_order_line.taxes.add(
            OrderLineTax.from_tax(get_test_tax(tax_rate),
                                  product_order_line.taxless_total_price))
    assert order.get_product_ids_and_quantities()[product.pk] == (
        quantity * n_lines), "Things got added"
    return order
Exemplo n.º 15
0
def create_order(request, creator, customer, product):
    billing_address = get_address().to_immutable()
    shipping_address = get_address(name="Shippy Doge").to_immutable()
    shipping_address.save()
    shop = request.shop
    order = Order(
        creator=creator,
        customer=customer,
        shop=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(),
        currency=shop.currency,
        prices_include_tax=shop.prices_include_tax,
    )
    order.full_clean()
    order.save()
    supplier = get_default_supplier()
    product_order_line = OrderLine(order=order)
    update_order_line_from_product(
        pricing_context=request, order_line=product_order_line, product=product, quantity=5, supplier=supplier
    )
    product_order_line.base_unit_price = shop.create_price(100)
    assert product_order_line.price.value > 0
    product_order_line.save()

    line_tax = get_line_taxes_for(product_order_line)[0]

    product_order_line.taxes.add(
        OrderLineTax.from_tax(tax=line_tax.tax, base_amount=line_tax.base_amount, order_line=product_order_line)
    )

    discount_order_line = OrderLine(order=order, quantity=1, type=OrderLineType.OTHER)
    discount_order_line.discount_amount = shop.create_price(30)
    assert discount_order_line.discount_amount.value == 30
    assert discount_order_line.price.value == -30
    assert discount_order_line.base_unit_price.value == 0
    discount_order_line.save()

    order.cache_prices()
    order.check_all_verified()
    order.save()
    base = 5 * shop.create_price(100).amount
    discount = shop.create_price(30).amount
    tax_value = line_tax.amount
    if not order.prices_include_tax:
        assert order.taxless_total_price.amount == base - discount
        assert order.taxful_total_price.amount == base + tax_value - discount
    else:
        assert_almost_equal(order.taxless_total_price.amount, base - tax_value - discount)
        assert_almost_equal(order.taxful_total_price.amount, base - discount)

    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!"
Exemplo n.º 16
0
def create_order(request, creator, customer, product):
    billing_address = get_address().to_immutable()
    shipping_address = get_address(name="Shippy Doge").to_immutable()
    shipping_address.save()
    shop = request.shop
    order = Order(
        creator=creator,
        customer=customer,
        shop=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(),
        currency=shop.currency,
        prices_include_tax=shop.prices_include_tax,
    )
    order.full_clean()
    order.save()
    supplier = get_default_supplier()
    product_order_line = OrderLine(order=order)
    update_order_line_from_product(pricing_context=request,
                                   order_line=product_order_line,
                                   product=product,
                                   quantity=5,
                                   supplier=supplier)

    assert product_order_line.text == product.safe_translation_getter("name")
    product_order_line.base_unit_price = shop.create_price(100)
    assert product_order_line.price.value > 0
    product_order_line.save()

    line_tax = get_line_taxes_for(product_order_line)[0]

    product_order_line.taxes.add(
        OrderLineTax.from_tax(
            tax=line_tax.tax,
            base_amount=line_tax.base_amount,
            order_line=product_order_line,
        ))

    discount_order_line = OrderLine(order=order,
                                    quantity=1,
                                    type=OrderLineType.OTHER)
    discount_order_line.discount_amount = shop.create_price(30)
    assert discount_order_line.discount_amount.value == 30
    assert discount_order_line.price.value == -30
    assert discount_order_line.base_unit_price.value == 0
    discount_order_line.save()

    order.cache_prices()
    order.check_all_verified()
    order.save()
    base = 5 * shop.create_price(100).amount
    discount = shop.create_price(30).amount
    tax_value = line_tax.amount
    if not order.prices_include_tax:
        assert order.taxless_total_price.amount == base - discount
        assert order.taxful_total_price.amount == base + tax_value - discount
    else:
        assert_almost_equal(order.taxless_total_price.amount,
                            base - tax_value - discount)
        assert_almost_equal(order.taxful_total_price.amount, base - discount)

    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!"