def _find_attachment_ids_email(self):
atts = super(InvoiceEletronic, self)._find_attachment_ids_email()
attachment_obj = self.env['ir.attachment']
if self.model not in ('009'):
return atts
tmp = tempfile._get_default_tempdir()
temp_name = os.path.join(tmp, next(tempfile._get_candidate_names()))
command_args = ["--dpi", "84", str(self.url_danfe), temp_name]
wkhtmltopdf = [_get_wkhtmltopdf_bin()] + command_args
process = subprocess.Popen(wkhtmltopdf, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
out, err = process.communicate()
if process.returncode not in [0, 1]:
raise UserError(_('Wkhtmltopdf failed (error code: %s). '
'Message: %s') % (str(process.returncode), err))
tmpDanfe = None
with open(temp_name, 'r') as f:
tmpDanfe = f.read()
try:
os.unlink(temp_name)
except (OSError, IOError):
_logger.error('Error when trying to remove file %s' % temp_name)
if tmpDanfe:
danfe_id = attachment_obj.create(dict(
name="Danfe-%08d.pdf" % self.numero,
datas_fname="Danfe-%08d.pdf" % self.numero,
datas=base64.b64encode(tmpDanfe),
mimetype='application/pdf',
res_model='account.invoice',
res_id=self.invoice_id.id,
))
atts.append(danfe_id.id)
return atts
评论列表
文章目录