本文整理汇总了Python中shuup_tests.utils.basketish_order_source.BasketishOrderSource.shipping_method方法的典型用法代码示例。如果您正苦于以下问题:Python BasketishOrderSource.shipping_method方法的具体用法?Python BasketishOrderSource.shipping_method怎么用?Python BasketishOrderSource.shipping_method使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shuup_tests.utils.basketish_order_source.BasketishOrderSource
的用法示例。
在下文中一共展示了BasketishOrderSource.shipping_method方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_translations_of_method_and_component
# 需要导入模块: from shuup_tests.utils.basketish_order_source import BasketishOrderSource [as 别名]
# 或者: from shuup_tests.utils.basketish_order_source.BasketishOrderSource import shipping_method [as 别名]
def test_translations_of_method_and_component():
sm = get_shipping_method(name="Unique shipping")
sm.set_current_language('en')
sm.name = "Shipping"
sm.set_current_language('fi')
sm.name = "Toimitus"
sm.save()
cost = FixedCostBehaviorComponent.objects.language('fi').create(
price_value=10, description="kymppi")
cost.set_current_language('en')
cost.description = "ten bucks"
cost.save()
sm.behavior_components.add(cost)
source = BasketishOrderSource(get_default_shop())
source.shipping_method = sm
translation.activate('fi')
shipping_lines = [
line for line in source.get_final_lines()
if line.type == OrderLineType.SHIPPING]
assert len(shipping_lines) == 1
assert shipping_lines[0].text == 'Toimitus: kymppi'
translation.activate('en')
source.uncache()
shipping_lines = [
line for line in source.get_final_lines()
if line.type == OrderLineType.SHIPPING]
assert len(shipping_lines) == 1
assert shipping_lines[0].text == 'Shipping: ten bucks'
示例2: test_source_lines_with_multiple_fixed_costs
# 需要导入模块: from shuup_tests.utils.basketish_order_source import BasketishOrderSource [as 别名]
# 或者: from shuup_tests.utils.basketish_order_source.BasketishOrderSource import shipping_method [as 别名]
def test_source_lines_with_multiple_fixed_costs():
"""
Costs with description creates new line always and costs without
description is combined into one line.
"""
translation.activate("en")
starting_price_value = 5
sm = get_shipping_method(name="Multiple costs", price=starting_price_value)
sm.behavior_components.clear()
source = BasketishOrderSource(get_default_shop())
source.shipping_method = sm
lines = list(sm.get_lines(source))
assert len(lines) == 1
assert get_total_price_value(lines) == Decimal("0")
sm.behavior_components.add(FixedCostBehaviorComponent.objects.create(price_value=10))
lines = list(sm.get_lines(source))
assert len(lines) == 1
assert get_total_price_value(lines) == Decimal("10")
sm.behavior_components.add(FixedCostBehaviorComponent.objects.create(price_value=15, description="extra"))
lines = list(sm.get_lines(source))
assert len(lines) == 2
assert get_total_price_value(lines) == Decimal("25")
sm.behavior_components.add(FixedCostBehaviorComponent.objects.create(price_value=1))
lines = list(sm.get_lines(source))
assert len(lines) == 2
assert get_total_price_value(lines) == Decimal("26")
示例3: get_order_and_source
# 需要导入模块: from shuup_tests.utils.basketish_order_source import BasketishOrderSource [as 别名]
# 或者: from shuup_tests.utils.basketish_order_source.BasketishOrderSource import shipping_method [as 别名]
def get_order_and_source(admin_user, product):
# 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=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
示例4: seed_source
# 需要导入模块: from shuup_tests.utils.basketish_order_source import BasketishOrderSource [as 别名]
# 或者: from shuup_tests.utils.basketish_order_source.BasketishOrderSource import shipping_method [as 别名]
def seed_source(user, shop):
source = BasketishOrderSource(shop)
source.status = get_initial_order_status()
source.customer = get_person_contact(user)
source.payment_method = get_default_payment_method()
source.shipping_method = get_default_shipping_method()
return source
示例5: test_methods_impossible
# 需要导入模块: from shuup_tests.utils.basketish_order_source import BasketishOrderSource [as 别名]
# 或者: from shuup_tests.utils.basketish_order_source.BasketishOrderSource import shipping_method [as 别名]
def test_methods_impossible(admin_user):
contact = get_person_contact(admin_user)
source = BasketishOrderSource(get_default_shop())
default_product = get_default_product()
default_product.width = 5000
default_product.depth = 4000
default_product.heith = 1300
default_product.save()
source.add_line(
type=OrderLineType.PRODUCT,
product=default_product,
supplier=get_default_supplier(),
quantity=1,
base_unit_price=source.create_price(10),
weight=Decimal("200"))
billing_address = get_address()
shipping_address = get_address(name="My House", country='BR')
shipping_address.postal_code = "89070210"
source.billing_address = billing_address
source.shipping_address = shipping_address
source.customer = contact
source.shipping_method = get_correios_carrier_1()
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())
assert len(errors) == 1
示例6: seed_source
# 需要导入模块: from shuup_tests.utils.basketish_order_source import BasketishOrderSource [as 别名]
# 或者: from shuup_tests.utils.basketish_order_source.BasketishOrderSource import shipping_method [as 别名]
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
示例7: get_source
# 需要导入模块: from shuup_tests.utils.basketish_order_source import BasketishOrderSource [as 别名]
# 或者: from shuup_tests.utils.basketish_order_source.BasketishOrderSource import shipping_method [as 别名]
def get_source(admin_user, service):
contact = get_person_contact(admin_user)
source = BasketishOrderSource(get_default_shop())
billing_address = get_address()
shipping_address = get_address(name="My House", country='BR')
source.billing_address = billing_address
source.shipping_address = shipping_address
source.customer = contact
source.shipping_method = service.carrier
source.payment_method = get_payment_method(name="neat", price=4)
return source
示例8: test_fixed_cost_with_waiving_costs
# 需要导入模块: from shuup_tests.utils.basketish_order_source import BasketishOrderSource [as 别名]
# 或者: from shuup_tests.utils.basketish_order_source.BasketishOrderSource import shipping_method [as 别名]
def test_fixed_cost_with_waiving_costs():
sm = get_shipping_method(name="Fixed and waiving", price=5)
sm.behavior_components.add(
*[WaivingCostBehaviorComponent.objects.create(
price_value=p, waive_limit_value=w)
for (p, w) in [(3, 5), (7, 10), (10, 30)]])
source = BasketishOrderSource(get_default_shop())
source.shipping_method = sm
def pricestr(pi):
assert pi.price.unit_matches_with(source.create_price(0))
return "%.0f EUR (%.0f EUR)" % (pi.price.value, pi.base_price.value)
assert pricestr(sm.get_total_cost(source)) == "25 EUR (25 EUR)"
assert source.total_price.value == 25
source.add_line(
type=OrderLineType.PRODUCT, product=get_default_product(),
base_unit_price=source.create_price(2), quantity=1)
assert pricestr(sm.get_total_cost(source)) == "25 EUR (25 EUR)"
assert source.total_price.value == 27
source.add_line(
type=OrderLineType.PRODUCT, product=get_default_product(),
base_unit_price=source.create_price(3), quantity=1)
assert pricestr(sm.get_total_cost(source)) == "22 EUR (25 EUR)"
assert source.total_price.value == 27
source.add_line(
type=OrderLineType.PRODUCT, product=get_default_product(),
base_unit_price=source.create_price(10), quantity=1)
assert pricestr(sm.get_total_cost(source)) == "15 EUR (25 EUR)"
assert source.total_price.value == 30
source.add_line(
type=OrderLineType.PRODUCT, product=get_default_product(),
base_unit_price=source.create_price(10), quantity=1)
assert pricestr(sm.get_total_cost(source)) == "15 EUR (25 EUR)"
assert source.total_price.value == 40
source.add_line(
type=OrderLineType.PRODUCT, product=get_default_product(),
base_unit_price=source.create_price(10), quantity=1)
assert pricestr(sm.get_total_cost(source)) == "5 EUR (25 EUR)"
assert source.total_price.value == 40
示例9: test_methods
# 需要导入模块: from shuup_tests.utils.basketish_order_source import BasketishOrderSource [as 别名]
# 或者: from shuup_tests.utils.basketish_order_source.BasketishOrderSource import shipping_method [as 别名]
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)
示例10: test_methods_possible_no_shipping_address
# 需要导入模块: from shuup_tests.utils.basketish_order_source import BasketishOrderSource [as 别名]
# 或者: from shuup_tests.utils.basketish_order_source.BasketishOrderSource import shipping_method [as 别名]
def test_methods_possible_no_shipping_address(admin_user):
with patch.object(CorreiosWS, 'get_preco_prazo', return_value=MOCKED_SUCCESS_RESULT):
contact = get_person_contact(admin_user)
source = BasketishOrderSource(get_default_shop())
default_product = get_default_product()
default_product.width = 500
default_product.depth = 400
default_product.heith = 130
default_product.save()
source.add_line(
type=OrderLineType.PRODUCT,
product=default_product,
supplier=get_default_supplier(),
quantity=1,
base_unit_price=source.create_price(10),
weight=Decimal("0.2"))
billing_address = get_address(name="My House", country='BR')
billing_address.postal_code = "89070210"
source.billing_address = billing_address
source.shipping_address = None
source.customer = contact
source.shipping_method = get_correios_carrier_1()
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())
# no errors
assert len(errors) == 0
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:
assert line.text == "Correios - PAC #1"
# no billing addres also - no shipping
source.billing_address = None
list(source.get_final_lines())
示例11: seed_source
# 需要导入模块: from shuup_tests.utils.basketish_order_source import BasketishOrderSource [as 别名]
# 或者: from shuup_tests.utils.basketish_order_source.BasketishOrderSource import shipping_method [as 别名]
def seed_source(shipping_method=None, produce_price=10):
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 = create_random_person()
source.payment_method = get_default_payment_method()
source.shipping_method = shipping_method if shipping_method else 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(produce_price),
)
return source
示例12: seed_source
# 需要导入模块: from shuup_tests.utils.basketish_order_source import BasketishOrderSource [as 别名]
# 或者: from shuup_tests.utils.basketish_order_source.BasketishOrderSource import shipping_method [as 别名]
def seed_source(user, extra_addr=True):
source = BasketishOrderSource(get_default_shop())
billing_address = get_address()
shipping_address = get_address(name="Shippy Doge")
if extra_addr:
billing_address.extra = ExtraMutableAddress.from_data(EXTRA_MUTABLE_ADDRESS_1)
if extra_addr:
shipping_address.extra = ExtraMutableAddress.from_data(EXTRA_MUTABLE_ADDRESS_2)
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
示例13: get_order_and_source
# 需要导入模块: from shuup_tests.utils.basketish_order_source import BasketishOrderSource [as 别名]
# 或者: from shuup_tests.utils.basketish_order_source.BasketishOrderSource import shipping_method [as 别名]
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
示例14: test_broken_order
# 需要导入模块: from shuup_tests.utils.basketish_order_source import BasketishOrderSource [as 别名]
# 或者: from shuup_tests.utils.basketish_order_source.BasketishOrderSource import shipping_method [as 别名]
def test_broken_order(admin_user):
"""
"""
quantities = [44, 23, 65]
expected = sum(quantities) * 50
expected_based_on = expected / 1.5
# Shuup is calculating taxes per line so there will be some "errors"
expected_based_on = ensure_decimal_places(Decimal("%s" % (expected_based_on + 0.01)))
shop = get_default_shop()
supplier = get_default_supplier()
product1 = create_product("simple-test-product1", shop, supplier, 50)
product2 = create_product("simple-test-product2", shop, supplier, 50)
product3 = create_product("simple-test-product3", shop, supplier, 50)
tax = get_default_tax()
source = BasketishOrderSource(get_default_shop())
billing_address = get_address(country="US")
shipping_address = get_address(name="Test street", country="US")
source.status = get_initial_order_status()
source.billing_address = billing_address
source.shipping_address = shipping_address
source.customer = create_random_person()
source.payment_method = get_default_payment_method()
source.shipping_method = get_default_shipping_method()
source.add_line(
type=OrderLineType.PRODUCT,
product=product1,
supplier=get_default_supplier(),
quantity=quantities[0],
base_unit_price=source.create_price(50),
)
source.add_line(
type=OrderLineType.PRODUCT,
product=product2,
supplier=get_default_supplier(),
quantity=quantities[1],
base_unit_price=source.create_price(50),
)
source.add_line(
type=OrderLineType.PRODUCT,
product=product3,
supplier=get_default_supplier(),
quantity=quantities[2],
base_unit_price=source.create_price(50),
)
currency = "EUR"
summary = source.get_tax_summary()
assert len(summary) == 1
summary = summary[0]
assert summary.taxful == Money(expected, "EUR")
assert summary.based_on == Money(expected_based_on, "EUR")
# originally non-rounded value
assert bankers_round(source.get_total_tax_amount()) == summary.tax_amount
assert source.taxless_total_price.value == expected_based_on
assert summary.taxful.value == source.taxful_total_price.value
assert summary.tax_amount == Money(bankers_round(source.taxful_total_price.value - source.taxless_total_price.value), currency)
assert summary.taxful == summary.raw_based_on + summary.tax_amount
assert summary.tax_rate == tax.rate
assert summary.taxful.value == (summary.based_on + summary.tax_amount).value - Decimal("%s" % 0.01)
# create order from basket
creator = OrderCreator()
order = creator.create_order(source)
assert order.taxless_total_price.value == expected_based_on
# originally non-rounded value
assert bankers_round(order.get_total_tax_amount()) == summary.tax_amount