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


Python Pool.products_by_location方法代码示例

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


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

示例1: get_quantity

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import products_by_location [as 别名]
    def get_quantity(cls, lines, name):
        Product = Pool().get('product.product')

        product_id = Transaction().context.get('product')
        warehouse_id = Transaction().context.get('warehouse')

        dates = sorted(l.date for l in lines)
        quantities = {}
        date_start = None
        for date in dates:
            context = {
                'stock_date_start': date_start,
                'stock_date_end': date,
                'forecast': True,
                }
            with Transaction().set_context(**context):
                quantities[date] = Product.products_by_location(
                    [warehouse_id], [product_id], with_childs=True,
                    skip_zero=False)[(warehouse_id, product_id)]
            try:
                date_start = date + datetime.timedelta(1)
            except OverflowError:
                pass
        cumulate = 0
        for date in dates:
            cumulate += quantities[date]
            quantities[date] = cumulate

        return dict((l.id, quantities[l.date]) for l in lines)
开发者ID:silpol,项目名称:tryton-bef,代码行数:31,代码来源:product.py

示例2: get_shortage

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import products_by_location [as 别名]
    def get_shortage(cls, location_id, product_ids, min_date, max_date,
            min_date_qties, order_points):
        """
        Return for each product the first date between min_date and max_date
        where the stock quantity is less than the minimal quantity and the
        smallest stock quantity in the interval or None if there is no date
        where stock quantity is less than the minimal quantity.

        The minimal quantity comes from the order point or is zero.

        min_date_qty is the quantities for each products at the min_date.
        order_points is a dictionary that links products to order point.
        """
        Product = Pool().get('product.product')

        res_dates = {}
        res_qties = {}

        min_quantities = {}
        for product_id in product_ids:
            order_point = order_points.get((location_id, product_id))
            if order_point:
                min_quantities[product_id] = order_point.min_quantity
            else:
                min_quantities[product_id] = 0.0

        current_date = min_date
        current_qties = min_date_qties.copy()
        while (current_date < max_date) or (current_date == min_date):
            for product_id in product_ids:
                current_qty = current_qties[product_id]
                min_quantity = min_quantities[product_id]
                res_qty = res_qties.get(product_id)
                res_date = res_dates.get(product_id)
                if current_qty < min_quantity:
                    if not res_date:
                        res_dates[product_id] = current_date
                    if (not res_qty) or (current_qty < res_qty):
                        res_qties[product_id] = current_qty

            if current_date == datetime.date.max:
                break
            current_date += datetime.timedelta(1)

            # Update current quantities with next moves
            with Transaction().set_context(forecast=True,
                    stock_date_start=current_date,
                    stock_date_end=current_date):
                pbl = Product.products_by_location([location_id],
                    product_ids, with_childs=True)
            for key, qty in pbl.iteritems():
                _, product_id = key
                current_qties[product_id] += qty

        return dict((x, (res_dates.get(x), res_qties.get(x)))
            for x in product_ids)
开发者ID:kret0s,项目名称:tryton3_8,代码行数:58,代码来源:purchase_request.py

示例3: parse

# 需要导入模块: from trytond.pool import Pool [as 别名]
# 或者: from trytond.pool.Pool import products_by_location [as 别名]
    def parse(cls, report, records, data, localcontext):
        ShipmentOut = Pool().get('stock.shipment.out')
        Date = Pool().get('ir.date')
        Product = Pool().get('product.product')

        domain = [('state', 'in', ['assigned', 'waiting'])]
        shipments = ShipmentOut.search(domain)
        moves_by_products = {}
        product_quantities = defaultdict(int)

        for shipment in shipments:
            for move in shipment.inventory_moves:
                moves_by_products.setdefault(
                    move.product, []).append(move)

        warehouses = cls.get_warehouses()
        products = moves_by_products.keys()
        with Transaction().set_context(
            stock_skip_warehouse=True,
            stock_date_end=Date.today(),
            stock_assign=True,
        ):
            pbl = Product.products_by_location(
                location_ids=map(int, warehouses),
                product_ids=map(int, products),
            )

            for key, qty in pbl.iteritems():
                _, product_id = key
                product_quantities[product_id] += qty

        localcontext.update({
            'moves_by_products': moves_by_products,
            # TODO: Report is already available on context
            # Use that and remove this context variable
            'report_ext': report.extension,
            'product_quantities': product_quantities,
        })
        return super(ItemsWaitingShipmentReport, cls).parse(
            report, records, data, localcontext
        )
开发者ID:priyankarani,项目名称:trytond-waiting-customer-shipment-report,代码行数:43,代码来源:shipment.py


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