Skip to content

Changing webservice schema version#17

Merged
thiaguin merged 3 commits intomaster3from
jt.change-webservice-schema-version
Mar 24, 2026
Merged

Changing webservice schema version#17
thiaguin merged 3 commits intomaster3from
jt.change-webservice-schema-version

Conversation

@thiaguin
Copy link

@thiaguin thiaguin commented Mar 20, 2026

This pull request introduces logic to dynamically determine the schema version when calling NFSe service methods in the pytrustnfe Paulistana integration. The main change is the introduction of a helper function to map methods to schema version attributes, improving flexibility in how requests are constructed.

Dynamic schema version selection:

  • Added _get_schema_version helper function to map NFSe service methods to their respective schema version attributes, allowing dynamic selection of schema versions based on method and provided arguments.
  • Updated the _send function to use the dynamic schema version when invoking service methods, replacing the previously hardcoded version.

Version bump:

  • Incremented the package version in setup.py from 1.0.52.dev0 to 1.0.53.dev0.

Tested local:

nfse = {'cpf_cnpj': 18277493000177,
 'data_inicio': '2026-03-18',
 'data_fim': '2026-03-18',
 'total_servicos': Decimal('10.00'),
 'valor_total_servicos': Decimal('10.00'),
 'total_deducoes': Decimal('0.00'),
 'versao': '2',
 'lista_rps': [{'assinatura': '000059871091LPD0 00000817025720260318TNN00000000000100000000000000000006302100041076932878',
   'serie': 'LPD0',
   'numero': '8170257',
   'data_emissao': '2026-03-18',
   'codigo_atividade': 6302,
   'aliquota_atividade': Decimal('0.02'),
   'valor_servico': Decimal('10.00'),
   'valor_deducao': Decimal('0.00'),
   'valor_ir': Decimal('0.00'),
   'prestador': {'inscricao_municipal': 59871091},
   'tomador': {'tipo_cpfcnpj': 1,
    'cpf_cnpj': '***********',
    'inscricao_municipal': '',
    'razao_social': 'Mateus Manetta',
    'tipo_logradouro': '',
    'logradouro': 'Rua Inacio Manuel Alvares',
    'numero': '1000',
    'bairro': 'Jardim Ester',
    'cidade': '3550308',
    'uf': 'SP',
    'cep': '05372111',
    'email': '*****@mail.com'},
   'descricao': '(teste) - Servico de cobranca dos valores dos fretes prestados pelo motofretista aos usuarios (tomadores| de servicos de transporte) da plataforma Loggi.',
   'valor_carga_tributaria': '',
   'fonte_carga_tributaria': '',
   'nbs': '123654321',
   'local_da_prestacao': '3550308',
   'ibs_cbs': {'finalidade_nfse': '0',
    'operacao_de_uso': '0',
    'codigo_indicador_da_operacao': '100501',
    'tipo_do_destinatario': '1',
    'classificacao_tributaria': '000001'}}]}


teste_envio_lote_rps(certificado, nfse=nfse)

# Return
<?xml version="1.0" encoding="UTF-8"?><RetornoEnvioLoteRPS xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.prefeitura.sp.gov.br/nfe"><Cabecalho Versao="2" xmlns=""><Sucesso>true</Sucesso><InformacoesLote><NumeroLote>0</NumeroLote><InscricaoPrestador>59871091</InscricaoPrestador><CPFCNPJRemetente><CNPJ>18277493000177</CNPJ></CPFCNPJRemetente><DataEnvioLote>2026-03-23T11:23:27</DataEnvioLote><QtdNotasProcessadas>1</QtdNotasProcessadas><TempoProcessamento>1</TempoProcessamento><ValorTotalServicos>0</ValorTotalServicos></InformacoesLote></Cabecalho></RetornoEnvioLoteRPS>

@thiaguin thiaguin self-assigned this Mar 20, 2026
Copy link

@seiti seiti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sinto falta de testes

"TesteEnvioLoteRPS": "nfse",
}

attribute = getattr(method_to_attribute_mapper, method, '')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isso funciona? TIL, pois eu imaginaria um method_to_attribute_mapper.get(method, '')

"TesteEnvioLoteRPS": "nfse",
}

attribute = getattr(method_to_attribute_mapper, method, '')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

também vi que o copilot deu uma sugerida, acredito que precisaremos olhar pro versao dentro do dict que vier no _send

Suggested change
attribute = getattr(method_to_attribute_mapper, method, '')
attribute = method_to_attribute_mapper.get(method, '')
schema_version = kwargs.get(attribute, {}).get('versao', '1') if attribute else '1'

@thiaguin thiaguin merged commit c0a6d80 into master3 Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants