Skip to content

Commit

Permalink
Merge 01ec6cf into d32f864
Browse files Browse the repository at this point in the history
  • Loading branch information
danimaribeiro committed Jul 31, 2018
2 parents d32f864 + 01ec6cf commit a9e27c0
Show file tree
Hide file tree
Showing 29 changed files with 455 additions and 414 deletions.
4 changes: 2 additions & 2 deletions br_account_einvoice/models/invoice_eletronic.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class InvoiceEletronic(models.Model):
partner_shipping_id = fields.Many2one(
'res.partner', string=u'Entrega', readonly=True, states=STATE)
payment_term_id = fields.Many2one(
'account.payment.term', string=u'Forma pagamento',
'account.payment.term', string=u'Condição pagamento',
readonly=True, states=STATE)
fiscal_position_id = fields.Many2one(
'account.fiscal.position', string=u'Posição Fiscal',
Expand Down Expand Up @@ -436,7 +436,7 @@ def unlink(self):

def log_exception(self, exc):
self.codigo_retorno = -1
self.mensagem_retorno = exc.message
self.mensagem_retorno = str(exc)

def _get_state_to_send(self):
return ('draft',)
Expand Down
76 changes: 35 additions & 41 deletions br_base/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,47 +198,41 @@ def action_check_sefaz(self):
resposta = consulta_cadastro(certificado, obj=obj, ambiente=1,
estado=self.state_id.ibge_code)

obj = resposta['object']
if "Body" in dir(obj) and \
"consultaCadastro2Result" in dir(obj.Body):
info = obj.Body.consultaCadastro2Result.retConsCad.infCons
if info.cStat == 111 or info.cStat == 112:
if not self.inscr_est:
self.inscr_est = info.infCad.IE
if not self.cnpj_cpf:
self.cnpj_cpf = info.infCad.IE

def get_value(obj, prop):
if prop not in dir(obj):
return None
return getattr(obj, prop)
self.legal_name = get_value(info.infCad, 'xNome')
if "ender" not in dir(info.infCad):
return
cep = get_value(info.infCad.ender, 'CEP') or ''
self.zip = str(cep).zfill(8) if cep else ''
self.street = get_value(info.infCad.ender, 'xLgr')
self.number = get_value(info.infCad.ender, 'nro')
self.street2 = get_value(info.infCad.ender, 'xCpl')
self.district = get_value(info.infCad.ender, 'xBairro')
cMun = get_value(info.infCad.ender, 'cMun')
xMun = get_value(info.infCad.ender, 'xMun')
city = None
if cMun:
city = self.env['res.state.city'].search(
[('ibge_code', '=', str(cMun)[2:]),
('state_id', '=', self.state_id.id)])
if not city and xMun:
city = self.env['res.state.city'].search(
[('name', 'ilike', xMun),
('state_id', '=', self.state_id.id)])
if city:
self.city_id = city.id
else:
msg = "%s - %s" % (info.cStat, info.xMotivo)
raise UserError(msg)
info = resposta['object'].getchildren()[0].infCons
if info.cStat == 111 or info.cStat == 112:
if not self.inscr_est:
self.inscr_est = info.infCad.IE.text
if not self.cnpj_cpf:
self.cnpj_cpf = info.infCad.IE.text

def get_value(obj, prop):
if prop not in dir(obj):
return None
return getattr(obj, prop)
self.legal_name = get_value(info.infCad, 'xNome')
if "ender" not in dir(info.infCad):
return
cep = get_value(info.infCad.ender, 'CEP') or ''
self.zip = str(cep).zfill(8) if cep else ''
self.street = get_value(info.infCad.ender, 'xLgr')
self.number = get_value(info.infCad.ender, 'nro')
self.street2 = get_value(info.infCad.ender, 'xCpl')
self.district = get_value(info.infCad.ender, 'xBairro')
cMun = get_value(info.infCad.ender, 'cMun')
xMun = get_value(info.infCad.ender, 'xMun')
city = None
if cMun:
city = self.env['res.state.city'].search(
[('ibge_code', '=', str(cMun)[2:]),
('state_id', '=', self.state_id.id)])
if not city and xMun:
city = self.env['res.state.city'].search(
[('name', 'ilike', xMun),
('state_id', '=', self.state_id.id)])
if city:
self.city_id = city.id
else:
raise UserError(u"Nenhuma resposta - verificou se seu \
certificado é válido?")
msg = "%s - %s" % (info.cStat, info.xMotivo)
raise UserError(msg)
else:
raise UserError(u'Preencha o estado e o CNPJ para pesquisar')
81 changes: 35 additions & 46 deletions br_base/tests/xml/consulta_cadastro.xml
Original file line number Diff line number Diff line change
@@ -1,46 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header>
<nfeCabecMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/CadConsultaCadastro2">
<cUF>42</cUF>
<versaoDados>2.00</versaoDados>
</nfeCabecMsg>
</soap:Header>
<soap:Body>
<consultaCadastro2Result xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/CadConsultaCadastro2">
<retConsCad versao="2.00" xmlns="http://www.portalfiscal.inf.br/nfe">
<infCons>
<verAplic>SC_NFE_PL_008i2</verAplic>
<cStat>111</cStat>
<xMotivo>Consulta cadastro com uma ocorrencia</xMotivo>
<UF>SC</UF>
<CNPJ>22814429000155</CNPJ>
<dhCons>2016-11-03T08:33:34-02:00</dhCons>
<cUF>35</cUF>
<infCad>
<IE>112632165</IE>
<CNPJ>22814429000155</CNPJ>
<UF>SC</UF>
<cSit>1</cSit>
<indCredNFe>1</indCredNFe>
<indCredCTe>4</indCredCTe>
<xNome>Empresa de Teste SC</xNome>
<xRegApur>SIMPLES NACIONAL</xRegApur>
<CNAE>4789099</CNAE>
<dIniAtiv>2014-11-03</dIniAtiv>
<dUltSit>2014-11-03</dUltSit>
<ender>
<xLgr>RUA PADRE JOAO</xLgr>
<nro>000</nro>
<xCpl>SL</xCpl>
<xBairro>Centro</xBairro>
<cMun>4205407</cMun>
<xMun>FLORIANOPOLIS</xMun>
<CEP>88032050</CEP>
</ender>
</infCad>
</infCons>
</retConsCad>
</consultaCadastro2Result>
</soap:Body>
</soap:Envelope>
<consultaCadastro2Result xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/CadConsultaCadastro2">
<retConsCad versao="2.00" xmlns="http://www.portalfiscal.inf.br/nfe">
<infCons>
<verAplic>SC_NFE_PL_008i2</verAplic>
<cStat>111</cStat>
<xMotivo>Consulta cadastro com uma ocorrencia</xMotivo>
<UF>SC</UF>
<CNPJ>22814429000155</CNPJ>
<dhCons>2016-11-03T08:33:34-02:00</dhCons>
<cUF>35</cUF>
<infCad>
<IE>112632165</IE>
<CNPJ>22814429000155</CNPJ>
<UF>SC</UF>
<cSit>1</cSit>
<indCredNFe>1</indCredNFe>
<indCredCTe>4</indCredCTe>
<xNome>Empresa de Teste SC</xNome>
<xRegApur>SIMPLES NACIONAL</xRegApur>
<CNAE>4789099</CNAE>
<dIniAtiv>2014-11-03</dIniAtiv>
<dUltSit>2014-11-03</dUltSit>
<ender>
<xLgr>RUA PADRE JOAO</xLgr>
<nro>000</nro>
<xCpl>SL</xCpl>
<xBairro>Centro</xBairro>
<cMun>4205407</cMun>
<xMun>FLORIANOPOLIS</xMun>
<CEP>88032050</CEP>
</ender>
</infCad>
</infCons>
</retConsCad>
</consultaCadastro2Result>
1 change: 1 addition & 0 deletions br_nfe/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
],
'depends': [
'br_account_einvoice',
'br_account_payment'
],
'external_dependencies': {
'python': [
Expand Down
1 change: 1 addition & 0 deletions br_nfe/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
from . import res_partner
from . import invoice_eletronic_item
from . import inutilized_nfe
from . import payment_mode
2 changes: 2 additions & 0 deletions br_nfe/models/account_fiscal_position.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class AccountFiscalPositionTemplate(models.Model):
('2', u'Operação não presencial, pela Internet'),
('3', u'Operação não presencial, Teleatendimento'),
('4', u'NFC-e em operação com entrega em domicílio'),
('5', u'Operação presencial, fora do estabelecimento'),
('9', u'Operação não presencial, outros'),
], u'Tipo de operação',
help=u'Indicador de presença do comprador no\n'
Expand Down Expand Up @@ -48,6 +49,7 @@ class AccountFiscalPosition(models.Model):
('2', u'Operação não presencial, pela Internet'),
('3', u'Operação não presencial, Teleatendimento'),
('4', u'NFC-e em operação com entrega em domicílio'),
('5', u'Operação presencial, fora do estabelecimento'),
('9', u'Operação não presencial, outros'),
], u'Tipo de operação',
help=u'Indicador de presença do comprador no\n'
Expand Down
3 changes: 2 additions & 1 deletion br_nfe/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def _return_pdf_invoice(self, doc):
def _prepare_edoc_vals(self, inv):
res = super(AccountInvoice, self)._prepare_edoc_vals(inv)

res['payment_mode_id'] = inv.payment_mode_id.id
res['ind_pres'] = inv.fiscal_position_id.ind_pres
res['finalidade_emissao'] = inv.fiscal_position_id.finalidade_emissao
res['informacoes_legais'] = inv.fiscal_comment
Expand Down Expand Up @@ -148,7 +149,7 @@ def _prepare_edoc_vals(self, inv):
count = 1
for parcela in inv.receivable_move_line_ids.sorted(lambda x: x.name):
duplicatas.append((0, None, {
'numero_duplicata': "%s/%02d" % (inv.internal_number, count),
'numero_duplicata': "%03d" % count,
'data_vencimento': parcela.date_maturity,
'valor': parcela.credit or parcela.debit,
}))
Expand Down
31 changes: 17 additions & 14 deletions br_nfe/models/inutilized_nfe.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class InutilizedNfe(models.Model):
string=u'Modelo', required=True, readonly=True, states=STATE)
serie = fields.Many2one('br_account.document.serie', string=u'Série',
required=True, readonly=True, states=STATE)
code = fields.Char(string="Código", size=10)
motive = fields.Char(string="Motivo", size=300)

@api.model
def create(self, vals):
Expand Down Expand Up @@ -105,21 +107,22 @@ def _prepare_obj(self, company, estado, ambiente):
'justificativa': self.justificativa,
}

def _handle_resposta(self, resposta):
self._create_attachment('inutilizacao-envio', self,
resposta['sent_xml'])
self._create_attachment('inutilizacao-recibo', self,
resposta['received_xml'])
if hasattr(resposta['object'].Body, 'Fault'):
raise UserError(u'Não foi possível concluir a operação.')
inf_inut = resposta['object'].Body.nfeInutilizacaoNF2Result.\
retInutNFe.infInut
def _handle_response(self, response):
self._create_attachment(
'inutilizacao-envio', self, response['sent_xml'])
self._create_attachment(
'inutilizacao-recibo', self, response['received_xml'])
inf_inut = response['object'].getchildren()[0].infInut
status = inf_inut.cStat
if status == 102:
self.state = 'done'
self.write({
'state': 'done',
'code': inf_inut.cStat,
'motive': inf_inut.xMotivo
})
else:
self.state = 'error'
self.erro = inf_inut.xMotivo
msg = '%s - %s' % (inf_inut.cStat, inf_inut.xMotivo)
raise UserError(msg)

def send_sefaz(self):
company = self.env.user.company_id
Expand All @@ -134,8 +137,8 @@ def send_sefaz(self):
certificado = Certificado(cert_pfx, company.nfe_a1_password)

resposta = inutilizar_nfe(certificado, obj=obj, estado=estado,
ambiente=int(ambiente))
self._handle_resposta(resposta=resposta)
ambiente=int(ambiente), modelo=obj['modelo'])
self._handle_response(response=resposta)

@api.multi
def action_send_inutilization(self):
Expand Down

0 comments on commit a9e27c0

Please sign in to comment.