Skip to content

Commit

Permalink
Implementação anexo pdf danfe paulistana
Browse files Browse the repository at this point in the history
FIX - Bug que anexava a ultima danfe enviada ao modelo de email
  • Loading branch information
danimaribeiro committed Aug 15, 2017
1 parent 0833b1d commit b8e33e6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
8 changes: 4 additions & 4 deletions br_account_einvoice/models/invoice_eletronic.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,10 +460,10 @@ def send_email_nfe(self):
if not mail:
raise UserError('Modelo de email padrão não configurado')
atts = self._find_attachment_ids_email()

if atts and len(atts):
mail.attachment_ids = [(6, 0, atts)]
mail.send_mail(self.invoice_id.id)
values = {
"attachment_ids": atts + mail.attachment_ids.ids
}
mail.send_mail(self.invoice_id.id, email_values=values)

@api.multi
def send_email_nfe_queue(self):
Expand Down
22 changes: 22 additions & 0 deletions br_nfse/models/invoice_eletronic.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,28 @@ def _prepare_eletronic_invoice_values(self):
res.update(nfse_vals)
return res

def _find_attachment_ids_email(self):
atts = super(InvoiceEletronic, self)._find_attachment_ids_email()
if self.model not in ('001'):
return atts

attachment_obj = self.env['ir.attachment']
danfe_report = self.env['ir.actions.report.xml'].search(
[('report_name', '=', 'br_nfse.main_template_br_nfse_danfe')])
report_service = danfe_report.report_name
danfse = self.env['report'].get_pdf([self.id], report_service)
if danfse:
danfe_id = attachment_obj.create(dict(
name="paulistana-%08d.pdf" % self.numero,
datas_fname="paulistana-%08d.pdf" % self.numero,
datas=base64.b64encode(danfse),
mimetype='application/pdf',
res_model='account.invoice',
res_id=self.invoice_id.id,
))
atts.append(danfe_id.id)
return atts

@api.multi
def action_send_eletronic_invoice(self):
super(InvoiceEletronic, self).action_send_eletronic_invoice()
Expand Down

0 comments on commit b8e33e6

Please sign in to comment.