def create_order(self, order_source): data = self.get_source_base_data(order_source) order = Order(**data) order.save() order = self.finalize_creation(order, order_source) order_creator_finished.send(sender=type(self), order=order, source=order_source) return order
def create_order(self, order_source): data = self.get_source_base_data(order_source) order = Order(**data) order.save() order = self.finalize_creation(order, order_source) order_creator_finished.send(sender=type(self), order=order, source=order_source) # reset product prices for line in order.lines.exclude(product_id=None): context_cache.bump_cache_for_product(line.product, shop=order.shop) return order
def test_order_address_immutability_unsaved_address(save): billing_address = get_address() if save: billing_address.save() order = Order(shop=get_default_shop(), billing_address=billing_address.to_immutable(), order_date=now(), status=get_initial_order_status()) order.save() order.billing_address.name = "Mute Doge" with pytest.raises(ValidationError): order.billing_address.save()
def test_order_address_immutability_unsaved_address(save): billing_address = get_address() if save: billing_address.save() order = Order( shop=get_default_shop(), billing_address=billing_address.to_immutable(), order_date=now(), status=get_initial_order_status() ) order.save() order.billing_address.name = "Mute Doge" with pytest.raises(ValidationError): order.billing_address.save()
def _get_order_and_order_line(request): order = Order( shop=request.shop, currency=request.shop.currency, prices_include_tax=request.shop.prices_include_tax, ) order.taxful_total_price = TaxfulPrice("100", request.shop.currency) order.taxless_total_price = TaxlessPrice("50", request.shop.currency) pi = _get_price_info(request.shop, Product(sku='6.0745'), quantity=2) return (order, OrderLine( order=order, base_unit_price=pi.base_unit_price, discount_amount=pi.discount_amount, quantity=pi.quantity, ))
def create_empty_order(prices_include_tax=False, shop=None): order = Order( shop=(shop or get_shop(prices_include_tax=prices_include_tax)), payment_method=get_default_payment_method(), shipping_method=get_default_shipping_method(), billing_address=get_address(name="Mony Doge").to_immutable(), shipping_address=get_address(name="Shippy Doge").to_immutable(), order_date=now(), status=get_initial_order_status()) return order
def _get_order_line(request): order = Order( shop=request.shop, currency=request.shop.currency, prices_include_tax=request.shop.prices_include_tax, ) pi = _get_price_info(request.shop, Product(sku='6.0745'), quantity=2) return OrderLine( order=order, base_unit_price=pi.base_unit_price, discount_amount=pi.discount_amount, quantity=pi.quantity, )
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] order_line_tax = OrderLineTax.from_tax( tax=line_tax.tax, base_amount=line_tax.base_amount, order_line=product_order_line, ) order_line_tax.save( ) # Save order_line_tax before linking to order_line.tax product_order_line.taxes.add(order_line_tax) 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() assert not order.can_set_complete() 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) assert not order.is_fully_shipped() shipment = order.create_shipment_of_all_products(supplier=supplier) assert order.is_fully_shipped() assert shipment.total_products == 5, "All products were shipped" assert shipment.weight == product.gross_weight * 5 / 1000, "Gravity works" assert not order.get_unshipped_products( ), "Nothing was left in the warehouse" assert order.can_set_complete() order.create_payment(order.taxful_total_price) assert order.is_paid() assert Order.objects.paid().filter( pk=order.pk).exists(), "It was paid! Honestly!" assert order.has_products()
def create_simple_order(request, creator, customer): 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() order.cache_prices() order.check_all_verified() order.save() return order
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() default_pm = get_default_payment_method() default_sm = get_default_shipping_method() shop = request.shop order = Order( creator=creator, customer=customer, shop=shop, payment_method=default_pm, shipping_method=default_sm, 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] order_line_tax = OrderLineTax.from_tax( tax=line_tax.tax, base_amount=line_tax.base_amount, order_line=product_order_line, ) order_line_tax.save() # Save order_line_tax before linking to order_line.tax product_order_line.taxes.add(order_line_tax) 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() assert not order.can_set_complete() 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) assert not order.is_fully_shipped() shipment = order.create_shipment_of_all_products(supplier=supplier) assert order.is_fully_shipped() assert shipment.total_products == 5, "All products were shipped" assert shipment.weight == product.gross_weight * 5 / 1000, "Gravity works" assert not order.get_unshipped_products(), "Nothing was left in the warehouse" assert order.can_set_complete() order.create_payment(order.taxful_total_price) assert order.is_paid() assert Order.objects.paid().filter(pk=order.pk).exists(), "It was paid! Honestly!" assert order.has_products() assert order.get_available_shipping_methods() assert order.get_available_payment_methods() assert default_sm in order.get_available_shipping_methods() assert default_pm in order.get_available_payment_methods()