title: How to write this domain to be sure at 100 % that we will get the right stock pack operation for each invoice line?
body: <p>This post should be a little more complex than usual.</p>
  
  <p>We have created a new field for an account.invoice.line : pack_operation. With this field, we can print serial/lot number for each line on the PDF invoice (this part works well).</p>
  
  <p>Many hours passed trying to write the domain to select the EXACT and ONLY stock pack operation for each invoice line.</p>
  
  <p>In the code below, we used the domain [('id','=', 31)] to make our tests printing the PDF.</p>
  
  <p>Ho to write this domain to be sure at 100 % that we will get the right stock pack operation for each invoice line?</p>
  
  <p>I really need your help here... Too complex for my brain.
  Our code :</p>
  
  <pre><code>class AccountInvoiceLine(models.Model):
  _inherit = "account.invoice.line"
      pack_operation = fields.Many2one(comodel_name='stock.pack.operation', compute='compute_stock_pack_operation_id')
  
      def compute_stock_pack_operation_id(self):       
           stock_operation_obj = self.env['stock.pack.operation']
           stock_operation = stock_operation_obj.search(            [('id','=', 31)]            )
           self.pack_operation = stock_operation[0]
  
  
  
  
     EDIT#1
  I know that you won't like my code. But, this one seems to work. I take any comments and improvements with pleasure.
  
  
  
      class AccountInvoiceLine(models.Model):
      _inherit = "account.invoice.line"
      pack_operation = fields.Many2one(comodel_name='stock.pack.operation', compute='compute_stock_pack_operation_id')@api.one
      def compute_stock_pack_operation_id(self):
  
  
          procurement_order_obj = self.env['procurement.order']
          stock_operation_obj = self.env['stock.pack.operation']
  
          all_picking_ids_for_this_invoice_line = []
  
  
          for saleorderline in self.sale_line_ids:
  
              for procurement in saleorderline.procurement_ids:
  
                  for stockmove in procurement.move_ids:
  
                      if stockmove.picking_id.id not in all_picking_ids_for_this_invoice_line
                          all_picking_ids_for_this_invoice_line.append(stockmove.picking_id.id)
  
  
          all_picking_ids_for_this_invoice_line))
  
          stock_operation = stock_operation_obj.search(
              [ '&amp;', 
                  ('picking_id','in',all_picking_ids_for_this_invoice_line),
                  ('product_id','=',self.product_id.id)
                  ]
              )
  
          self.pack_operation = stock_operation[0]
  </code></pre>