I have a problem where I have a lot of data records, and when I try to download more than 1 data record an error always appears which basically looks like this
File "c:\\users\\it uw\\odoo14\\mspcustomaddons\\l10n_id_efaktur\\models\\account_move.py ", line 136, in download_efaktur
self.\_generate_efaktur(',')
File "c:\\users\\it uw\\odoo14\\mspcustomaddons\\l10n_id_efaktur\\models\\account_move.py", line 296, in \_generate_efaktur
output_head = self.\_generate_efaktur_invoice(delimiter)
File "c:\\users\\it uw\\odoo14\\mspcustomaddons\\l10n_id_efaktur\\models\\account_move.py", line 144, in \_generate_efaktur_invoice
company_id = self. company_id
File "C:\\Users\\IT UW\\odoo14\\flectra\\flectra\\fields.py", line 947, in __get__
record. ensure_one()
File "C:\\Users\\IT UW\\odoo14\\flectra\\flectra\\models.py", line 4437, in ensure_one
raise ValueError("Expected singleton: %s" % self)
ValueError: \<class 'ValueError'\>: "Expected singleton: account. invoice(35590, 35589, 35588, 35587)" while evaluating
'action = records.download_effect()'
And here is the code
@api.multi
def download_efaktur(self):
"""Collect the data and execute function _generate_efaktur."""
for record in self:
if record.state == 'draft':
raise ValidationError(_('Could not download E-faktur in draft state'))
if record.partner_id.l10n_id_pkp and not record.l10n_id_tax_number:
raise ValidationError(_('Connect %(move_number)s with E-faktur to download this report',
move_number=record.name))
self._generate_efaktur(',')
return self.download_csv()
@api.multi
def _generate_efaktur(self, delimiter):
if self.filtered(lambda x: not x.l10n_id_kode_transaksi):
raise UserError(_('Some documents don\'t have a transaction code'))
if self.filtered(lambda x: x.type != 'out_invoice'):
raise UserError(_('Some documents are not Customer Invoices'))
output_head = self._generate_efaktur_invoice(delimiter)
my_utf8 = output_head.encode("utf-8")
out = base64.b64encode(my_utf8)
attachment = self.env['ir.attachment'].create({
'datas': out,
'name': 'efaktur_%s.csv' % (fields.Datetime.to_string(fields.Datetime.now())
.replace(" ", "_")),
'type': 'binary',
})
for record in self:
record.message_post(attachment_ids=[attachment.id])
self.l10n_id_attachment_id = attachment.id
return {
'type': 'ir.actions.client',
'tag': 'reload',
}
I have tried to change the looping logic in the download_efaktur()
method and also the generate_efaktur()
method
but the error still appears.