Odoo Mindscape. Understand Odoo faster. Explore modules, fields, dependencies and version differences in one place instead of digging through the source code.

Module: Purchase Stock

Entity: stock.lot

Compute Method: _compute_purchase_order_ids

Inputs Method Outputs
  • lot_id
  • lot_id.id
  • move_id
  • move_id.purchase_line_id
  • move_id.purchase_line_id.order_id
  • move_id.purchase_line_id.order_id.id
  • id
  • purchase_order_ids
purchase_order_ids_map = defaultdict(set)
move_lines = self.env['stock.move.line'].search([
            ('lot_id', 'in', self.ids),
            ('state', '=', 'done'),
            ('move_id.picking_id.location_id.usage', '=', 'supplier'),
            ('move_id.purchase_line_id.order_id', '!=', False)
        ])
for move_line in move_lines:
            purchase_order_ids_map[move_line.lot_id.id].add(move_line.move_id.purchase_line_id.order_id.id)
for lot in self:
            po_ids = purchase_order_ids_map.get(lot.id, [])
            lot.purchase_order_ids = self.env['purchase.order'].browse(po_ids)
            lot.purchase_order_count = len(lot.purchase_order_ids)

Back to entity