Finding an order associated with invoice

Asked by grisha

Hello everybody.
I'm going to add the order_id field to "account_invoice" object to distinguish shipping addree and invoice address.
How can I do that? Can I use self.pool.get(..).search if invoice_id is of the one2many type?
I think it would be something like

def _get_order(self, cr, uid, ids, context={}):
         cursor.execute('SELECT rel.id ' \
                         'FROM sale_order AS rel ' \
                                         'WHERE %s IN rel.invoice_ids ', self.id))
         res = cursor.fetchall()
         return res

Question information

Language:
English Edit question
Status:
Solved
For:
Odoo Addons (MOVED TO GITHUB) Edit question
Assignee:
No assignee Edit question
Solved by:
grisha
Solved:
Last query:
Last reply:
Revision history for this message
grisha (bzvqzrvpageu0tp-deactivatedaccount) said :
#1

And that's what I have got trying to execue that:
"InternalError: current transaction is aborted, commands ignored until end of transaction block"

Revision history for this message
grisha (bzvqzrvpageu0tp-deactivatedaccount) said :
#2

Ok, I managed to do it myself

def _get_order(self, cr, uid, ids, field_name, args, context={}):
res={}
sids = self.pool.get('sale.order').search(cr, uid, [('invoice_ids','=',ids)],context=context)
if sids:
       for id in ids:
             res[id]=[x for x in sids]
       return res
else:
      return False