本文整理汇总了Python中shoop.core.order_creator.OrderCreator类的典型用法代码示例。如果您正苦于以下问题:Python OrderCreator类的具体用法?Python OrderCreator怎么用?Python OrderCreator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OrderCreator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _get_order_with_coupon
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)
dc = Coupon.objects.create(code="TEST", active=True)
campaign = BasketCampaign.objects.create(
shop=shop,
name="test",
public_name="test",
coupon=dc,
discount_amount_value=shop.create_price("20"),
active=True
)
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() == 2
assert OrderLineType.DISCOUNT in [l.type for l in order.lines.all()]
return order
开发者ID:NinaWelch,项目名称:shoop,代码行数:28,代码来源:test_order_edit_with_coupons.py
示例2: test_order_creation_adds_usage
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", discount_percentage="0.1", coupon=coupon
)
source.add_code(coupon.code)
request = apply_request_middleware(rf.get("/"))
creator = OrderCreator(request)
order = creator.create_order(source)
assert CouponUsage.objects.count() == 1
开发者ID:luizgustavo90,项目名称:shoop,代码行数:29,代码来源:test_basket_campaigns.py
示例3: create_random_order
def create_random_order(customer=None, products=(), completion_probability=0):
if not customer:
customer = Contact.objects.all().order_by("?").first()
if not customer:
raise ValueError("No valid contacts")
shop = get_default_shop()
request = apply_request_middleware(RequestFactory().get("/"),
customer=customer)
context = PriceTaxContext.from_request(request)
source = OrderSource()
source.customer = customer
source.customer_comment = "Mock Order"
if customer.default_billing_address and customer.default_shipping_address:
source.billing_address = customer.default_billing_address
source.shipping_address = customer.default_shipping_address
else:
source.billing_address = create_random_address()
source.shipping_address = create_random_address()
source.order_date = now() - datetime.timedelta(days=random.uniform(0, 400))
source.shop = shop
source.language = customer.language
source.status = get_initial_order_status()
if not products:
products = list(Product.objects.list_visible(source.shop, customer).order_by("?")[:40])
source.lines = []
for i in range(random.randint(3, 10)):
product = random.choice(products)
quantity = random.randint(1, 5)
price_info = product.get_price_info(context, quantity=quantity)
shop_product = product.get_shop_instance(source.shop)
supplier = shop_product.suppliers.first()
line = SourceLine(
type=OrderLineType.PRODUCT,
product=product,
supplier=supplier,
quantity=quantity,
unit_price=price_info.unit_base_price,
total_discount=price_info.discount_amount,
sku=product.sku,
text=product.safe_translation_getter("name", any_language=True)
)
assert line.total_price == price_info.price
source.lines.append(line)
with atomic():
oc = OrderCreator(request)
order = oc.create_order(source)
if random.random() < completion_probability:
order.create_shipment_of_all_products()
# also set complete
order.status = OrderStatus.objects.get_default_complete()
order.save(update_fields=("status",))
return order
开发者ID:US365,项目名称:shoop,代码行数:60,代码来源:factories.py
示例4: test_order_creator
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,
)
request = apply_request_middleware(rf.get("/"))
creator = OrderCreator(request)
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)
assert source.customer == order.customer
assert source.payment_method == order.payment_method
assert source.shipping_method == order.shipping_method
assert order.pk
开发者ID:DemOneEh,项目名称:shoop,代码行数:26,代码来源:test_order_creator.py
示例5: test_order_source_parentage
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"
)
request = apply_request_middleware(rf.get("/"))
creator = OrderCreator(request)
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
开发者ID:DemOneEh,项目名称:shoop,代码行数:26,代码来源:test_order_creator.py
示例6: get_order_and_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
开发者ID:00WhengWheng,项目名称:shuup,代码行数:27,代码来源:test_order_modifier.py
示例7: test_package
def test_package():
shop = get_default_shop()
supplier = get_default_supplier()
package_product = create_product("PackageParent", shop=shop, supplier=supplier)
assert not package_product.get_package_child_to_quantity_map()
children = [create_product("PackageChild-%d" % x, shop=shop, supplier=supplier) for x in range(4)]
package_def = {child: 1 + i for (i, child) in enumerate(children)}
package_product.make_package(package_def)
assert package_product.mode == ProductMode.PACKAGE_PARENT
package_product.save()
sp = package_product.get_shop_instance(shop)
assert not list(sp.get_orderability_errors(supplier=supplier, quantity=1, customer=AnonymousContact()))
with pytest.raises(ValueError): # Test re-packaging fails
package_product.make_package(package_def)
# Check that OrderCreator can deal with packages
source = BasketishOrderSource()
source.lines.append(SourceLine(
type=OrderLineType.PRODUCT,
product=package_product,
supplier=get_default_supplier(),
quantity=10,
unit_price=TaxlessPrice(10),
))
source.shop = get_default_shop()
source.status = get_initial_order_status()
creator = OrderCreator(request=None)
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
开发者ID:charn,项目名称:shoop,代码行数:34,代码来源:test_product_packages.py
示例8: create_order_from_state
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
开发者ID:Carolina061,项目名称:shoop,代码行数:25,代码来源:json_order_creator.py
示例9: test_order_creator_can_deal_with_packages
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
开发者ID:00WhengWheng,项目名称:shuup,代码行数:9,代码来源:test_product_packages.py
示例10: test_order_creator_supplierless_product_line_conversion_should_fail
def test_order_creator_supplierless_product_line_conversion_should_fail(admin_user):
source = seed_source(admin_user)
source.lines.append(SourceLine(
type=OrderLineType.PRODUCT,
product=get_default_product(),
supplier=None,
quantity=1,
unit_price=TaxlessPrice(10),
))
creator = OrderCreator(request=None)
with pytest.raises(ValueError):
order = creator.create_order(source)
开发者ID:charn,项目名称:shoop,代码行数:12,代码来源:test_order_creator.py
示例11: test_order_creator_supplierless_product_line_conversion_should_fail
def test_order_creator_supplierless_product_line_conversion_should_fail(rf, admin_user):
source = seed_source(admin_user)
source.add_line(
type=OrderLineType.PRODUCT,
product=get_default_product(),
supplier=None,
quantity=1,
base_unit_price=source.create_price(10),
)
creator = OrderCreator()
with pytest.raises(ValueError):
order = creator.create_order(source)
开发者ID:Carolina061,项目名称:shoop,代码行数:13,代码来源:test_order_creator.py
示例12: test_campaign_with_coupons
def test_campaign_with_coupons(rf):
status = get_initial_order_status()
request, shop, group = initialize_test(rf, False)
basket = get_basket(request)
supplier = get_default_supplier()
for x in range(2):
product = create_product(printable_gibberish(), shop, supplier=supplier, default_price="50")
basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
dc = Coupon.objects.create(code="TEST", active=True)
campaign = BasketCampaign.objects.create(
shop=shop,
name="test", public_name="test",
coupon=dc,
discount_amount_value=shop.create_price("20"),
active=True
)
rule = BasketTotalProductAmountCondition.objects.create(value=2)
campaign.conditions.add(rule)
campaign.save()
assert len(basket.get_final_lines()) == 2 # no discount was applied because coupon is required
basket.add_code(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()]
# 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
开发者ID:NinaWelch,项目名称:shoop,代码行数:44,代码来源:test_discount_codes.py
示例13: test_order_source_parentage
def test_order_source_parentage(admin_user):
source = seed_source(admin_user)
product = get_default_product()
source.lines.append(SourceLine(
type=OrderLineType.PRODUCT,
product=product,
supplier=get_default_supplier(),
quantity=1,
unit_price=TaxlessPrice(10),
line_id="parent"
))
source.lines.append(SourceLine(
type=OrderLineType.OTHER,
text="Child Line",
sku="KIDKIDKID",
quantity=1,
unit_price=TaxlessPrice(5),
parent_line_id="parent"
))
creator = OrderCreator(request=None)
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
开发者ID:charn,项目名称:shoop,代码行数:24,代码来源:test_order_creator.py
示例14: test_order_creator
def test_order_creator(admin_user):
source = seed_source(admin_user)
source.lines.append(SourceLine(
type=OrderLineType.PRODUCT,
product=get_default_product(),
supplier=get_default_supplier(),
quantity=1,
unit_price=TaxlessPrice(10),
))
source.lines.append(SourceLine(
type=OrderLineType.OTHER,
quantity=1,
unit_price=TaxlessPrice(10),
require_verification=True,
))
creator = OrderCreator(request=None)
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)
assert source.customer == order.customer
assert source.payment_method == order.payment_method
assert source.shipping_method == order.shipping_method
assert order.pk
开发者ID:charn,项目名称:shoop,代码行数:24,代码来源:test_order_creator.py
示例15: create_order_from_state
def create_order_from_state(self, state, creator=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
:return: The created order, or None if something failed along the way
:rtype: Order|None
"""
if not self.is_valid: # pragma: no cover
raise ValueError("Create a new JsonOrderCreator for each order.")
# We'll be mutating the state to make it easier to track we've done everything,
# so it's nice to deepcopy things first.
state = deepcopy(state)
# First, initialize an OrderSource.
source = self._initialize_source_from_state(state, creator)
if not source:
return None
# Then, copy some lines into it.
self._process_lines(source, state)
if not self.is_valid: # If we encountered any errors thus far, don't bother going forward
return None
# Then create an OrderCreator and try to get things done!
creator = OrderCreator(request=None)
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
开发者ID:hitchhooker,项目名称:shoop,代码行数:36,代码来源:json_order_creator.py
注:本文中的shoop.core.order_creator.OrderCreator类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论