def get_order_and_source(admin_user): # create original source to tamper with 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 = get_person_contact(admin_user) source.payment_method = get_default_payment_method() source.shipping_method = get_default_shipping_method() source.add_line( type=OrderLineType.PRODUCT, product=get_default_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 creator = OrderCreator() order = creator.create_order(source) return order, source
def get_order_and_source(admin_user): # create original source to tamper with 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 = get_person_contact(admin_user) source.payment_method = get_default_payment_method() source.shipping_method = get_default_shipping_method() source.add_line( type=OrderLineType.PRODUCT, product=get_default_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 creator = OrderCreator() order = creator.create_order(source) return order, source
def test_methods(admin_user, country): contact = get_person_contact(admin_user) source = BasketishOrderSource( lines=[ SourceLine( type=OrderLineType.PRODUCT, product=get_default_product(), supplier=get_default_supplier(), quantity=1, unit_price=TaxlessPrice(10), weight=Decimal("0.2"), ) ] ) billing_address = get_address() shipping_address = get_address(name="Shippy Doge", country=country) source.shop = get_default_shop() source.billing_address = billing_address source.shipping_address = shipping_address source.customer = contact with override_provides_for_expensive_sweden_shipping_method(): source.shipping_method = get_expensive_sweden_shipping_method() source.payment_method = PaymentMethod.objects.create( identifier="neat", module_data={"price": 4}, tax_class=get_default_tax_class() ) assert source.shipping_method_id assert source.payment_method_id errors = list(source.get_validation_errors()) if ( country == "FI" ): # "Expenseefe-a Svedee Sheepping" will not allow shipping to Finland, let's see if that holds true assert any([ve.code == "we_no_speak_finnish" for ve in errors]) return # Shouldn't try the rest if we got an error here else: assert not errors final_lines = list(source.get_final_lines()) assert any(line.type == OrderLineType.SHIPPING for line in final_lines) # TODO: (TAX) for some reason SourceLine.taxless_total_price property has been removed # I think it should be implemented back like in OrderLine / janne for line in final_lines: if line.type == OrderLineType.SHIPPING: if country == "SE": # We _are_ using Expenseefe-a Svedee Sheepping after all. assert line.taxless_total_price == TaxlessPrice("5.00") else: assert line.taxless_total_price == TaxlessPrice("4.00") assert line.text == u"Expenseefe-a Svedee Sheepping" if line.type == OrderLineType.PAYMENT: assert line.taxless_total_price == TaxlessPrice("4")
def seed_source(user): source = BasketishOrderSource(get_default_shop()) billing_address = get_address() shipping_address = get_address(name="Shippy Doge") source.status = get_initial_order_status() source.billing_address = billing_address source.shipping_address = shipping_address source.customer = get_person_contact(user) source.payment_method = get_default_payment_method() source.shipping_method = get_default_shipping_method() assert source.payment_method_id == get_default_payment_method().id assert source.shipping_method_id == get_default_shipping_method().id return source
def seed_source(user): source = BasketishOrderSource(get_default_shop()) billing_address = get_address() shipping_address = get_address(name="Shippy Doge") source.status = get_initial_order_status() source.billing_address = billing_address source.shipping_address = shipping_address source.customer = get_person_contact(user) source.payment_method = get_default_payment_method() source.shipping_method = get_default_shipping_method() assert source.payment_method_id == get_default_payment_method().id assert source.shipping_method_id == get_default_shipping_method().id return source
def test_methods(admin_user, country): contact = get_person_contact(admin_user) source = BasketishOrderSource(lines=[ SourceLine(type=OrderLineType.PRODUCT, product=get_default_product(), supplier=get_default_supplier(), quantity=1, unit_price=TaxlessPrice(10), weight=Decimal("0.2")) ]) billing_address = get_address() shipping_address = get_address(name="Shippy Doge", country=country) source.shop = get_default_shop() source.billing_address = billing_address source.shipping_address = shipping_address source.customer = contact with override_provides_for_expensive_sweden_shipping_method(): source.shipping_method = get_expensive_sweden_shipping_method() source.payment_method = PaymentMethod.objects.create( identifier="neat", module_data={"price": 4}, tax_class=get_default_tax_class()) assert source.shipping_method_id assert source.payment_method_id errors = list(source.get_validation_errors()) if country == "FI": # "Expenseefe-a Svedee Sheepping" will not allow shipping to Finland, let's see if that holds true assert any([ve.code == "we_no_speak_finnish" for ve in errors]) return # Shouldn't try the rest if we got an error here else: assert not errors final_lines = list(source.get_final_lines()) assert any(line.type == OrderLineType.SHIPPING for line in final_lines) # TODO: (TAX) for some reason SourceLine.taxless_total_price property has been removed # I think it should be implemented back like in OrderLine / janne for line in final_lines: if line.type == OrderLineType.SHIPPING: if country == "SE": # We _are_ using Expenseefe-a Svedee Sheepping after all. assert line.taxless_total_price == TaxlessPrice("5.00") else: assert line.taxless_total_price == TaxlessPrice("4.00") assert line.text == u"Expenseefe-a Svedee Sheepping" if line.type == OrderLineType.PAYMENT: assert line.taxless_total_price == TaxlessPrice("4")
def test_methods(admin_user, country): contact = get_person_contact(admin_user) source = BasketishOrderSource(get_default_shop()) source.add_line( type=OrderLineType.PRODUCT, product=get_default_product(), supplier=get_default_supplier(), quantity=1, base_unit_price=source.create_price(10), weight=Decimal("0.2") ) billing_address = get_address() shipping_address = get_address(name="Shippy Doge", country=country) source.billing_address = billing_address source.shipping_address = shipping_address source.customer = contact source.shipping_method = get_expensive_sweden_shipping_method() source.payment_method = get_payment_method(name="neat", price=4) assert source.shipping_method_id assert source.payment_method_id errors = list(source.get_validation_errors()) if country == "FI": # "Expenseefe-a Svedee Sheepping" will not allow shipping to # Finland, let's see if that holds true assert any([ve.code == "we_no_speak_finnish" for ve in errors]) assert [x.code for x in errors] == ["we_no_speak_finnish"] return # Shouldn't try the rest if we got an error here else: assert not errors final_lines = list(source.get_final_lines()) assert any(line.type == OrderLineType.SHIPPING for line in final_lines) for line in final_lines: if line.type == OrderLineType.SHIPPING: if country == "SE": # We _are_ using Expenseefe-a Svedee Sheepping after all. assert line.price == source.create_price("5.00") else: assert line.price == source.create_price("4.00") assert line.text == u"Expenseefe-a Svedee Sheepping" if line.type == OrderLineType.PAYMENT: assert line.price == source.create_price(4)