Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2022
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.48 KB | None | 0 0
  1. def lot_search_v2(pool, transaction, search_data):
  2.     Location = pool.get('stock.location')
  3.     Product = pool.get('product.product')
  4.     Lot = pool.get('stock.lot')
  5.     Date = pool.get('ir.date')
  6.     today = Date.today()
  7.     result = {}
  8.     data = []
  9.     found = False
  10.     result['type'] = 'lot'
  11.     warehouse = Location.get_default_warehouse()
  12.     location_id = warehouse.storage_location.id
  13.     domain = [('number', '=', str(search_data))]
  14.     lots = Lot.search(domain)
  15.     lot_ids = [lot.id for lot in lots]
  16.     product_ids = [lot.product.id for lot in lots]
  17.     with transaction.set_context(forecast=False, stock_date_end=today):
  18.         pbl = Product.products_by_location(
  19.             [location_id], grouping=('product', 'lot'),
  20.             grouping_filter=(product_ids, lot_ids), with_childs=True)
  21.     for key, quantity in pbl.items():
  22.         location_id, product_id, lot_id = key
  23.         product = Product(product_id)
  24.         lot = Lot(lot_id)
  25.         data.append({
  26.             'product': product.rec_name,
  27.             'product_id': product_id,
  28.             'location': Location(location_id).rec_name,
  29.             'location_id': location_id,
  30.             'quantity': quantity,
  31.             'uom': product.default_uom.symbol,
  32.             'uom_id': product.default_uom.id,
  33.             'lot': lot.number,
  34.             'lot_id': lot_id,
  35.             'id_preciball_po': lot.id_preciball_po,
  36.         })
  37.     result['data'] = data
  38.     result['found'] = found
  39.     return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement