Conditions | 10 |
Total Lines | 507 |
Code Lines | 393 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like satdigitalinvoice.layout.make_layout() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | from datetime import date, datetime, timedelta |
||
165 | def make_layout(): |
||
166 | # ----- Full layout ----- |
||
167 | return [ |
||
168 | [ |
||
169 | sg.TabGroup( |
||
170 | [[ |
||
171 | sg.Tab( |
||
172 | 'Emitidas '.center(13), |
||
173 | [ |
||
174 | [ |
||
175 | sg.Column([[ |
||
176 | sg.Button(image_data=FOLDER_ICON, key="ver_emitidas", border_width=0, button_color=BUTTON_COLOR), |
||
177 | sg.ButtonMenu( |
||
178 | image_data=SEARCH_ICON, button_text="", key="buscar_facturas", border_width=0, button_color=BUTTON_COLOR, |
||
179 | menu_def=[ |
||
180 | [], |
||
181 | [str(o) for o in SearchOptions], |
||
182 | ], |
||
183 | ), |
||
184 | sg.Input(datetime.now().strftime(PERIODO_FMT), size=(40, 1), key="emitidas_search"), |
||
185 | sg.Push(), |
||
186 | sg.Button(image_data=IMPORT_CSV, key="importar_emitidas", border_width=0, button_color=BUTTON_COLOR), |
||
187 | ]], |
||
188 | expand_x=True |
||
189 | ) |
||
190 | ], |
||
191 | [ |
||
192 | sg.HorizontalSeparator(color="black"), |
||
193 | ], |
||
194 | [ |
||
195 | sg.Column([[ |
||
196 | sg.Button("".ljust(10), key="status_sat", border_width=0, button_color=sg.theme_background_color()), |
||
197 | sg.Button("".ljust(10), key="email_notificada", border_width=0, button_color=sg.theme_background_color()), |
||
198 | sg.Button("".ljust(10), key="pendiente_pago", border_width=0, button_color=sg.theme_background_color()), |
||
199 | ]]), |
||
200 | sg.VSeparator(color="black"), |
||
201 | sg.Column([[ |
||
202 | sg.CalendarButton("FechaPago:", format=CALENDAR_FECHA_FMT, title="FechaPago", no_titlebar=False, target="fecha_pago", pad=TEXT_PADDING, |
||
203 | border_width=0), |
||
204 | sg.Input(datetime.now().strftime(CALENDAR_FECHA_FMT), size=(12, 1), key="fecha_pago"), |
||
205 | sg.Text("FormaPago:", pad=TEXT_PADDING, border_width=0), |
||
206 | sg.Combo([Code(k, v) for k, v in FORMA_PAGO.items()], |
||
207 | default_value=Code("03", FORMA_PAGO["03"]), key="forma_pago", size=(35, 1)), |
||
208 | sg.Text("ImpPagado:", pad=TEXT_PADDING, border_width=0), |
||
209 | sg.Input("", size=(12, 1), key="importe_pago"), |
||
210 | ]], visible=False, key="ppd_action_items"), |
||
211 | ], |
||
212 | [ |
||
213 | MyTable( |
||
214 | key="emitidas_table", |
||
215 | headings=[ |
||
216 | '#', |
||
217 | 'Receptor Razon Social', |
||
218 | 'Recep. Rfc', |
||
219 | 'Factura', |
||
220 | "Fecha", |
||
221 | "Total", |
||
222 | "Pendiente", |
||
223 | "Status", |
||
224 | "Tipo", |
||
225 | "Folio" |
||
226 | ], |
||
227 | row_fn=lambda i, r: [ |
||
228 | i, |
||
229 | r['Receptor'].get('Nombre', ''), |
||
230 | r['Receptor']['Rfc'], |
||
231 | r.name, |
||
232 | r["Fecha"].strftime(CALENDAR_FECHA_FMT), |
||
233 | r["Total"], |
||
234 | r.saldo_pendiente() or "", |
||
235 | r.liquidated_notified_icons, |
||
236 | mf_pago_fmt(r), |
||
237 | r.uuid |
||
238 | ] |
||
239 | ) |
||
240 | ]], |
||
241 | key='emitidas_tab', |
||
242 | ), |
||
243 | sg.Tab( |
||
244 | 'Recibidas '.center(13), |
||
245 | [ |
||
246 | [ |
||
247 | sg.Column([[ |
||
248 | sg.Button(image_data=FOLDER_ICON, key="ver_recibidas", border_width=0, button_color=BUTTON_COLOR), |
||
249 | sg.ButtonMenu( |
||
250 | image_data=SEARCH_ICON, button_text="", key="buscar_facturas_recibidas", border_width=0, button_color=BUTTON_COLOR, |
||
251 | menu_def=[ |
||
252 | [], |
||
253 | [str(o) for o in SearchOptions], |
||
254 | ], |
||
255 | ), |
||
256 | sg.Input(datetime.now().strftime(PERIODO_FMT), size=(40, 1), key="recibidas_search"), |
||
257 | ]], |
||
258 | expand_x=True |
||
259 | ) |
||
260 | ], |
||
261 | [ |
||
262 | sg.HorizontalSeparator(color="black"), |
||
263 | ], |
||
264 | [ |
||
265 | sg.Column([[ |
||
266 | sg.Button("".ljust(10), key="status_sat_recibidas", border_width=0, button_color=sg.theme_background_color()), |
||
267 | sg.Button("".ljust(10), key="pendiente_pago_recibidas", border_width=0, button_color=sg.theme_background_color()), |
||
268 | ]]), |
||
269 | ], |
||
270 | [ |
||
271 | MyTable( |
||
272 | key="recibidas_table", |
||
273 | headings=[ |
||
274 | '#', |
||
275 | 'Emisor Razon Social', |
||
276 | 'Emisor Rfc', |
||
277 | 'Factura', |
||
278 | "Fecha", |
||
279 | "Total", |
||
280 | "Pendiente", |
||
281 | "Status", |
||
282 | "Tipo", |
||
283 | "Folio" |
||
284 | ], |
||
285 | row_fn=lambda i, r: [ |
||
286 | i, |
||
287 | r['Emisor'].get('Nombre', ''), |
||
288 | r['Emisor']['Rfc'], |
||
289 | r.name, |
||
290 | r["Fecha"].strftime(CALENDAR_FECHA_FMT), |
||
291 | r["Total"], |
||
292 | r.saldo_pendiente() or "", |
||
293 | r.liquidated_notified_icons, |
||
294 | mf_pago_fmt(r), |
||
295 | r.uuid |
||
296 | ] |
||
297 | ) |
||
298 | ]], |
||
299 | key='recibidas_tab', |
||
300 | ), |
||
301 | sg.Tab( |
||
302 | 'Facturas '.center(13), |
||
303 | [ |
||
304 | [ |
||
305 | sg.Button(image_data=EDIT_ICON, key="editar_facturas", border_width=0, button_color=BUTTON_COLOR), |
||
306 | sg.Text("Periodo:", pad=TEXT_PADDING), |
||
307 | sg.Input(date.today().strftime(PERIODO_FMT), size=(11, 1), key="facturas_periodo"), |
||
308 | sg.Text("", pad=TEXT_PADDING, key="preparar_facturas_text", font=LARGE_FONT), |
||
309 | sg.Push(), |
||
310 | sg.Button("Enviar Prediales", key="enviar_prediales"), |
||
311 | ], |
||
312 | [ |
||
313 | MyTable( |
||
314 | key="facturas_table", |
||
315 | headings=[ |
||
316 | '#', |
||
317 | 'EReg', |
||
318 | 'Receptor Razon Social', |
||
319 | 'Recep. Rfc', |
||
320 | "Tipo", |
||
321 | "Subtotal", |
||
322 | "Total" |
||
323 | ], |
||
324 | row_fn=lambda i, r: [ |
||
325 | i, |
||
326 | r['Emisor']['RegimenFiscal'].code, |
||
327 | r['Receptor']['Nombre'], |
||
328 | r['Receptor']['Rfc'], |
||
329 | mf_pago_fmt(r), |
||
330 | r['SubTotal'], |
||
331 | r['Total'] |
||
332 | ] |
||
333 | ) |
||
334 | ]], |
||
335 | key='facturas_tab', |
||
336 | ), |
||
337 | sg.Tab( |
||
338 | 'Productos '.center(13), |
||
339 | [ |
||
340 | [ |
||
341 | sg.Button(image_data=EDIT_ICON, key="editar_productos", border_width=0, button_color=BUTTON_COLOR), |
||
342 | ], |
||
343 | [ |
||
344 | MyTable( |
||
345 | key="productos_table", |
||
346 | headings=[ |
||
347 | '#', |
||
348 | 'Producto', |
||
349 | 'Descripcion', |
||
350 | 'CuentaPredial', |
||
351 | 'ClaveProdServ' |
||
352 | ], |
||
353 | row_fn=lambda i, r: [ |
||
354 | i, |
||
355 | r['Producto'], |
||
356 | r['Concepto']['Descripcion'], |
||
357 | r['Concepto'].get('CuentaPredial'), |
||
358 | r['Concepto']['ClaveProdServ'] |
||
359 | ] |
||
360 | ) |
||
361 | ]], |
||
362 | key='productos_tab', |
||
363 | ), |
||
364 | sg.Tab( |
||
365 | 'Correos'.center(13), |
||
366 | [ |
||
367 | [ |
||
368 | sg.Text("", pad=TEXT_PADDING), |
||
369 | ], |
||
370 | [ |
||
371 | MyTable( |
||
372 | key="correos_table", |
||
373 | headings=[ |
||
374 | '#', |
||
375 | 'Receptor Razon Social', |
||
376 | 'Recep. Rfc', |
||
377 | 'Facturas', |
||
378 | 'Pendientes Emitidas Meses Anteriores' |
||
379 | ], |
||
380 | row_fn=lambda i, r: [ |
||
381 | i, |
||
382 | r[0]["RazonSocial"], |
||
383 | r[0]["Rfc"], |
||
384 | ",".join(n.name for n in r[1]), |
||
385 | ",".join(n.name for n in r[2]) |
||
386 | ] |
||
387 | ) |
||
388 | ]], |
||
389 | key='correos_tab', |
||
390 | ), |
||
391 | sg.Tab( |
||
392 | 'Ajustes'.center(13), |
||
393 | [ |
||
394 | [ |
||
395 | sg.Button(image_data=EDIT_ICON, key="editar_ajustes", border_width=0, button_color=BUTTON_COLOR), |
||
396 | sg.Text("Periodo:", pad=TEXT_PADDING), |
||
397 | sg.Input((date.today() + relativedelta(months=1)).strftime(PERIODO_FMT), size=(11, 1), key="ajustes_periodo"), |
||
398 | sg.Text("", pad=TEXT_PADDING, key="preparar_ajustes_text", font=LARGE_FONT), |
||
399 | ], |
||
400 | [ |
||
401 | MyTable( |
||
402 | key="ajustes_table", |
||
403 | headings=[ |
||
404 | "#", |
||
405 | "Receptor Razon Social", |
||
406 | "Recep. Rfc", |
||
407 | "Producto", |
||
408 | "Actual", |
||
409 | "Nuevo", |
||
410 | "Ajuste %", |
||
411 | "Periodo", |
||
412 | "Meses" |
||
413 | ], |
||
414 | row_fn=lambda i, r: [ |
||
415 | i, |
||
416 | r["receptor"]["RazonSocial"], |
||
417 | r["receptor"]["Rfc"], |
||
418 | r["concepto"].get("_producto"), |
||
419 | r["valor_unitario"], |
||
420 | r["valor_unitario_nuevo"], |
||
421 | r["ajuste_porcentaje"], |
||
422 | r["periodo"], |
||
423 | r["meses"] |
||
424 | ] |
||
425 | ) |
||
426 | ]], |
||
427 | key='ajustes_tab' |
||
428 | ), |
||
429 | sg.Tab( |
||
430 | 'Depositos'.center(13), |
||
431 | [ |
||
432 | [ |
||
433 | sg.Button(image_data=EDIT_ICON, key="editar_depositos", border_width=0, button_color=BUTTON_COLOR), |
||
434 | ], |
||
435 | [ |
||
436 | MyTable( |
||
437 | key="depositos_table", |
||
438 | headings=[ |
||
439 | "#", |
||
440 | "Receptor Razon Social", |
||
441 | "Recep. Rfc", |
||
442 | "Producto", |
||
443 | "Actual", |
||
444 | ], |
||
445 | row_fn=lambda i, r: [ |
||
446 | i, |
||
447 | r["receptor"]["RazonSocial"], |
||
448 | r["receptor"]["Rfc"], |
||
449 | r["concepto"].get("_producto"), |
||
450 | r["deposito"], |
||
451 | ] |
||
452 | ) |
||
453 | ]], |
||
454 | key='depositos_tab' |
||
455 | ), |
||
456 | sg.Tab( |
||
457 | 'Clientes '.center(13), |
||
458 | [ |
||
459 | [ |
||
460 | sg.Button(image_data=EDIT_ICON, key="editar_clientes", border_width=0, button_color=BUTTON_COLOR), |
||
461 | sg.Push(), |
||
462 | sg.Button("Exportar", key="exportar_clientes", border_width=0), |
||
463 | ], |
||
464 | [ |
||
465 | MyTable( |
||
466 | key="clientes_table", |
||
467 | headings=[ |
||
468 | "#", |
||
469 | "Razon Social", |
||
470 | "Rfc", |
||
471 | "Reg", |
||
472 | "CP", |
||
473 | "IdCIF" |
||
474 | ], |
||
475 | row_fn=lambda i, r: [ |
||
476 | i, |
||
477 | r["RazonSocial"], |
||
478 | r["Rfc"], |
||
479 | r["RegimenFiscal"], |
||
480 | r["CodigoPostal"], |
||
481 | r["IdCIF"] |
||
482 | ] |
||
483 | ) |
||
484 | ]], |
||
485 | key='clientes_tab', |
||
486 | ), |
||
487 | sg.Tab( |
||
488 | 'Solicitudes'.center(13), |
||
489 | [ |
||
490 | [ |
||
491 | sg.Column([[ |
||
492 | sg.Button(image_data=ZIP_ICON, key="cargar_zip", border_width=0, button_color=BUTTON_COLOR), |
||
493 | sg.Text("Rfc:", pad=TEXT_PADDING), |
||
494 | sg.Combo([], default_value="", key="solicitudes_rfc", size=(15, 1)), |
||
495 | |||
496 | sg.Text("Recuperar:", pad=TEXT_PADDING), |
||
497 | sg.Combo([TipoRecuperar.Recibidas, TipoRecuperar.Emitidas], default_value=TipoRecuperar.Recibidas, key="tipo_recuperar", size=(10, 1)), |
||
498 | |||
499 | sg.CalendarButton("Inicio:", format=CALENDAR_FECHA_FMT, title="Inicio", no_titlebar=False, target="fecha_inicial", pad=TEXT_PADDING, |
||
500 | border_width=0), |
||
501 | sg.Input((datetime.now() - timedelta(days=40)).strftime(CALENDAR_FECHA_FMT), size=(12, 1), key="fecha_inicial"), |
||
502 | |||
503 | sg.CalendarButton("Final:", format=CALENDAR_FECHA_FMT, title="Final", no_titlebar=False, target="fecha_final", pad=TEXT_PADDING, |
||
504 | border_width=0), |
||
505 | sg.Input(datetime.now().strftime(CALENDAR_FECHA_FMT), size=(12, 1), key="fecha_final"), |
||
506 | |||
507 | sg.Text("Tipo:", pad=TEXT_PADDING), |
||
508 | sg.Combo([TipoDescargaMasivaTerceros.CFDI, TipoDescargaMasivaTerceros.METADATA], default_value=TipoDescargaMasivaTerceros.CFDI, |
||
509 | key="tipo_solicitud", size=(10, 1)), |
||
510 | |||
511 | sg.Button("Nueva Solicitud", key="nueva_solicitud", border_width=0), |
||
512 | ]], |
||
513 | expand_x=True |
||
514 | ) |
||
515 | ], |
||
516 | [ |
||
517 | MyTable( |
||
518 | key="solicitudes_table", |
||
519 | headings=[ |
||
520 | "#", |
||
521 | "IdSolicitud", |
||
522 | "Mensaje", |
||
523 | "EstadoSolicitud", |
||
524 | "FechaInicial", |
||
525 | "FechaFinal", |
||
526 | "TipoSolicitud", |
||
527 | "RfcReceptor", |
||
528 | "RfcEmisor", |
||
529 | ], |
||
530 | row_fn=lambda i, r: [ |
||
531 | i, |
||
532 | r["response"]["IdSolicitud"], |
||
533 | r["response"]["Mensaje"], |
||
534 | r["response"].get("EstadoSolicitud", ""), |
||
535 | r["request"]["fecha_inicial"].strftime(CALENDAR_FECHA_FMT), |
||
536 | r["request"]["fecha_final"].strftime(CALENDAR_FECHA_FMT), |
||
537 | r["request"]["tipo_solicitud"], |
||
538 | r["request"]["rfc_receptor"] or "", |
||
539 | r["request"]["rfc_emisor"] or "", |
||
540 | ] |
||
541 | ) |
||
542 | ] |
||
543 | ], |
||
544 | key='solicitudes_tab', |
||
545 | # visible=has_fiel |
||
546 | ), |
||
547 | sg.Tab( |
||
548 | 'Contabilidad '.center(13), |
||
549 | [ |
||
550 | [ |
||
551 | sg.Column([[ |
||
552 | sg.Text("Rfc:", pad=TEXT_PADDING), |
||
553 | sg.Combo([], default_value="", key="contabilidad_rfc", size=(15, 1)), |
||
554 | sg.Text("Periodo:", pad=TEXT_PADDING), |
||
555 | sg.Input((date.today() - relativedelta(months=1)).strftime(PERIODO_FMT), size=(11, 1), key="periodo"), |
||
556 | sg.Text("Prediales:", pad=TEXT_PADDING), |
||
557 | sg.Input("", size=(11, 1), key="prediales"), |
||
558 | |||
559 | # sg.Button(image_data=EXCEL_ICON, key="ver_excel", border_width=0, button_color=BUTTON_COLOR), |
||
560 | # sg.Button(image_data=DIOT_ICON, key="ver_diot", border_width=0, button_color=BUTTON_COLOR), |
||
561 | sg.Button(image_data=FOLDER_ICON, key="ver_carpeta", border_width=0, button_color=BUTTON_COLOR), |
||
562 | ]]) |
||
563 | ], |
||
564 | [ |
||
565 | sg.Multiline( |
||
566 | expand_x=True, |
||
567 | expand_y=True, |
||
568 | key="declaracion", |
||
569 | write_only=True, |
||
570 | autoscroll=True, |
||
571 | reroute_stdout=True |
||
572 | ) |
||
573 | ] |
||
574 | ], |
||
575 | key='contabilidad_tab', |
||
576 | ), |
||
577 | sg.Tab( |
||
578 | 'Configuracion'.center(13), |
||
579 | [ |
||
580 | [ |
||
581 | sg.Column([ |
||
582 | [ |
||
583 | sg.Button(image_data=FOLDER_ICON, key="projecto_ver", border_width=0, button_color=BUTTON_COLOR), |
||
584 | sg.Button( |
||
585 | border_width=0, |
||
586 | button_text='Seleccionar Projecto', target='projecto_dir_selected', |
||
587 | button_type=BUTTON_TYPE_BROWSE_FOLDER, key='projecto_dir_browse', |
||
588 | ), |
||
589 | sg.Text("", pad=TEXT_PADDING, key="projecto_dir"), |
||
590 | sg.Button("Projecto:", pad=TEXT_PADDING, key='projecto_dir_selected', visible=False, enable_events=True, change_submits=True), |
||
591 | ], |
||
592 | [ |
||
593 | sg.Button(image_data=EDIT_ICON, key="editar_configurar", border_width=0, button_color=BUTTON_COLOR), |
||
594 | ] |
||
595 | ]) |
||
596 | ], |
||
597 | [ |
||
598 | sg.Column([ |
||
599 | [ |
||
600 | sg.Text(" Proxima Factura:", pad=TEXT_PADDING), |
||
601 | sg.Text("Serie:", pad=TEXT_PADDING), |
||
602 | sg.Input("", key="serie", size=(8, 1)), |
||
603 | sg.Text("Folio:", pad=TEXT_PADDING), |
||
604 | sg.Input("", key="folio", size=(8, 1)), |
||
605 | ], |
||
606 | [ |
||
607 | sg.Text("Complemento Pago:", pad=TEXT_PADDING), |
||
608 | sg.Text("Serie:", pad=TEXT_PADDING), |
||
609 | sg.Input("", key="serie_pago", size=(8, 1)), |
||
610 | sg.Text("", key="folio_pago", pad=TEXT_PADDING), |
||
611 | ] |
||
612 | ], |
||
613 | expand_x=True |
||
614 | ) |
||
615 | ], |
||
616 | [ |
||
617 | sg.Column([[]], size=(40, 40)) |
||
618 | ], |
||
619 | [ |
||
620 | sg.Column([[ |
||
621 | sg.Button("Organizar Facturas", key="organizar_facturas", border_width=0), |
||
622 | ]], |
||
623 | expand_x=True |
||
624 | ) |
||
625 | ], |
||
626 | [ |
||
627 | sg.Column([[ |
||
628 | sg.Button("Exportar Metadata ", key="exportar_metadata", border_width=0), |
||
629 | sg.Button("Importar Metadata ", key="importar_metadata", border_width=0), |
||
630 | ]], |
||
631 | expand_x=True |
||
632 | ) |
||
633 | ] |
||
634 | ], |
||
635 | key='configuracion_tab', |
||
636 | ), |
||
637 | sg.Tab( |
||
638 | 'Consola'.center(13), |
||
639 | [ |
||
640 | [ |
||
641 | sg.Push(), |
||
642 | sg.Button(image_data=ABOUT_ICON, key="about", border_width=0, button_color=BUTTON_COLOR), |
||
643 | ], |
||
644 | [sg.Multiline( |
||
645 | expand_x=True, |
||
646 | expand_y=True, |
||
647 | key="console", |
||
648 | write_only=True, |
||
649 | autoscroll=True, |
||
650 | reroute_stdout=True |
||
651 | )] |
||
652 | ], |
||
653 | key='errores_tab', |
||
654 | ), |
||
655 | ]], |
||
656 | expand_x=True, |
||
657 | expand_y=True, |
||
658 | enable_events=True, |
||
659 | key="main_tab_group", |
||
660 | ) |
||
661 | ], |
||
662 | [ |
||
663 | sg.Column([[ |
||
664 | sg.Push(), |
||
665 | sg.Text("Factura:", pad=TEXT_PADDING), |
||
666 | sg.Text("", key="serie_folio", pad=TEXT_PADDING), |
||
667 | sg.Button(image_data=PREVIEW_ICON, key="ver_preview", border_width=0, button_color=BUTTON_COLOR, disabled=True), |
||
668 | sg.Button("".center(22), disabled=True, key="crear_facturas", border_width=0, button_color=sg.theme_background_color()), |
||
669 | sg.Sizegrip(), |
||
670 | ]], |
||
671 | expand_x=True, |
||
672 | ), |
||
719 |