diff --git a/satcfdi/diot/__init__.py b/satcfdi/diot/__init__.py index f903b13..d07deda 100644 --- a/satcfdi/diot/__init__.py +++ b/satcfdi/diot/__init__.py @@ -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: @@ -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 diff --git a/tests/test_diot.py b/tests/test_diot.py index 2708607..fbcf932 100644 --- a/tests/test_diot.py +++ b/tests/test_diot.py @@ -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( @@ -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: @@ -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( @@ -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