本文整理汇总了Python中shoop.core.models.OrderLine.quantity方法的典型用法代码示例。如果您正苦于以下问题:Python OrderLine.quantity方法的具体用法?Python OrderLine.quantity怎么用?Python OrderLine.quantity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shoop.core.models.OrderLine
的用法示例。
在下文中一共展示了OrderLine.quantity方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: source_line_to_order_lines
# 需要导入模块: from shoop.core.models import OrderLine [as 别名]
# 或者: from shoop.core.models.OrderLine import quantity [as 别名]
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
示例2: test_line_discount_more
# 需要导入模块: from shoop.core.models import OrderLine [as 别名]
# 或者: from shoop.core.models.OrderLine import quantity [as 别名]
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)
示例3: test_line_discount_more
# 需要导入模块: from shoop.core.models import OrderLine [as 别名]
# 或者: from shoop.core.models.OrderLine import quantity [as 别名]
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)
示例4: source_line_to_order_lines
# 需要导入模块: from shoop.core.models import OrderLine [as 别名]
# 或者: from shoop.core.models.OrderLine import quantity [as 别名]
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