title: openerp server action - python code
body: <p>i dont know if i should be asking this here (im now thinking maybe a moderator would move it to stackoverflow), but im not getting an answer on the openerp or launchpad forums.<br>
  In OpenERP 6.0.1, the following function does what its supposed to do when a button is placed in the invoice form to execute it:  </p>
  
  <pre><code>class account_invoice(osv.osv):
      _inherit = "account.invoice"
  
      """ Function to update all lines on invoice """
      def update_invoice(self, cr, uid, ids, context=None):
          if context is None:
              context = {}
          line_obj = self.pool.get('account.invoice.line')
          invoice_ids = self.browse(cr, uid, ids, context)
          for invoice in invoice_ids:
              for line in invoice.invoice_line:
                  if line.product_id:
                      res = line_obj.product_id_change(cr, uid, [line.id], (line.product_id and line.product_id.id or False), uom=(line.uos_id and line.uos_id.id or False), qty=(line.quantity or 0),
                  name=(line.name or ''), type=(invoice.type or False), partner_id=invoice.partner_id.id, fposition_id=invoice.fiscal_position.id, price_unit=(line.price_unit or 0),
                  address_invoice_id=(invoice.address_invoice_id and invoice.address_invoice_id.id or False), currency_id=(invoice.currency_id and invoice.currency_id.id or False), context=context)
                      price_unit = res['value']['price_unit']
                      discount = res['value']['discount']
                      line_obj.write(cr, uid, [line.id], {'price_unit': price_unit})
                      line_obj.write(cr, uid, [line.id], {'discount': discount})
          return True
  
      account_invoice()
  </code></pre>
  
  <p>this is to say that the invoice lines' price unit and discount are updated when this button is clicked in the form.</p>
  
  <p>im trying to create a server action for object "Invoice" of type "python code" that executes this function on all invoices from a menu item. in the python code box, i wrote:</p>
  
  <pre><code>inv = self.pool.get('account.invoice')
  line_obj = self.pool.get('account.invoice.line')
  for invoice in inv.browse(cr, uid, ids):
      for line in invoice.invoice_line:
          res = line_obj.product_id_change(cr, uid, [line.id], (line.product_id and line.product_id.id or False), uom=(line.uos_id and line.uos_id.id or False), qty=(line.quantity or 0), name=(line.name or ''), type=(invoice.type or False), partner_id=invoice.partner_id.id, fposition_id=invoice.fiscal_position.id, price_unit=(line.price_unit or 0), address_invoice_id=(invoice.address_invoice_id and invoice.address_invoice_id.id or False), currency_id=(invoice.currency_id and invoice.currency_id.id or False), context=context)
      price_unit = res['value']['price_unit']
      discount = res['value']['discount']
      line_obj.write(cr, uid, [line.id], {'price_unit': price_unit})
      line_obj.write(cr, uid, [line.id], {'discount': discount})
  </code></pre>
  
  <p>but it does not work. what am i doing wrong?</p>
  
  <p><strong>EDIT:</strong>
  can anyone help me write a function that updates all invoices' lines' similar to those in /account/wizard/account_invoice_state.py ?</p>