本文整理汇总了Python中shuup_tests.utils.basketish_order_source.BasketishOrderSource.add_line方法的典型用法代码示例。如果您正苦于以下问题:Python BasketishOrderSource.add_line方法的具体用法?Python BasketishOrderSource.add_line怎么用?Python BasketishOrderSource.add_line使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shuup_tests.utils.basketish_order_source.BasketishOrderSource
的用法示例。
在下文中一共展示了BasketishOrderSource.add_line方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_order_and_source
# 需要导入模块: from shuup_tests.utils.basketish_order_source import BasketishOrderSource [as 别名]
# 或者: from shuup_tests.utils.basketish_order_source.BasketishOrderSource import add_line [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
示例2: test_methods_impossible
# 需要导入模块: from shuup_tests.utils.basketish_order_source import BasketishOrderSource [as 别名]
# 或者: from shuup_tests.utils.basketish_order_source.BasketishOrderSource import add_line [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
示例3: test_weight_limits
# 需要导入模块: from shuup_tests.utils.basketish_order_source import BasketishOrderSource [as 别名]
# 或者: from shuup_tests.utils.basketish_order_source.BasketishOrderSource import add_line [as 别名]
def test_weight_limits():
carrier = CustomCarrier.objects.create()
sm = carrier.create_service(
None, shop=get_default_shop(), enabled=True,
tax_class=get_default_tax_class())
sm.behavior_components.add(
WeightLimitsBehaviorComponent.objects.create(
min_weight=100, max_weight=500))
source = BasketishOrderSource(get_default_shop())
assert any(ve.code == "min_weight" for ve in sm.get_unavailability_reasons(source))
source.add_line(type=OrderLineType.PRODUCT, weight=600)
assert any(ve.code == "max_weight" for ve in sm.get_unavailability_reasons(source))
示例4: test_waiver
# 需要导入模块: from shuup_tests.utils.basketish_order_source import BasketishOrderSource [as 别名]
# 或者: from shuup_tests.utils.basketish_order_source.BasketishOrderSource import add_line [as 别名]
def test_waiver():
sm = get_shipping_method(name="Waivey", price=100, waive_at=370)
source = BasketishOrderSource(get_default_shop())
assert sm.get_effective_name(source) == u"Waivey"
assert sm.get_total_cost(source).price == source.create_price(100)
source.add_line(
type=OrderLineType.PRODUCT,
product=get_default_product(),
base_unit_price=source.create_price(400),
quantity=1
)
assert sm.get_total_cost(source).price == source.create_price(0)
示例5: test_order_creator_parent_linkage
# 需要导入模块: from shuup_tests.utils.basketish_order_source import BasketishOrderSource [as 别名]
# 或者: from shuup_tests.utils.basketish_order_source.BasketishOrderSource import add_line [as 别名]
def test_order_creator_parent_linkage():
"""
Test OrderCreator creates parent links from OrderSource.
"""
source = BasketishOrderSource(get_default_shop())
source.status = get_initial_order_status()
source.add_line(line_id="LINE1", type=OrderLineType.OTHER, quantity=1, sku="parent", text="Parent line")
source.add_line(
line_id="LINE1.1",
parent_line_id="LINE1",
type=OrderLineType.OTHER,
quantity=1,
sku="child1.1",
text="Child line 1.1",
)
source.add_line(
line_id="LINE1.2",
parent_line_id="LINE1",
type=OrderLineType.OTHER,
quantity=1,
sku="child1.2",
text="Child line 1.2",
)
source.add_line(
line_id="LINE1.2.1",
parent_line_id="LINE1.2",
type=OrderLineType.OTHER,
quantity=1,
sku="child1.2.1",
text="Child line 1.2.1",
)
source.add_line(
line_id="LINE1.3",
parent_line_id="LINE1",
type=OrderLineType.OTHER,
quantity=1,
sku="child1.3",
text="Child line 1.3",
)
order = OrderCreator().create_order(source)
lines = [prettify_order_line(line) for line in order.lines.all()]
assert lines == [
"#0 1 x parent",
"#1 1 x child1.1, child of #0",
"#2 1 x child1.2, child of #0",
"#3 1 x child1.2.1, child of #2",
"#4 1 x child1.3, child of #0",
]
示例6: get_source
# 需要导入模块: from shuup_tests.utils.basketish_order_source import BasketishOrderSource [as 别名]
# 或者: from shuup_tests.utils.basketish_order_source.BasketishOrderSource import add_line [as 别名]
def get_source():
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),
)
source.add_line(
type=OrderLineType.OTHER,
quantity=1,
base_unit_price=source.create_price(10),
require_verification=True,
)
return source
示例7: get_order_source_with_a_package
# 需要导入模块: from shuup_tests.utils.basketish_order_source import BasketishOrderSource [as 别名]
# 或者: from shuup_tests.utils.basketish_order_source.BasketishOrderSource import add_line [as 别名]
def get_order_source_with_a_package():
package_product = get_package_product()
source = BasketishOrderSource(get_default_shop())
source.add_line(
type=OrderLineType.PRODUCT,
product=package_product,
supplier=get_default_supplier(),
quantity=10,
base_unit_price=source.create_price(10),
sku=package_product.sku,
text=package_product.name,
)
source.status = get_initial_order_status()
return source
示例8: _get_custom_order
# 需要导入模块: from shuup_tests.utils.basketish_order_source import BasketishOrderSource [as 别名]
# 或者: from shuup_tests.utils.basketish_order_source.BasketishOrderSource import add_line [as 别名]
def _get_custom_order(regular_user, **kwargs):
prices_include_tax = kwargs.pop("prices_include_tax", False)
include_basket_campaign = kwargs.pop("include_basket_campaign", False)
include_catalog_campaign = kwargs.pop("include_catalog_campaign", False)
shop = get_shop(prices_include_tax=prices_include_tax)
supplier = get_simple_supplier()
if include_basket_campaign:
_add_basket_campaign(shop)
if include_catalog_campaign:
_add_catalog_campaign(shop)
_add_taxes()
contact = get_person_contact(regular_user)
source = BasketishOrderSource(shop)
source.status = get_initial_order_status()
source.customer = contact
ctx = get_pricing_module().get_context_from_data(shop, contact)
for product_data in _get_product_data():
quantity = product_data.pop("quantity")
product = create_product(
sku=product_data.pop("sku"),
shop=shop,
supplier=supplier,
stock_behavior=StockBehavior.STOCKED,
tax_class=get_default_tax_class(),
**product_data)
shop_product = product.get_shop_instance(shop)
shop_product.categories.add(get_default_category())
shop_product.save()
supplier.adjust_stock(product.id, INITIAL_PRODUCT_QUANTITY)
pi = product.get_price_info(ctx)
source.add_line(
type=OrderLineType.PRODUCT,
product=product,
supplier=supplier,
quantity=quantity,
base_unit_price=pi.base_unit_price,
discount_amount=pi.discount_amount
)
oc = OrderCreator()
order = oc.create_order(source)
return order
示例9: 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 add_line [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
示例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 add_line [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: test_methods
# 需要导入模块: from shuup_tests.utils.basketish_order_source import BasketishOrderSource [as 别名]
# 或者: from shuup_tests.utils.basketish_order_source.BasketishOrderSource import add_line [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)
示例12: test_order_creator_parent_linkage
# 需要导入模块: from shuup_tests.utils.basketish_order_source import BasketishOrderSource [as 别名]
# 或者: from shuup_tests.utils.basketish_order_source.BasketishOrderSource import add_line [as 别名]
def test_order_creator_parent_linkage():
"""
Test OrderCreator creates parent links from OrderSource.
"""
source = BasketishOrderSource(get_default_shop())
source.status = get_initial_order_status()
source.add_line(
line_id='LINE1',
type=OrderLineType.OTHER, quantity=1,
sku='parent', text='Parent line',
)
source.add_line(
line_id='LINE1.1',
parent_line_id='LINE1',
type=OrderLineType.OTHER, quantity=1,
sku='child1.1', text='Child line 1.1',
)
source.add_line(
line_id='LINE1.2',
parent_line_id='LINE1',
type=OrderLineType.OTHER, quantity=1,
sku='child1.2', text='Child line 1.2',
)
source.add_line(
line_id='LINE1.2.1',
parent_line_id='LINE1.2',
type=OrderLineType.OTHER, quantity=1,
sku='child1.2.1', text='Child line 1.2.1',
)
source.add_line(
line_id='LINE1.3',
parent_line_id='LINE1',
type=OrderLineType.OTHER, quantity=1,
sku='child1.3', text='Child line 1.3',
)
order = OrderCreator().create_order(source)
lines = [prettify_order_line(line) for line in order.lines.all()]
assert lines == [
'#0 1 x parent',
'#1 1 x child1.1, child of #0',
'#2 1 x child1.2, child of #0',
'#3 1 x child1.2.1, child of #2',
'#4 1 x child1.3, child of #0',
]
示例13: seed_source
# 需要导入模块: from shuup_tests.utils.basketish_order_source import BasketishOrderSource [as 别名]
# 或者: from shuup_tests.utils.basketish_order_source.BasketishOrderSource import add_line [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
示例14: _get_order
# 需要导入模块: from shuup_tests.utils.basketish_order_source import BasketishOrderSource [as 别名]
# 或者: from shuup_tests.utils.basketish_order_source.BasketishOrderSource import add_line [as 别名]
def _get_order(prices_include_tax=False, include_basket_campaign=False, include_catalog_campaign=False):
shop = get_shop(prices_include_tax=prices_include_tax)
supplier = get_simple_supplier()
if include_basket_campaign:
_add_basket_campaign(shop)
if include_catalog_campaign:
_add_catalog_campaign(shop)
_add_taxes()
source = BasketishOrderSource(shop)
source.status = get_initial_order_status()
ctx = get_pricing_module().get_context_from_data(shop, AnonymousContact())
for product_data in _get_product_data():
quantity = product_data.pop("quantity")
product = create_product(
sku=product_data.pop("sku"),
shop=shop,
supplier=supplier,
stock_behavior=StockBehavior.STOCKED,
tax_class=get_default_tax_class(),
**product_data)
shop_product = product.get_shop_instance(shop)
shop_product.categories.add(get_default_category())
shop_product.save()
supplier.adjust_stock(product.id, INITIAL_PRODUCT_QUANTITY)
pi = product.get_price_info(ctx)
source.add_line(
type=OrderLineType.PRODUCT,
product=product,
supplier=supplier,
quantity=quantity,
base_unit_price=pi.base_unit_price,
discount_amount=pi.discount_amount
)
oc = OrderCreator()
order = oc.create_order(source)
order.create_payment(Money("1", "EUR"))
assert not order.has_refunds()
assert order.can_create_refund()
assert order.shipping_status == ShippingStatus.NOT_SHIPPED
assert order.payment_status == PaymentStatus.PARTIALLY_PAID
return order
示例15: get_order_and_source
# 需要导入模块: from shuup_tests.utils.basketish_order_source import BasketishOrderSource [as 别名]
# 或者: from shuup_tests.utils.basketish_order_source.BasketishOrderSource import add_line [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