ProgrammingError: can't adapt type 'account.invoice' in method
ProgrammingError: can't adapt type 'account.invoice' in method
我想遍历我拥有的所有发票,但收到此错误。如果我更改 inv[0].id 它可以工作但只循环第一张发票。我怎样才能让它循环所有发票。
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'
当我们调用 self.env['account.invoice'].search([])
时,我们将收到一个包含所有记录的记录集,该记录集存储在 account.invoice
模型中。将该记录集再次放入 browse
方法是多余的,因为此方法也是 returns 一个记录集。此外,它不应该工作,因为 browse
方法需要你提供一个 id 或它们的列表。查看文档。
从现在开始,您只需通过 for
循环遍历记录集即可。每次您将从该记录集中获取一条记录,因此您只能操作它。
def generate(self):
for record in self.env['account.invoice'].search([]):
# go ahead with each record
我想遍历我拥有的所有发票,但收到此错误。如果我更改 inv[0].id 它可以工作但只循环第一张发票。我怎样才能让它循环所有发票。
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'
当我们调用 self.env['account.invoice'].search([])
时,我们将收到一个包含所有记录的记录集,该记录集存储在 account.invoice
模型中。将该记录集再次放入 browse
方法是多余的,因为此方法也是 returns 一个记录集。此外,它不应该工作,因为 browse
方法需要你提供一个 id 或它们的列表。查看文档。
从现在开始,您只需通过 for
循环遍历记录集即可。每次您将从该记录集中获取一条记录,因此您只能操作它。
def generate(self):
for record in self.env['account.invoice'].search([]):
# go ahead with each record