diff --git a/br_nfe/models/invoice_eletronic.py b/br_nfe/models/invoice_eletronic.py index 1cf7ffee6..7dc90270d 100644 --- a/br_nfe/models/invoice_eletronic.py +++ b/br_nfe/models/invoice_eletronic.py @@ -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) @@ -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: @@ -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 diff --git a/br_nfse_paulistana/models/invoice_eletronic.py b/br_nfse_paulistana/models/invoice_eletronic.py index 047e020f4..da331d4a5 100644 --- a/br_nfse_paulistana/models/invoice_eletronic.py +++ b/br_nfse_paulistana/models/invoice_eletronic.py @@ -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 @@ -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': @@ -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, @@ -309,6 +315,8 @@ 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): @@ -316,6 +324,7 @@ def action_cancel_document(self, context=None, justificativa=None): 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) @@ -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, @@ -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':