本文整理汇总了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)
示例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)
示例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
)