当前位置: 首页>>代码示例>>Python>>正文


Python OrderLine.source_line方法代码示例

本文整理汇总了Python中shoop.core.models.OrderLine.source_line方法的典型用法代码示例。如果您正苦于以下问题:Python OrderLine.source_line方法的具体用法?Python OrderLine.source_line怎么用?Python OrderLine.source_line使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在shoop.core.models.OrderLine的用法示例。


在下文中一共展示了OrderLine.source_line方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: source_line_to_order_lines

# 需要导入模块: from shoop.core.models import OrderLine [as 别名]
# 或者: from shoop.core.models.OrderLine import source_line [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
开发者ID:00WhengWheng,项目名称:shuup,代码行数:51,代码来源:_creator.py

示例2: create_package_children

# 需要导入模块: from shoop.core.models import OrderLine [as 别名]
# 或者: from shoop.core.models.OrderLine import source_line [as 别名]
 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,代码行数:19,代码来源:creator.py

示例3: source_line_to_order_lines

# 需要导入模块: from shoop.core.models import OrderLine [as 别名]
# 或者: from shoop.core.models.OrderLine import source_line [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
开发者ID:DemOneEh,项目名称:shoop,代码行数:43,代码来源:creator.py

示例4: create_package_children

# 需要导入模块: from shoop.core.models import OrderLine [as 别名]
# 或者: from shoop.core.models.OrderLine import source_line [as 别名]
    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,代码行数:23,代码来源:_creator.py


注:本文中的shoop.core.models.OrderLine.source_line方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。