本文整理汇总了Python中shoop.core.models.OrderLine类的典型用法代码示例。如果您正苦于以下问题:Python OrderLine类的具体用法?Python OrderLine怎么用?Python OrderLine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OrderLine类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: create_order_with_product
def create_order_with_product(
product, supplier, quantity, taxless_base_unit_price, tax_rate=0, n_lines=1,
shop=None):
order = create_empty_order(shop=shop)
order.full_clean()
order.save()
request = apply_request_middleware(RequestFactory().get("/"))
request.shop = order.shop
for x in range(n_lines):
product_order_line = OrderLine(order=order)
update_order_line_from_product(pricing_context=request,
order_line=product_order_line,
product=product, quantity=quantity,
supplier=supplier)
product_order_line.base_unit_price = order.shop.create_price(taxless_base_unit_price)
product_order_line.save()
product_order_line.taxes.add(OrderLineTax.from_tax(
get_test_tax(tax_rate),
product_order_line.taxless_price.amount,
order_line=product_order_line,
))
assert order.get_product_ids_and_quantities()[product.pk] == (quantity * n_lines), "Things got added"
return order
开发者ID:hitchhooker,项目名称:shoop,代码行数:25,代码来源:factories.py
示例2: create_order_with_product
def create_order_with_product(product, supplier, quantity, taxless_unit_price, tax_rate=0, n_lines=1):
order = create_empty_order()
order.full_clean()
order.save()
for x in range(n_lines):
product_order_line = OrderLine(order=order)
update_order_line_from_product(request=None, order_line=product_order_line, product=product, quantity=quantity,
supplier=supplier)
product_order_line.unit_price = TaxlessPrice(taxless_unit_price)
product_order_line.save()
product_order_line.taxes.add(
OrderLineTax.from_tax(get_test_tax(tax_rate), product_order_line.taxless_total_price)
)
assert order.get_product_ids_and_quantities()[product.pk] == (quantity * n_lines), "Things got added"
return order
开发者ID:charn,项目名称:shoop,代码行数:15,代码来源:factories.py
示例3: add_product_to_order
def add_product_to_order(order, supplier, product, quantity, taxless_base_unit_price, tax_rate=0, pricing_context=None):
if not pricing_context:
pricing_context = _get_pricing_context(order.shop, order.customer)
product_order_line = OrderLine(order=order)
update_order_line_from_product(pricing_context,
order_line=product_order_line,
product=product, quantity=quantity,
supplier=supplier)
product_order_line.base_unit_price = order.shop.create_price(taxless_base_unit_price)
product_order_line.save()
product_order_line.taxes.add(OrderLineTax.from_tax(
get_test_tax(tax_rate),
product_order_line.taxless_price.amount,
order_line=product_order_line,
))
开发者ID:00WhengWheng,项目名称:shuup,代码行数:15,代码来源:factories.py
示例4: test_basic_order
def test_basic_order():
PRODUCTS_TO_SEND = 10
product = get_default_product()
supplier = get_default_supplier()
order = create_order_with_product(
product,
supplier=supplier,
quantity=PRODUCTS_TO_SEND,
taxless_base_unit_price=10,
tax_rate=Decimal("0.5")
)
assert order.shop.prices_include_tax is False
price = order.shop.create_price
currency = order.currency
discount_order_line = OrderLine(order=order, quantity=1, type=OrderLineType.OTHER)
discount_order_line.discount_amount = price(30)
assert discount_order_line.total_price == price(-30)
discount_order_line.save()
order.cache_prices()
order.check_all_verified()
order.save()
assert order.taxful_total_price == TaxfulPrice(PRODUCTS_TO_SEND * (10 + 5) - 30, currency)
shipment = order.create_shipment_of_all_products(supplier=supplier)
assert shipment.total_products == PRODUCTS_TO_SEND, "All products were shipped"
assert shipment.weight == product.net_weight * PRODUCTS_TO_SEND, "Gravity works"
assert not order.get_unshipped_products(), "Nothing was left in the warehouse"
order.shipping_status = ShippingStatus.FULLY_SHIPPED
order.create_payment(order.taxful_total_price)
assert order.payments.exists(), "A payment was created"
with pytest.raises(NoPaymentToCreateException):
order.create_payment(Money(6, currency))
assert order.is_paid(), "Order got paid"
assert order.can_set_complete(), "Finalization is possible"
order.status = OrderStatus.objects.get_default_complete()
assert order.is_complete(), "Finalization done"
summary = order.get_tax_summary()
assert len(summary) == 2
assert summary[0].tax_id is None
assert summary[0].tax_code == ''
assert summary[0].tax_amount == Money(0, currency)
assert summary[0].tax_rate == 0
assert summary[1].tax_rate * 100 == 50
assert summary[1].based_on == Money(100, currency)
assert summary[1].tax_amount == Money(50, currency)
assert summary[1].taxful == summary[1].based_on + summary[1].tax_amount
开发者ID:Jeewes,项目名称:shoop,代码行数:48,代码来源:test_orders.py
示例5: test_line_discount
def test_line_discount():
order = create_empty_order(prices_include_tax=False)
order.save()
currency = order.shop.currency
ol = OrderLine(order=order, type=OrderLineType.OTHER, quantity=5, text="Thing")
ol.discount_amount = order.shop.create_price(50)
ol.base_unit_price = order.shop.create_price(40)
ol.save()
ol.taxes.add(OrderLineTax.from_tax(get_default_tax(), ol.taxless_price.amount, order_line=ol))
assert ol.taxless_discount_amount == order.shop.create_price(50)
assert ol.taxful_discount_amount == TaxfulPrice(75, currency)
assert ol.taxless_price == order.shop.create_price(150)
assert ol.taxful_price == TaxfulPrice(150 + 75, currency)
assert ol.taxless_base_unit_price == order.shop.create_price(40)
assert ol.taxful_base_unit_price == TaxfulPrice(60, currency)
assert "Thing" in six.text_type(ol)
开发者ID:taedori81,项目名称:shoop,代码行数:16,代码来源:test_orders.py
示例6: create_package_children
def create_package_children(self, order_line):
order = order_line.order
if order_line.product and order_line.product.mode == ProductMode.PACKAGE_PARENT:
for child_product, child_quantity in six.iteritems(order_line.product.get_package_child_to_quantity_map()):
child_order_line = OrderLine(order=order, parent_line=order_line)
update_order_line_from_product(
request=self.request,
order_line=child_order_line,
product=child_product,
quantity=(order_line.quantity * child_quantity),
)
# Package children are free
assert child_order_line.unit_price.amount == 0
child_order_line.source_line = order_line.source_line
child_order_line.supplier = order_line.supplier
self._check_orderability(child_order_line)
yield child_order_line
开发者ID:charn,项目名称:shoop,代码行数:17,代码来源:creator.py
示例7: test_line_discount
def test_line_discount():
order = create_empty_order()
order.save()
ol = OrderLine(
order=order,
type=OrderLineType.OTHER,
quantity=5,
text="Thing"
)
ol.total_discount = TaxlessPrice(50)
ol.unit_price = TaxlessPrice(40)
ol.save()
ol.taxes.add(OrderLineTax.from_tax(get_default_tax(), ol.taxless_total_price))
assert ol.taxless_total_discount == TaxlessPrice(50)
assert ol.taxful_total_discount == TaxfulPrice(75)
assert ol.taxless_total_price == TaxlessPrice(150)
assert ol.taxful_total_price == TaxfulPrice(150 + 75)
assert ol.taxless_unit_price == TaxlessPrice(40)
assert ol.taxful_unit_price == TaxfulPrice(60)
assert "Thing" in six.text_type(ol)
开发者ID:charn,项目名称:shoop,代码行数:20,代码来源:test_orders.py
示例8: create_package_children
def create_package_children(self, order_line):
order = order_line.order
parent_product = order_line.product
# :type parent_product: shoop.core.models.Product
if not (parent_product and parent_product.is_package_parent()):
return
for child_product, child_quantity in six.iteritems(parent_product.get_package_child_to_quantity_map()):
child_order_line = OrderLine(order=order, parent_line=order_line)
update_order_line_from_product(
pricing_context=self.request,
order_line=child_order_line,
product=child_product,
quantity=(order_line.quantity * child_quantity),
)
# Package children are free
assert child_order_line.base_unit_price.value == 0
child_order_line.source_line = order_line.source_line
child_order_line.supplier = order_line.supplier
self._check_orderability(child_order_line)
yield child_order_line
开发者ID:luizgustavo90,项目名称:shoop,代码行数:21,代码来源:_creator.py
示例9: create_order
def create_order(request, creator, customer, product):
billing_address = get_address()
shipping_address = get_address(name="Shippy Doge")
shipping_address.save()
order = Order(
creator=creator,
customer=customer,
shop=get_default_shop(),
payment_method=get_default_payment_method(),
shipping_method=get_default_shipping_method(),
billing_address=billing_address,
shipping_address=shipping_address,
order_date=now(),
status=get_initial_order_status()
)
order.full_clean()
order.save()
supplier = get_default_supplier()
product_order_line = OrderLine(order=order)
update_order_line_from_product(order_line=product_order_line, product=product, request=request, quantity=5, supplier=supplier)
product_order_line.unit_price = TaxlessPrice(100)
assert product_order_line.taxful_total_price.amount > 0
product_order_line.save()
product_order_line.taxes.add(OrderLineTax.from_tax(get_default_tax(), product_order_line.taxless_total_price))
discount_order_line = OrderLine(order=order, quantity=1, type=OrderLineType.OTHER)
discount_order_line.total_discount = TaxfulPrice(30)
assert discount_order_line.taxful_total_discount.amount == 30
assert discount_order_line.taxful_total_price.amount == -30
assert discount_order_line.taxful_unit_price.amount == 0
discount_order_line.save()
order.cache_prices()
order.check_all_verified()
order.save()
base_amount = 5 * 100
tax_value = get_default_tax().calculate_amount(base_amount)
assert order.taxful_total_price == base_amount + tax_value - 30, "Math works"
shipment = order.create_shipment_of_all_products(supplier=supplier)
assert shipment.total_products == 5, "All products were shipped"
assert shipment.weight == product.net_weight * 5, "Gravity works"
assert not order.get_unshipped_products(), "Nothing was left in the warehouse"
order.create_payment(order.taxful_total_price)
assert order.is_paid()
assert Order.objects.paid().filter(pk=order.pk).exists(), "It was paid! Honestly!"
开发者ID:charn,项目名称:shoop,代码行数:47,代码来源:test_basic_order.py
示例10: test_line_discount_more
def test_line_discount_more():
order = create_empty_order()
order.save()
ol = OrderLine(order=order, type=OrderLineType.OTHER)
ol.quantity = 5
ol.unit_price = TaxlessPrice(30)
ol.total_discount = TaxlessPrice(50)
ol.save()
assert ol.taxless_unit_price == TaxlessPrice(30)
assert ol.taxless_total_discount == TaxlessPrice(50)
assert ol.taxless_total_price == TaxlessPrice(5 * 30 - 50)
ol.taxes.add(OrderLineTax.from_tax(get_default_tax(), ol.taxless_total_price))
assert ol.taxless_total_discount == TaxlessPrice(50)
assert ol.taxful_total_discount == TaxfulPrice(75)
assert ol.taxless_total_price == TaxlessPrice(100)
assert ol.taxful_total_price == TaxfulPrice(150)
assert ol.taxless_unit_price == TaxlessPrice(30)
assert ol.taxful_unit_price == TaxfulPrice(45)
开发者ID:charn,项目名称:shoop,代码行数:18,代码来源:test_orders.py
示例11: test_line_discount_more
def test_line_discount_more():
order = create_empty_order()
order.save()
ol = OrderLine(order=order, type=OrderLineType.OTHER)
ol.quantity = 5
ol.base_unit_price = order.shop.create_price(30)
ol.discount_amount = order.shop.create_price(50)
ol.save()
currency = order.shop.currency
assert ol.taxless_base_unit_price == TaxlessPrice(30, currency)
assert ol.taxless_discount_amount == TaxlessPrice(50, currency)
assert ol.taxless_price == TaxlessPrice(5 * 30 - 50, currency)
ol.taxes.add(OrderLineTax.from_tax(get_default_tax(), ol.taxless_price.amount, order_line=ol))
assert ol.taxless_discount_amount == TaxlessPrice(50, currency)
assert ol.taxful_discount_amount == TaxfulPrice(75, currency)
assert ol.taxless_price == TaxlessPrice(100, currency)
assert ol.taxful_price == TaxfulPrice(150, currency)
assert ol.taxless_base_unit_price == TaxlessPrice(30, currency)
assert ol.taxful_base_unit_price == TaxfulPrice(45, currency)
开发者ID:taedori81,项目名称:shoop,代码行数:19,代码来源:test_orders.py
示例12: create_order
def create_order(request, creator, customer, product):
billing_address = get_address().to_immutable()
shipping_address = get_address(name="Shippy Doge").to_immutable()
shipping_address.save()
shop = request.shop
order = Order(
creator=creator,
customer=customer,
shop=shop,
payment_method=get_default_payment_method(),
shipping_method=get_default_shipping_method(),
billing_address=billing_address,
shipping_address=shipping_address,
order_date=now(),
status=get_initial_order_status(),
currency=shop.currency,
prices_include_tax=shop.prices_include_tax,
)
order.full_clean()
order.save()
supplier = get_default_supplier()
product_order_line = OrderLine(order=order)
update_order_line_from_product(
pricing_context=request, order_line=product_order_line, product=product, quantity=5, supplier=supplier
)
product_order_line.base_unit_price = shop.create_price(100)
assert product_order_line.price.value > 0
product_order_line.save()
line_tax = get_line_taxes_for(product_order_line)[0]
product_order_line.taxes.add(
OrderLineTax.from_tax(tax=line_tax.tax, base_amount=line_tax.base_amount, order_line=product_order_line)
)
discount_order_line = OrderLine(order=order, quantity=1, type=OrderLineType.OTHER)
discount_order_line.discount_amount = shop.create_price(30)
assert discount_order_line.discount_amount.value == 30
assert discount_order_line.price.value == -30
assert discount_order_line.base_unit_price.value == 0
discount_order_line.save()
order.cache_prices()
order.check_all_verified()
order.save()
base = 5 * shop.create_price(100).amount
discount = shop.create_price(30).amount
tax_value = line_tax.amount
if not order.prices_include_tax:
assert order.taxless_total_price.amount == base - discount
assert order.taxful_total_price.amount == base + tax_value - discount
else:
assert_almost_equal(order.taxless_total_price.amount, base - tax_value - discount)
assert_almost_equal(order.taxful_total_price.amount, base - discount)
shipment = order.create_shipment_of_all_products(supplier=supplier)
assert shipment.total_products == 5, "All products were shipped"
assert shipment.weight == product.net_weight * 5, "Gravity works"
assert not order.get_unshipped_products(), "Nothing was left in the warehouse"
order.create_payment(order.taxful_total_price)
assert order.is_paid()
assert Order.objects.paid().filter(pk=order.pk).exists(), "It was paid! Honestly!"
开发者ID:taedori81,项目名称:shoop,代码行数:63,代码来源:test_basic_order.py
示例13: source_line_to_order_lines
def source_line_to_order_lines(self, order, source_line):
"""
Convert a SourceLine into one or more OrderLines (yield them)
:param order: The order
:param source_line: The SourceLine
"""
order_line = OrderLine(order=order)
product = source_line.product
quantity = Decimal(source_line.quantity)
if product:
order_line.product = product
if product.sales_unit:
quantized_quantity = bankers_round(quantity, product.sales_unit.decimals)
if quantized_quantity != quantity:
raise ValueError("Sales unit decimal conversion causes precision loss!")
else:
order_line.product = None
def text(value):
return force_text(value) if value is not None else ""
order_line.quantity = quantity
order_line.supplier = source_line.supplier
order_line.sku = text(source_line.sku)
order_line.text = (text(source_line.text))[:192]
if source_line.base_unit_price:
order_line.base_unit_price = source_line.base_unit_price
if source_line.discount_amount:
order_line.discount_amount = source_line.discount_amount
order_line.type = source_line.type if source_line.type is not None else OrderLineType.OTHER
order_line.accounting_identifier = text(source_line.accounting_identifier)
order_line.require_verification = bool(source_line.require_verification)
order_line.verified = False
order_line.source_line = source_line
self._check_orderability(order_line)
yield order_line
for child_order_line in self.create_package_children(order_line):
yield child_order_line
开发者ID:luizgustavo90,项目名称:shoop,代码行数:40,代码来源:_creator.py
示例14: source_line_to_order_lines
def source_line_to_order_lines(self, order, source_line):
"""
Convert a source line into one or more order lines.
Normally each source line will yield just one order line, but
package products will yield a parent line and its child lines.
:type order: shoop.core.models.Order
:param order: The order
:type source_line: shoop.core.order_creator.SourceLine
:param source_line: The SourceLine
:rtype: Iterable[OrderLine]
"""
order_line = OrderLine(order=order)
product = source_line.product
quantity = Decimal(source_line.quantity)
if product:
order_line.product = product
if product.sales_unit:
quantized_quantity = bankers_round(quantity, product.sales_unit.decimals)
if quantized_quantity != quantity:
raise ValueError("Sales unit decimal conversion causes precision loss!")
else:
order_line.product = None
def text(value):
return force_text(value) if value is not None else ""
order_line.quantity = quantity
order_line.supplier = source_line.supplier
order_line.sku = text(source_line.sku)
order_line.text = (text(source_line.text))[:192]
if source_line.base_unit_price:
order_line.base_unit_price = source_line.base_unit_price
if source_line.discount_amount:
order_line.discount_amount = source_line.discount_amount
order_line.type = (source_line.type if source_line.type is not None
else OrderLineType.OTHER)
order_line.accounting_identifier = text(source_line.accounting_identifier)
order_line.require_verification = bool(source_line.require_verification)
order_line.verified = (not order_line.require_verification)
order_line.source_line = source_line
order_line.parent_source_line = source_line.parent_line
self._check_orderability(order_line)
yield order_line
for child_order_line in self.create_package_children(order_line):
yield child_order_line
开发者ID:00WhengWheng,项目名称:shuup,代码行数:49,代码来源:_creator.py
注:本文中的shoop.core.models.OrderLine类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论