def get_order_and_source(admin_user, product, language, language_fallback): # create original source to tamper with contact = get_person_contact(admin_user) contact.language = language contact.save() assert contact.language == language # contact language is naive source = BasketishOrderSource(get_default_shop()) source.status = get_initial_order_status() source.billing_address = MutableAddress.objects.create( name="Original Billing") source.shipping_address = MutableAddress.objects.create( name="Original Shipping") source.customer = contact source.payment_method = get_default_payment_method() source.shipping_method = get_default_shipping_method() source.add_line( type=OrderLineType.PRODUCT, product=product, supplier=get_default_supplier(), quantity=1, base_unit_price=source.create_price(10), ) source.add_line( type=OrderLineType.OTHER, quantity=1, base_unit_price=source.create_price(10), require_verification=True, ) assert len(source.get_lines()) == 2 source.creator = admin_user assert not source._language # is None because it was not directly assigned assert source.language == language_fallback creator = OrderCreator() order = creator.create_order(source) assert order.language == source.language return order, source
def test_order_source_rounding(prices): shop = Shop.objects.create(name="test", identifier="test", status=ShopStatus.ENABLED, public_name="test", prices_include_tax=False) expected = 0 for p in prices: expected += bankers_round(p, 2) source = BasketishOrderSource(shop) for x, price in enumerate(prices): source.add_line( type=OrderLineType.OTHER, quantity=1, text=x, base_unit_price=source.create_price(price), ordering=x, ) for x, order_source in enumerate(source.get_lines()): price = Decimal(prices[x]).quantize(Decimal(".1")**9) # make sure prices are in database with original precision assert order_source.base_unit_price == source.shop.create_price(price) # make sure the line taxless price is rounded assert order_source.taxless_price == source.shop.create_price( bankers_round(price, 2)) # Check that total prices calculated from priceful parts still matches assert _get_taxless_price(order_source) == order_source.taxless_price assert _get_taxful_price(order_source) == order_source.taxful_price # make sure the line price is rounded assert order_source.price == source.shop.create_price(price) # make sure order total is rounded assert source.taxless_total_price == source.shop.create_price( bankers_round(expected, 2))