本文整理汇总了Python中shuup.core.order_creator.OrderCreator.create_order方法的典型用法代码示例。如果您正苦于以下问题:Python OrderCreator.create_order方法的具体用法?Python OrderCreator.create_order怎么用?Python OrderCreator.create_order使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shuup.core.order_creator.OrderCreator
的用法示例。
在下文中一共展示了OrderCreator.create_order方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_order_creation_adds_usage
# 需要导入模块: from shuup.core.order_creator import OrderCreator [as 别名]
# 或者: from shuup.core.order_creator.OrderCreator import create_order [as 别名]
def test_order_creation_adds_usage(rf, admin_user):
request, shop, group = initialize_test(rf, False)
source = seed_source(admin_user)
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,
)
# add coupon
coupon = Coupon.objects.create(active=True, code="asdf")
campaign = BasketCampaign.objects.create(
active=True,
shop=shop,
name="test",
public_name="test",
coupon=coupon)
BasketDiscountPercentage.objects.create(campaign=campaign, discount_percentage="0.1")
source.add_code(coupon.code)
creator = OrderCreator()
creator.create_order(source)
assert CouponUsage.objects.count() == 1
示例2: test_order_creator_account_manager
# 需要导入模块: from shuup.core.order_creator import OrderCreator [as 别名]
# 或者: from shuup.core.order_creator.OrderCreator import create_order [as 别名]
def test_order_creator_account_manager():
company = create_random_company()
shop = get_shop(identifier="random-shop", enabled=True)
source = seed_source(create_random_user(), shop)
source.customer = company
source.add_line(
type=OrderLineType.PRODUCT,
product=get_default_product(),
supplier=get_default_supplier(),
quantity=1,
base_unit_price=source.create_price(10),
)
creator = OrderCreator()
order = creator.create_order(source)
assert order.account_manager is None # Company contact doesn't have account manager field
person = create_random_person()
person.account_manager = create_random_person()
person.save()
source = seed_source(create_random_user(), shop)
source.customer = person
source.add_line(
type=OrderLineType.PRODUCT,
product=get_default_product(),
supplier=get_default_supplier(),
quantity=1,
base_unit_price=source.create_price(10),
)
creator = OrderCreator()
order = creator.create_order(source)
assert order.account_manager is not None
assert order.account_manager == person.account_manager
with pytest.raises(ProtectedError):
person.account_manager.delete()
示例3: test_order_creator_with_package_product
# 需要导入模块: from shuup.core.order_creator import OrderCreator [as 别名]
# 或者: from shuup.core.order_creator.OrderCreator import create_order [as 别名]
def test_order_creator_with_package_product(rf, admin_user):
if "shuup.simple_supplier" not in settings.INSTALLED_APPS:
pytest.skip("Need shuup.simple_supplier in INSTALLED_APPS")
from shuup_tests.simple_supplier.utils import get_simple_supplier
shop = get_default_shop()
supplier = get_simple_supplier()
package_product = create_package_product("Package-Product-Test", shop=shop, supplier=supplier,
children=2)
shop_product = package_product.get_shop_instance(shop)
quantity_map = package_product.get_package_child_to_quantity_map()
product_1, product_2 = quantity_map.keys()
product_1.stock_behavior = StockBehavior.STOCKED
product_1.save()
product_2.stock_behavior = StockBehavior.STOCKED
product_2.save()
assert quantity_map[product_1] == 1
assert quantity_map[product_2] == 2
supplier.adjust_stock(product_1.pk, 1)
supplier.adjust_stock(product_2.pk, 2)
assert supplier.get_stock_status(product_1.pk).logical_count == 1
assert supplier.get_stock_status(product_2.pk).logical_count == 2
creator = OrderCreator()
# There should be no exception when creating order with only package product
source = seed_source(admin_user)
source.add_line(
type=OrderLineType.PRODUCT,
product=package_product,
supplier=supplier,
quantity=1,
base_unit_price=source.create_price(10),
)
order = creator.create_order(source)
# However, there should not be enough stock for both package and child products
source = seed_source(admin_user)
source.add_line(
type=OrderLineType.PRODUCT,
product=package_product,
supplier=supplier,
quantity=1,
base_unit_price=source.create_price(10),
)
source.add_line(
type=OrderLineType.PRODUCT,
product=product_1,
supplier=supplier,
quantity=1,
base_unit_price=source.create_price(10),
)
# And a validation error should be raised
with pytest.raises(ValidationError):
order = creator.create_order(source)
示例4: test_refunds_report
# 需要导入模块: from shuup.core.order_creator import OrderCreator [as 别名]
# 或者: from shuup.core.order_creator.OrderCreator import create_order [as 别名]
def test_refunds_report(rf):
shop = get_default_shop()
get_default_tax_class()
creator = OrderCreator()
source1 = seed_source()
source2 = seed_source()
source3 = seed_source()
source4 = seed_source()
order1 = creator.create_order(source1)
order2 = creator.create_order(source2)
order3 = creator.create_order(source3)
order4 = creator.create_order(source4)
# pay orders
[o.create_payment(o.taxful_total_price) for o in Order.objects.all()]
order1.create_full_refund()
order2.create_refund(
[{"line": order2.lines.first(), "amount": order2.taxful_total_price.amount * Decimal(0.5), "quantity": 1}]
)
order3.create_refund(
[{"line": order3.lines.first(), "amount": order3.taxful_total_price.amount * Decimal(0.3), "quantity": 1}]
)
order4.create_refund(
[{"line": order4.lines.first(), "amount": order4.taxful_total_price.amount * Decimal(0.1), "quantity": 1}]
)
total_refunded = (order1.get_total_refunded_amount() +
order2.get_total_refunded_amount() +
order3.get_total_refunded_amount() +
order4.get_total_refunded_amount())
data = {
"report": RefundedSalesReport.get_name(),
"shop": shop.pk,
"date_range": DateRangeChoices.ALL_TIME,
"writer": "json",
"force_download": 1,
}
report = RefundedSalesReport(**data)
writer = get_writer_instance(data["writer"])
response = writer.get_response(report=report)
if hasattr(response, "render"):
response.render()
json_data = json.loads(response.content.decode("utf-8"))
assert force_text(RefundedSalesReport.title) in json_data.get("heading")
data = json_data.get("tables")[0].get("data")
assert len(data) == 1
data = data[0]
expected_data = {
"refunded_orders": "4",
"total_refunded": str(total_refunded.value)
}
for k, v in expected_data.items():
assert data[k] == v
示例5: _create_order
# 需要导入模块: from shuup.core.order_creator import OrderCreator [as 别名]
# 或者: from shuup.core.order_creator.OrderCreator import create_order [as 别名]
def _create_order(request, customer, coupon, product, expected_product_price):
creator = OrderCreator(request)
shop = request.shop
request.basket = None
request.customer = customer
basket = get_basket(request)
basket.status = factories.get_initial_order_status()
basket.add_product(supplier=factories.get_default_supplier(), shop=shop, product=product, quantity=1)
basket.shipping_method = factories.get_shipping_method(shop=shop)
basket.payment_method = factories.get_payment_method(shop=shop)
basket.add_code(coupon)
assert basket.shop == request.shop
assert basket.customer == request.customer
assert product.get_price_info(request).price == expected_product_price
creator.create_order(basket)
示例6: get_order_and_source
# 需要导入模块: from shuup.core.order_creator import OrderCreator [as 别名]
# 或者: from shuup.core.order_creator.OrderCreator import create_order [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
示例7: test_campaign_with_coupons1
# 需要导入模块: from shuup.core.order_creator import OrderCreator [as 别名]
# 或者: from shuup.core.order_creator.OrderCreator import create_order [as 别名]
def test_campaign_with_coupons1(rf):
basket, dc, request, status = _init_basket_coupon_test(rf)
assert len(basket.get_final_lines()) == 3 # no discount was applied because coupon is required
basket.add_code(dc.code)
assert len(basket.get_final_lines()) == 4 # now basket has codes so they will be applied too
assert OrderLineType.DISCOUNT in [l.type for l in basket.get_final_lines()]
# Ensure codes persist between requests, so do what the middleware would, i.e.
basket.save()
# and then reload the basket:
del request.basket
basket = get_basket(request)
assert basket.codes == [dc.code]
assert len(basket.get_final_lines()) == 3 # now basket has codes so they will be applied too
assert OrderLineType.DISCOUNT in [l.type for l in basket.get_final_lines()]
basket.status = status
creator = OrderCreator(request)
order = creator.create_order(basket)
assert CouponUsage.objects.filter(order=order).count() == 1
assert CouponUsage.objects.filter(order=order, coupon__code=dc.code).count() == 1
示例8: create_order_from_state
# 需要导入模块: from shuup.core.order_creator import OrderCreator [as 别名]
# 或者: from shuup.core.order_creator.OrderCreator import create_order [as 别名]
def create_order_from_state(self, state, creator=None, ip_address=None):
"""
Create an order from a state dict unserialized from JSON.
:param state: State dictionary
:type state: dict
:param creator: Creator user
:type creator: django.contrib.auth.models.User|None
:param ip_address: Remote IP address (IPv4 or IPv6)
:type ip_address: str
:return: The created order, or None if something failed along the way
:rtype: Order|None
"""
source = self.create_source_from_state(
state, creator=creator, ip_address=ip_address, save=True)
# Then create an OrderCreator and try to get things done!
creator = OrderCreator()
try:
order = creator.create_order(order_source=source)
self._postprocess_order(order, state)
return order
except Exception as exc: # pragma: no cover
self.add_error(exc)
return
示例9: test_order_source_parentage
# 需要导入模块: from shuup.core.order_creator import OrderCreator [as 别名]
# 或者: from shuup.core.order_creator.OrderCreator import create_order [as 别名]
def test_order_source_parentage(rf, admin_user):
source = seed_source(admin_user)
product = get_default_product()
source.add_line(
type=OrderLineType.PRODUCT,
product=product,
supplier=get_default_supplier(),
quantity=1,
base_unit_price=source.create_price(10),
line_id="parent"
)
source.add_line(
type=OrderLineType.OTHER,
text="Child Line",
sku="KIDKIDKID",
quantity=1,
base_unit_price=source.create_price(5),
parent_line_id="parent"
)
creator = OrderCreator()
order = Order.objects.get(pk=creator.create_order(source).pk)
kid_line = order.lines.filter(sku="KIDKIDKID").first()
assert kid_line
assert kid_line.parent_line.product_id == product.pk
示例10: test_order_source_extra_data
# 需要导入模块: from shuup.core.order_creator import OrderCreator [as 别名]
# 或者: from shuup.core.order_creator.OrderCreator import create_order [as 别名]
def test_order_source_extra_data(rf, admin_user):
source = seed_source(admin_user)
product = get_default_product()
line1 = source.add_line(
type=OrderLineType.PRODUCT,
product=product,
supplier=get_default_supplier(),
quantity=1,
base_unit_price=source.create_price(10),
line_id="parent"
)
line2 = source.add_line(
type=OrderLineType.OTHER,
text="Child Line",
sku="KIDKIDKID",
quantity=1,
base_unit_price=source.create_price(5),
parent_line_id="parent"
)
creator = OrderCreator()
order = Order.objects.get(pk=creator.create_order(source).pk)
line_ids = [line.extra_data["source_line_id"] for line in order.lines.all()]
assert line1.line_id in line_ids
assert line2.line_id in line_ids
示例11: test_order_statuses
# 需要导入模块: from shuup.core.order_creator import OrderCreator [as 别名]
# 或者: from shuup.core.order_creator.OrderCreator import create_order [as 别名]
def test_order_statuses(admin_user):
create_default_order_statuses()
source = seed_source(admin_user)
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,
)
creator = OrderCreator()
order = creator.create_order(source)
# new order, status/role is new/initial
assert order.status.identifier == DefaultOrderStatus.INITIAL.value
assert order.status.role == OrderStatusRole.INITIAL
# FUTURE: order gets payment the status changes to processing/processing
total = order.taxful_total_price.amount
order.create_payment(total)
assert order.status.identifier == DefaultOrderStatus.INITIAL.value
assert order.status.role == OrderStatusRole.INITIAL
# FUTURE: order is fully shipped the status changes to complete/complete
order.create_shipment_of_all_products()
assert order.status.identifier == DefaultOrderStatus.INITIAL.value
assert order.status.role == OrderStatusRole.INITIAL
示例12: test_order_creator
# 需要导入模块: from shuup.core.order_creator import OrderCreator [as 别名]
# 或者: from shuup.core.order_creator.OrderCreator import create_order [as 别名]
def test_order_creator(rf, admin_user):
source = seed_source(admin_user)
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,
)
creator = OrderCreator()
order = creator.create_order(source)
assert get_data_dict(source.billing_address) == get_data_dict(order.billing_address)
assert get_data_dict(source.shipping_address) == get_data_dict(order.shipping_address)
customer = source.customer
assert customer == order.customer
assert customer.groups.count() == 1
assert customer.groups.first() == order.customer_groups.first()
assert customer.tax_group is not None
assert customer.tax_group == order.tax_group
assert source.payment_method == order.payment_method
assert source.shipping_method == order.shipping_method
assert order.pk
示例13: _get_order_with_coupon
# 需要导入模块: from shuup.core.order_creator import OrderCreator [as 别名]
# 或者: from shuup.core.order_creator.OrderCreator import create_order [as 别名]
def _get_order_with_coupon(request, initial_status, condition_product_count=1):
shop = request.shop
basket = get_basket(request)
supplier = get_default_supplier()
product = create_product(printable_gibberish(), shop=shop, supplier=supplier, default_price="50")
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
basket.shipping_method = get_shipping_method(shop=shop) # For shippable products
dc = Coupon.objects.create(code="TEST", active=True)
campaign = BasketCampaign.objects.create(
shop=shop,
name="test",
public_name="test",
coupon=dc,
active=True
)
BasketDiscountAmount.objects.create(discount_amount=shop.create_price("20"), campaign=campaign)
rule = BasketTotalProductAmountCondition.objects.create(value=1)
campaign.conditions.add(rule)
campaign.save()
basket.add_code(dc.code)
basket.save()
basket.status = initial_status
creator = OrderCreator(request)
order = creator.create_order(basket)
assert order.lines.count() == 3
assert OrderLineType.DISCOUNT in [l.type for l in order.lines.all()]
return order
示例14: test_order_creator_company_multishop
# 需要导入模块: from shuup.core.order_creator import OrderCreator [as 别名]
# 或者: from shuup.core.order_creator.OrderCreator import create_order [as 别名]
def test_order_creator_company_multishop():
with override_settings(SHUUP_MANAGE_CONTACTS_PER_SHOP=True, SHUUP_ENABLE_MULTIPLE_SHOPS=True):
company = create_random_company()
shop = get_shop(identifier="random-shop", enabled=True)
source = seed_source(create_random_user(), shop)
source.customer = company
source.add_line(
type=OrderLineType.PRODUCT,
product=get_default_product(),
supplier=get_default_supplier(),
quantity=1,
base_unit_price=source.create_price(10),
)
creator = OrderCreator()
creator.create_order(source)
company.refresh_from_db()
assert shop in company.shops.all()
示例15: test_order_creator_can_deal_with_packages
# 需要导入模块: from shuup.core.order_creator import OrderCreator [as 别名]
# 或者: from shuup.core.order_creator.OrderCreator import create_order [as 别名]
def test_order_creator_can_deal_with_packages():
source = get_order_source_with_a_package()
package_product = source.get_lines()[0].product
package_def = package_product.get_package_child_to_quantity_map()
creator = OrderCreator()
order = creator.create_order(source)
pids_to_quantities = order.get_product_ids_and_quantities()
for child, quantity in six.iteritems(package_def):
assert pids_to_quantities[child.pk] == 10 * quantity