Skip to content

Commit

Permalink
[IMP] Adiciona log ao cancelamento e nfse paulistana
Browse files Browse the repository at this point in the history
  • Loading branch information
danimaribeiro committed Jun 30, 2019
1 parent 07e689a commit 84427e6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
13 changes: 9 additions & 4 deletions br_nfe/models/invoice_eletronic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,7 @@ def action_cancel_document(self, context=None, justificativa=None):
}
}

_logger.info('Cancelling NF-e (%s)' % self.numero)
cert = self.company_id.with_context({'bin_size': False}).nfe_a1_file
cert_pfx = base64.decodestring(cert)
certificado = Certificado(cert_pfx, self.company_id.nfe_a1_password)
Expand Down Expand Up @@ -1093,10 +1094,12 @@ def action_cancel_document(self, context=None, justificativa=None):
resposta = resp['object'].getchildren()[0]
if resposta.cStat == 128 and \
resposta.retEvento.infEvento.cStat in (135, 136, 155):
self.state = 'cancel'
self.codigo_retorno = resposta.retEvento.infEvento.cStat
self.mensagem_retorno = resposta.retEvento.infEvento.xMotivo
self.sequencial_evento += 1
self.write({
'state': 'cancel',
'codigo_retorno': resposta.retEvento.infEvento.cStat,
'mensagem_retorno': resposta.retEvento.infEvento.xMotivo,
'sequencial_evento': self.sequencial_evento + 1,
})
else:
code, motive = None, None
if resposta.cStat == 128:
Expand Down Expand Up @@ -1124,6 +1127,8 @@ def action_cancel_document(self, context=None, justificativa=None):
nfe_processada, resp['received_xml'].encode())
if nfe_proc_cancel:
self.nfe_processada = base64.encodestring(nfe_proc_cancel)
_logger.info('Cancelling NF-e (%s) was finished with status %s' % (
self.numero, self.codigo_retorno))

def action_get_status(self):
cert = self.company_id.with_context({'bin_size': False}).nfe_a1_file
Expand Down
37 changes: 26 additions & 11 deletions br_nfse_paulistana/models/invoice_eletronic.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ def action_send_eletronic_invoice(self):
if self.model == '001' and self.state not in ('done', 'cancel'):
self.state = 'error'

_logger.info('Sending NFS-e Paulistana (%s) %s' % (
self.numero, self.partner_id.name))
nfse_values = self._prepare_eletronic_invoice_values()
cert = self.company_id.with_context(
{'bin_size': False}).nfe_a1_file
Expand All @@ -278,10 +280,11 @@ def action_send_eletronic_invoice(self):
certificado, nfse=nfse_values)
retorno = resposta['object']
if retorno.Cabecalho.Sucesso:
self.state = 'done'
self.codigo_retorno = '100'
self.mensagem_retorno = \
'Nota Fiscal Paulistana emitida com sucesso'
self.write({
'state': 'done',
'codigo_retorno': '100',
'mensagem_retorno': 'Nota Paulistana emitida com sucesso',
})

# Apenas producão tem essa tag
if self.ambiente == 'producao':
Expand All @@ -297,8 +300,11 @@ def action_send_eletronic_invoice(self):
'numero_nfse': self.numero_nfse})

else:
self.codigo_retorno = retorno.Erro.Codigo
self.mensagem_retorno = retorno.Erro.Descricao
self.write({
'codigo_retorno': retorno.Erro.Codigo,
'mensagem_retorno': retorno.Erro.Descricao,
})
self.notify_user()

self.env['invoice.eletronic.event'].create({
'code': self.codigo_retorno,
Expand All @@ -309,13 +315,16 @@ def action_send_eletronic_invoice(self):
'nfse-envio', self, resposta['sent_xml'])
self._create_attachment(
'nfse-ret', self, resposta['received_xml'])
_logger.info('NFS-e Paulistana (%s) finished with status %s' % (
self.numero, self.codigo_retorno))

@api.multi
def action_cancel_document(self, context=None, justificativa=None):
if self.model not in ('001'):
return super(InvoiceEletronic, self).action_cancel_document(
justificativa=justificativa)

_logger.info('Cancelling NFS-e Paulistana (%s)' % self.numero)
cert = self.company_id.with_context({'bin_size': False}).nfe_a1_file
cert_pfx = base64.decodestring(cert)
certificado = Certificado(cert_pfx, self.company_id.nfe_a1_password)
Expand All @@ -340,12 +349,16 @@ def action_cancel_document(self, context=None, justificativa=None):
resposta = cancelamento_nfe(certificado, cancelamento=canc)
retorno = resposta['object']
if retorno.Cabecalho.Sucesso:
self.state = 'cancel'
self.codigo_retorno = '100'
self.mensagem_retorno = 'Nota Fiscal Paulistana Cancelada'
self.write({
'state': 'cancel',
'codigo_retorno': '100',
'mensagem_retorno': 'Nota Fiscal Paulistana Cancelada',
})
else:
self.codigo_retorno = retorno.Erro.Codigo
self.mensagem_retorno = retorno.Erro.Descricao
self.write({
'codigo_retorno': retorno.Erro.Codigo,
'mensagem_retorno': retorno.Erro.Descricao,
})

self.env['invoice.eletronic.event'].create({
'code': self.codigo_retorno,
Expand All @@ -354,6 +367,8 @@ def action_cancel_document(self, context=None, justificativa=None):
})
self._create_attachment('canc', self, resposta['sent_xml'])
self._create_attachment('canc-ret', self, resposta['received_xml'])
_logger.info('Cancelling NFS-e (%s) was finished with status %s' % (
self.numero, self.codigo_retorno))

def action_check_nfse_status(self):
if self.model != '001':
Expand Down

0 comments on commit 84427e6

Please sign in to comment.