4
4
from pynfe .entidades .emitente import Emitente
5
5
from pynfe .entidades .notafiscal import NotaFiscalServico
6
6
from pynfe .entidades .servico import Servico
7
+ from pynfe .processamento .assinatura import AssinaturaA1
7
8
from pynfe .processamento .serializacao import SerializacaoNfse
8
9
from pynfe .utils import obter_codigo_por_municipio
9
10
from pynfe .utils .flags import (
12
13
from decimal import Decimal
13
14
import datetime
14
15
import re
16
+ from lxml import etree
15
17
16
18
17
19
class SerializacaoNFSeConfigTest :
@@ -22,14 +24,7 @@ def __init__(self, certificado: str, senha: str, homologacao: bool):
22
24
23
25
24
26
class SerializacaoNFSeTest :
25
-
26
- @staticmethod
27
- def get_config () -> SerializacaoNFSeConfigTest :
28
- return SerializacaoNFSeConfigTest (
29
- "./tests/certificado.pfx" ,
30
- bytes ("123456" , "utf-8" ),
31
- True
32
- )
27
+ data_hora = "2025-04-10T09:45:29"
33
28
34
29
@staticmethod
35
30
def get_notafiscal_servico () -> NotaFiscalServico :
@@ -61,7 +56,8 @@ def get_notafiscal_servico() -> NotaFiscalServico:
61
56
62
57
return NotaFiscalServico (
63
58
identificador = '50' ,
64
- data_emissao = datetime .datetime .now (),
59
+ data_emissao = datetime .datetime .strptime (
60
+ SerializacaoNFSeTest .data_hora , "%Y-%m-%dT%H:%M:%S" ),
65
61
servico = servico ,
66
62
emitente = SerializacaoNFSeTest ._get_emitente (),
67
63
cliente = SerializacaoNFSeTest ._get_destinatario (),
@@ -84,16 +80,19 @@ def serializa_nfse(nfse: NotaFiscalServico, autorizador: str) -> str:
84
80
xml = serializador .gerar (nfse )
85
81
return xml
86
82
87
- # TODO: assinatura digital
88
- # @staticmethod
89
- # def assina_xml(config: SerializacaoNFSeConfigTest, nfse_xml: str):
90
- # a1 = AssinaturaA1(config.certificado, config.senha)
91
- # xml = a1.assinar(nfse_xml, True)
92
- # return xml
83
+ @staticmethod
84
+ def assina_xml (xml : str ) -> str :
85
+ config = SerializacaoNFSeTest ._get_config ()
86
+ nfse = etree .fromstring (xml )
87
+
88
+ a1 = AssinaturaA1 (config .certificado , config .senha )
89
+ xml_assinado = a1 .assinar (nfse , True )
90
+
91
+ return xml_assinado
93
92
94
93
@staticmethod
95
94
def strip_xml (xml : str ) -> str :
96
- return re .sub (r">\s+<" , "><" , xml .replace ( " \n " , "" ). strip ())
95
+ return re .sub (r">\s+<" , "><" , xml .strip ())
97
96
98
97
@staticmethod
99
98
def limpa_namespace () -> None :
@@ -114,6 +113,14 @@ def limpa_namespace() -> None:
114
113
# xml_doc=nfse_xml_assinado, xsd_file=xsd_nfse, use_assert=True
115
114
# )
116
115
116
+ @staticmethod
117
+ def _get_config () -> SerializacaoNFSeConfigTest :
118
+ return SerializacaoNFSeConfigTest (
119
+ "./tests/certificado.pfx" ,
120
+ bytes ("123456" , "utf-8" ),
121
+ True
122
+ )
123
+
117
124
@staticmethod
118
125
def _get_emitente () -> Emitente :
119
126
return Emitente (
0 commit comments