I want to loop through all invoices I have but getting this error. if I change inv[0].id it works but loops only first invoice. how can i make it loop all invoices.
def generate(self):
Invoice = self.env['account.invoice']
inv = Invoice.browse(Invoice.search([]))
invoice = inv and inv[0]
for inv in invoice:
root = etree.Element('000')
po_code = etree.SubElement(root, '22')
po_code.text = str(inv.id) or ''
return root
ProgrammingError: can't adapt type 'account.invoice'
When we call self.env['account.invoice'].search([])
, we will be received a recordset of all records, that is stored in account.invoice
model. Putting that recordset in the browse
method again is redundant, as this method also returns a recordset. Moreover, it's not supposed to work because browse
method expects from you an id or list of those. Check out documentation.
All you have to do from now is just to iterate over the recordset via for
loop. At each time you will get one record from that recordset, so you can manipulate only it.
def generate(self):
for record in self.env['account.invoice'].search([]):
# go ahead with each record