Skip to content

Commit 4f06df0

Browse files
committed
Updated
1 parent 65fc6b4 commit 4f06df0

3 files changed

Lines changed: 33 additions & 5 deletions

File tree

satdigitalinvoice/facturacion.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,8 +530,8 @@ def action_button(self, action_name, action_items, action_text):
530530

531531
def attachments():
532532
for ni in facturas:
533-
yield ni.filename + ".xml"
534-
yield ni.filename + ".pdf"
533+
yield ni.xml_filename
534+
yield ni.pdf_filename
535535

536536
if "I" in tipos_facturas:
537537
titulo = "Comprobantes Fiscales"
@@ -1357,6 +1357,23 @@ def action(self, event, values):
13571357
cfdi.status_sat(update=True)
13581358
self.done_message("FIN")
13591359

1360+
case 'descargar_emitidas':
1361+
download_folder = sg.popup_get_folder('', no_window=True,)
1362+
if download_folder:
1363+
emitidas = self.window["emitidas_table"].selected_items()
1364+
1365+
zip_name = f"emitidas_{datetime.now().strftime('%Y%m%d_%H%M%S')}.zip"
1366+
zip_path = os.path.join(download_folder, zip_name)
1367+
added = 0
1368+
with ZipFile(zip_path, 'w') as zf:
1369+
for i in emitidas:
1370+
for f in (i.xml_filename, i.pdf_filename):
1371+
if not os.path.isfile(f):
1372+
raise FileNotFoundError(f"Archivo no encontrado: {f}")
1373+
zf.write(f, arcname=os.path.basename(f))
1374+
added += 1
1375+
self.done_message(f"ZIP creado con {added} archivo(s): {zip_path}")
1376+
13601377
case "exportar_metadata":
13611378
with open(METADATA_FILE, 'w', newline='', encoding='utf-8') as f:
13621379
writer = csv.writer(f)

satdigitalinvoice/layout.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@
7272
"+xiLmLj2MZHPCl0WbrjhZjPb7EEh3CEU/zAOpYiZxKf8LUMYCPEI6jFDz3DYfhYdPEb7/ET9TKAbqtoGt9xheWINWInt3KnygDehKjWIR7GaxzjIPJW43treh5EbBY7eHQdoFXsJMRNPMRmvJ" \
7373
"/jZeSNRqzeUfwiYvu9IAN4EcXFCCcwWMibwdNC8bwXpL1LU+0Z9grHePtYX6l6VPzNkrQpF07WxZMBqVdmVhVwE/v3gD+of4e/h7E8SwAAAABJRU5ErkJggg=="
7474

75+
DOWNLOAD = "iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAj0lEQVR4nO2UwQmDQBQF5xhIsCh7CEsgfaSGVPW9xGrswIBh4S2EILqbfD2EHZjbdx56ECrOmNwMqwNrWB3YdeAAtBkDrW6LuQMjEBYGgm7ibTFHoAOewHVm4Kx4DzTfDMyNmHSJJxqFYnCQbvHPN5mkazwRgw/pHk+c5M9cgFuh8Zls7O17T5lu+gvhf3kBdHg9SpCbAQgAAAAASUVORK5CYII="
76+
7577
BUTTON_COLOR = (sg.theme_background_color(), sg.theme_background_color())
7678
LARGE_FONT = ("Courier New", 11, "bold")
7779
PERIODO_FMT = "%Y-%m"
@@ -186,6 +188,7 @@ def make_layout():
186188
sg.Input(SearchOptions.PorPagar, size=(40, 1), key="emitidas_search"), # datetime.now().strftime(PERIODO_FMT)
187189
sg.Push(),
188190
sg.Button(image_data=IMPORT_CSV, key="importar_emitidas", border_width=0, button_color=BUTTON_COLOR),
191+
sg.Button(image_data=DOWNLOAD, key="descargar_emitidas", border_width=0, button_color=BUTTON_COLOR),
189192
]],
190193
expand_x=True
191194
)

satdigitalinvoice/mycfdi.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,14 @@ def filename(self):
181181

182182
return os.path.join(self.base_dir, path)
183183

184+
@property
185+
def pdf_filename(self):
186+
return self.filename + ".pdf"
187+
188+
@property
189+
def xml_filename(self):
190+
return self.filename + ".xml"
191+
184192
@classmethod
185193
def uuid_from_filename(cls, filename):
186194
filename = os.path.basename(filename)
@@ -197,16 +205,16 @@ def move_to_folder(cls, xml_data, pdf_data):
197205
os.makedirs(os.path.dirname(full_name), exist_ok=True)
198206

199207
try:
200-
with open(full_name + ".xml", 'xb') as fp:
208+
with open(cfdi.xml_filename, 'xb') as fp:
201209
fp.write(xml_data)
202210
print(f"Factura ha sido agregada: '{full_name}'")
203211

204212
if pdf_data:
205-
with open(full_name + ".pdf", 'wb') as fp:
213+
with open(cfdi.pdf_filename, 'wb') as fp:
206214
fp.write(pdf_data)
207215
else:
208216
try:
209-
render.pdf_write(cfdi, full_name + ".pdf")
217+
render.pdf_write(cfdi, cfdi.pdf_filename)
210218
except:
211219
logger.exception("Fallo crear PDF: '%s'", full_name)
212220
except FileExistsError:

0 commit comments

Comments
 (0)