title: Odoo Automated Actions how can you iterate through One2Many record to add desired values to a new object using python expression?
body: <p>I have a situation like this:</p>
  
  <p>I want to create a Customer Invoice with 3 invoice lines: one for Customer payment, one for payment processing fee and one for a commission.</p>
  
  <p>When the invoice is created, I've got an automated action set up to create 3 separate Supplier invoices, one per invoice line. That's fine. However I need a way to select values from specific invoice lines, based on the invoice.line.product_id. At the moment I can get the invoice line values like this, using python expression on the Automatic Actions interface:</p>
  
  <pre><code>[(0, 0, {'name': object.invoice_line.name, 'product_id': object.invoice_line.product_id.id, 'account_id': object.invoice_line.account_id.id, 'account_analytic_id': object.invoice_line.account_analytic_id.id, 'quantity': object.invoice_line.quantity, 'price_unit': object.invoice_line.price_unit})]
  </code></pre>
  
  <p>And this works fine when there's a single invoice line. However, I want to do something like this:</p>
  
  <pre><code>for line in object.invoice_line:
      if line.product_id == 2:
          [(0, 0, {'name': line.name, 'product_id': line.product_id.id, 'account_id': line.account_id.id, 'account_analytic_id': line.account_analytic_id.id, 'quantity': line.quantity, 'price_unit': line.price_unit})]
  </code></pre>
  
  <p>I get an error like this:</p>
  
  <pre><code>File "&lt;string&gt;", line 1
  for line in object.invoice_line:
    ^
  SyntaxError: invalid syntax
  </code></pre>
  
  <p>I'm not too familiar with python but that looks like it should work, given that object.invoice_line can be iterated through like an array. I'm sure there's a correct way to iterate through one2many records like this, that I'm not aware with.</p>
  
  <p>I could simply put Payment Provider Fee and Commission as custom fields on the Customer invoice record and then access them directly without much of an issue. That works but it's less optimal than having them all live as invoice lines.</p>
  
  <p><strong>EDIT 1:</strong></p>
  
  <p>Seems like you can't add condition statements at all through Automated Actions, at least the ones created through the interface. However, I can just call specific element by doing something like object.invoice_line[0], [1], etc. Since the order of items will always be the same, I can simply use that. However, if there's a better way, or even a way, to search for a specific line using conditions, I'd rather use that.</p>
  
  <p>Thanks.</p>