Skip to content

Commit

Permalink
added export function to DIOT
Browse files Browse the repository at this point in the history
  • Loading branch information
satcfdi committed Feb 15, 2024
1 parent 92e488a commit cf0e395
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
16 changes: 8 additions & 8 deletions satcfdi/diot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ def render(self, w: DIOTWriter):

w.end()

def _tmp_filename(self):
def filename(self):
rfc = self.datos_identificacion.rfc

if len(rfc) == 12:
Expand Down Expand Up @@ -487,15 +487,15 @@ def _encrypted_write(self, target, tmp_filename):
e(data_encrypted.getvalue(), nr=0, cls=Classes.Context)
e.stream(target)

def generate_package(self, dirname: str = None) -> str:
def generate_package(self, dirname: str = None, filename: str = None) -> str:
"""
Generate Package, return filename
"""
tmp_filename = self._tmp_filename()
filename = filename or self.filename()
if dirname:
filename = os.path.join(dirname, tmp_filename + ".dec")
out_file = os.path.join(dirname, filename + ".dec")
else:
filename = tmp_filename + ".dec"
with open(filename, 'wb') as f:
self._encrypted_write(f, tmp_filename)
return filename
out_file = filename + ".dec"
with open(out_file, 'wb') as f:
self._encrypted_write(f, filename)
return out_file
8 changes: 4 additions & 4 deletions tests/test_diot.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_create_filename():
periodo=Periodo.OCTUBRE,
proveedores=[]
)
assert diot._tmp_filename() == 'XIQB891116QE40DOTAAM1MCMB811401'
assert diot.filename() == 'XIQB891116QE40DOTAAM1MCMB811401'

with mock.patch(f'{module}.diot.datetime') as m:
p = ProveedorTercero(
Expand All @@ -64,7 +64,7 @@ def test_create_filename():
periodo=Periodo.OCTUBRE,
proveedores=[p for _ in range(40001)]
)
assert diot._tmp_filename() == 'XIQB891116QE40DOTAAM1MCMB813202'
assert diot.filename() == 'XIQB891116QE40DOTAAM1MCMB813202'

rfc = "OÑO120726RX3"
with mock.patch(f'{module}.diot.datetime') as m:
Expand All @@ -77,7 +77,7 @@ def test_create_filename():
periodo=Periodo.OCTUBRE,
proveedores=[]
)
assert diot._tmp_filename() == '_OÑO120726RX30DOTAAM1MCMB817181'
assert diot.filename() == '_OÑO120726RX30DOTAAM1MCMB817181'


xiqb891116qe4_issuer = DatosIdentificacion(
Expand Down Expand Up @@ -105,7 +105,7 @@ def test_create_declaracion_diot():
# Verify FILENAME
with mock.patch(f'{module}.diot.datetime') as m:
m.now = mock.Mock(return_value=datetime(2022, 11, 8, 11, 40))
tmp_filename = diot._tmp_filename()
tmp_filename = diot.filename()
assert tmp_filename == text_file

# Verify ZIP
Expand Down

0 comments on commit cf0e395

Please sign in to comment.