Conditions | 13 |
Total Lines | 441 |
Code Lines | 344 |
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 |
||
160 | def make_layout(has_fiel, local_db): |
||
161 | # ----- Full layout ----- |
||
162 | return [ |
||
163 | [ |
||
164 | sg.TabGroup( |
||
165 | [[ |
||
166 | sg.Tab( |
||
167 | 'Emitidas '.center(13), |
||
168 | [ |
||
169 | [ |
||
170 | sg.Column([[ |
||
171 | sg.Button(image_data=IMPORT_CSV, key="importar_emitidas", border_width=0, button_color=BUTTON_COLOR), |
||
172 | sg.ButtonMenu( |
||
173 | image_data=SEARCH_ICON, button_text="", key="buscar_facturas", border_width=0, button_color=BUTTON_COLOR, |
||
174 | menu_def=[ |
||
175 | [], |
||
176 | [str(o) for o in SearchOptions], |
||
177 | ], |
||
178 | ), |
||
179 | sg.Input(datetime.now().strftime(PERIODO_FMT), size=(40, 1), key="emitidas_search"), |
||
180 | ]], |
||
181 | expand_x=True |
||
182 | ) |
||
183 | ], |
||
184 | [ |
||
185 | sg.HorizontalSeparator(color="black"), |
||
186 | ], |
||
187 | [ |
||
188 | sg.Column([[ |
||
189 | sg.Button("".ljust(10), key="status_sat", border_width=0, button_color=sg.theme_background_color()), |
||
190 | sg.Button("".ljust(10), key="email_notificada", border_width=0, button_color=sg.theme_background_color()), |
||
191 | sg.Button("".ljust(10), key="pendiente_pago", border_width=0, button_color=sg.theme_background_color()), |
||
192 | ]]), |
||
193 | sg.VSeparator(color="black"), |
||
194 | sg.Column([[ |
||
195 | sg.CalendarButton("FechaPago:", format=CALENDAR_FECHA_FMT, title="FechaPago", no_titlebar=False, target="fecha_pago", pad=TEXT_PADDING, |
||
196 | border_width=0), |
||
197 | sg.Input(datetime.now().strftime(CALENDAR_FECHA_FMT), size=(12, 1), key="fecha_pago"), |
||
198 | sg.Text("FormaPago:", pad=TEXT_PADDING, border_width=0), |
||
199 | sg.Combo([Code(k, v) for k, v in FORMA_PAGO.items()], |
||
200 | default_value=Code("03", FORMA_PAGO["03"]), key="forma_pago", size=(35, 1)), |
||
201 | sg.Text("ImpPagado:", pad=TEXT_PADDING, border_width=0), |
||
202 | sg.Input("", size=(12, 1), key="importe_pago"), |
||
203 | ]], visible=False, key="ppd_action_items"), |
||
204 | ], |
||
205 | [ |
||
206 | MyTable( |
||
207 | key="emitidas_table", |
||
208 | headings=[ |
||
209 | '#', |
||
210 | 'Receptor Razon Social', |
||
211 | 'Recep. Rfc', |
||
212 | 'Factura', |
||
213 | "Fecha", |
||
214 | "Total", |
||
215 | "Pendiente", |
||
216 | "Status", |
||
217 | "Tipo", |
||
218 | "Folio" |
||
219 | ], |
||
220 | row_fn=lambda i, r: [ |
||
221 | i, |
||
222 | r['Receptor'].get('Nombre', ''), |
||
223 | r['Receptor']['Rfc'], |
||
224 | r.name, |
||
225 | r["Fecha"].strftime(CALENDAR_FECHA_FMT), |
||
226 | r["Total"], |
||
227 | r.saldo_pendiente if r.saldo_pendiente else "", |
||
228 | str(local_db.liquidated_state(r)) + str(" 📧" if local_db.notified(r) else " "), |
||
229 | mf_pago_fmt(r), |
||
230 | r.uuid |
||
231 | ] |
||
232 | ) |
||
233 | ]], |
||
234 | key='emitidas_tab', |
||
235 | ), |
||
236 | sg.Tab( |
||
237 | 'Recibidas '.center(13), |
||
238 | [ |
||
239 | [ |
||
240 | sg.Column([[ |
||
241 | sg.Button(image_data=IMPORT_CSV, key="importar_recibidas", border_width=0, button_color=BUTTON_COLOR), |
||
242 | sg.ButtonMenu( |
||
243 | image_data=SEARCH_ICON, button_text="", key="buscar_facturas_recibidas", border_width=0, button_color=BUTTON_COLOR, |
||
244 | menu_def=[ |
||
245 | [], |
||
246 | [str(o) for o in SearchOptions], |
||
247 | ], |
||
248 | ), |
||
249 | sg.Input(datetime.now().strftime(PERIODO_FMT), size=(40, 1), key="recibidas_search"), |
||
250 | ]], |
||
251 | expand_x=True |
||
252 | ) |
||
253 | ], |
||
254 | [ |
||
255 | sg.HorizontalSeparator(color="black"), |
||
256 | ], |
||
257 | [ |
||
258 | MyTable( |
||
259 | key="recibidas_table", |
||
260 | headings=[ |
||
261 | '#', |
||
262 | 'Emisor Razon Social', |
||
263 | 'Emisor Rfc', |
||
264 | 'Factura', |
||
265 | "Fecha", |
||
266 | "Total", |
||
267 | "Pendiente", |
||
268 | "Status", |
||
269 | "Tipo", |
||
270 | "Folio" |
||
271 | ], |
||
272 | row_fn=lambda i, r: [ |
||
273 | i, |
||
274 | r['Emisor'].get('Nombre', ''), |
||
275 | r['Emisor']['Rfc'], |
||
276 | r.name, |
||
277 | r["Fecha"].strftime(CALENDAR_FECHA_FMT), |
||
278 | r["Total"], |
||
279 | r.saldo_pendiente if r.saldo_pendiente else "", |
||
280 | str(local_db.liquidated_state(r)) + str(" 📧" if local_db.notified(r) else " "), |
||
281 | mf_pago_fmt(r), |
||
282 | r.uuid |
||
283 | ] |
||
284 | ) |
||
285 | ]], |
||
286 | key='recibidas_tab', |
||
287 | ), |
||
288 | sg.Tab( |
||
289 | 'Facturas '.center(13), |
||
290 | [ |
||
291 | [ |
||
292 | sg.Button(image_data=EDIT_ICON, key="editar_facturas", border_width=0, button_color=BUTTON_COLOR), |
||
293 | sg.Text("Periodo:", pad=TEXT_PADDING), |
||
294 | sg.Input(date.today().strftime(PERIODO_FMT), size=(11, 1), key="facturas_periodo"), |
||
295 | sg.Text("", pad=TEXT_PADDING, key="preparar_facturas_text", font=LARGE_FONT), |
||
296 | ], |
||
297 | [ |
||
298 | MyTable( |
||
299 | key="facturas_table", |
||
300 | headings=[ |
||
301 | '#', |
||
302 | 'EReg', |
||
303 | 'Receptor Razon Social', |
||
304 | 'Recep. Rfc', |
||
305 | "Tipo", |
||
306 | "Subtotal", |
||
307 | "Total" |
||
308 | ], |
||
309 | row_fn=lambda i, r: [ |
||
310 | i, |
||
311 | r['Emisor']['RegimenFiscal'].code, |
||
312 | r['Receptor']['Nombre'], |
||
313 | r['Receptor']['Rfc'], |
||
314 | mf_pago_fmt(r), |
||
315 | r['SubTotal'], |
||
316 | r['Total'] |
||
317 | ] |
||
318 | ) |
||
319 | ]], |
||
320 | key='facturas_tab', |
||
321 | ), |
||
322 | sg.Tab( |
||
323 | 'Correos'.center(13), |
||
324 | [ |
||
325 | [ |
||
326 | sg.Text("", pad=TEXT_PADDING), |
||
327 | ], |
||
328 | [ |
||
329 | MyTable( |
||
330 | key="correos_table", |
||
331 | headings=[ |
||
332 | '#', |
||
333 | 'Receptor Razon Social', |
||
334 | 'Recep. Rfc', |
||
335 | 'Facturas', |
||
336 | 'Pendientes Emitidas Meses Anteriores' |
||
337 | ], |
||
338 | row_fn=lambda i, r: [ |
||
339 | i, |
||
340 | r[0]["RazonSocial"], |
||
341 | r[0]["Rfc"], |
||
342 | ",".join(n.name for n in r[1]), |
||
343 | ",".join(n.name for n in r[2]) |
||
344 | ] |
||
345 | ) |
||
346 | ]], |
||
347 | key='correos_tab', |
||
348 | ), |
||
349 | sg.Tab( |
||
350 | 'Ajustes'.center(13), |
||
351 | [ |
||
352 | [ |
||
353 | sg.Button(image_data=EDIT_ICON, key="editar_ajustes", border_width=0, button_color=BUTTON_COLOR), |
||
354 | sg.Text("Periodo:", pad=TEXT_PADDING), |
||
355 | sg.Input(date.today().strftime(PERIODO_FMT), size=(11, 1), key="ajustes_periodo"), |
||
356 | sg.Text("", pad=TEXT_PADDING, key="preparar_ajustes_text", font=LARGE_FONT), |
||
357 | ], |
||
358 | [ |
||
359 | MyTable( |
||
360 | key="ajustes_table", |
||
361 | headings=[ |
||
362 | "#", |
||
363 | "Receptor Razon Social", |
||
364 | "Recep. Rfc", |
||
365 | "Actual", |
||
366 | "Nuevo", |
||
367 | "Ajuste %", |
||
368 | "Periodo", |
||
369 | "Meses", |
||
370 | "Ajuste Efectivo" |
||
371 | ], |
||
372 | row_fn=lambda i, r: [ |
||
373 | i, |
||
374 | r["receptor"]["RazonSocial"], |
||
375 | r["receptor"]["Rfc"], |
||
376 | r["valor_unitario"], |
||
377 | r["valor_unitario_nuevo"], |
||
378 | r["ajuste_porcentaje"], |
||
379 | r["periodo"], |
||
380 | r["meses"], |
||
381 | r["efectivo_periodo_desc"] |
||
382 | ] |
||
383 | ) |
||
384 | ]], |
||
385 | key='ajustes_tab' |
||
386 | ), |
||
387 | sg.Tab( |
||
388 | 'Depositos'.center(13), |
||
389 | [ |
||
390 | [ |
||
391 | sg.Button(image_data=EDIT_ICON, key="editar_depositos", border_width=0, button_color=BUTTON_COLOR), |
||
392 | sg.Text("Periodo:", pad=TEXT_PADDING), |
||
393 | sg.Input(date.today().strftime(PERIODO_FMT), size=(11, 1), key="depositos_periodo"), |
||
394 | sg.Text("", pad=TEXT_PADDING, key="preparar_depositos_text", font=LARGE_FONT), |
||
395 | ], |
||
396 | [ |
||
397 | MyTable( |
||
398 | key="depositos_table", |
||
399 | headings=[ |
||
400 | "#", |
||
401 | "Receptor Razon Social", |
||
402 | "Recep. Rfc", |
||
403 | "Actual", |
||
404 | ], |
||
405 | row_fn=lambda i, r: [ |
||
406 | i, |
||
407 | r["receptor"]["RazonSocial"], |
||
408 | r["receptor"]["Rfc"], |
||
409 | r["valor_unitario"], |
||
410 | ] |
||
411 | ) |
||
412 | ]], |
||
413 | key='depositos_tab' |
||
414 | ), |
||
415 | sg.Tab( |
||
416 | 'Clientes '.center(13), |
||
417 | [ |
||
418 | [ |
||
419 | sg.Button(image_data=EDIT_ICON, key="editar_clientes", border_width=0, button_color=BUTTON_COLOR), |
||
420 | sg.Push(), |
||
421 | sg.Button("Exportar", key="exportar_clientes", border_width=0), |
||
422 | ], |
||
423 | [ |
||
424 | MyTable( |
||
425 | key="clientes_table", |
||
426 | headings=[ |
||
427 | "#", |
||
428 | "Razon Social", |
||
429 | "Rfc", |
||
430 | "Reg", |
||
431 | "CP", |
||
432 | "IdCIF" |
||
433 | ], |
||
434 | row_fn=lambda i, r: [ |
||
435 | i, |
||
436 | r["RazonSocial"], |
||
437 | r["Rfc"], |
||
438 | r["RegimenFiscal"], |
||
439 | r["CodigoPostal"], |
||
440 | r["IdCIF"] |
||
441 | ] |
||
442 | ) |
||
443 | ]], |
||
444 | key='clientes_tab', |
||
445 | ), |
||
446 | sg.Tab( |
||
447 | 'Solicitudes'.center(13), |
||
448 | [ |
||
449 | [ |
||
450 | sg.Column([[ |
||
451 | sg.Button(image_data=ZIP_ICON, key="cargar_zip", border_width=0, button_color=BUTTON_COLOR), |
||
452 | sg.Text("Recuperar:", pad=TEXT_PADDING), |
||
453 | sg.Combo([TipoRecuperar.Recibidas, TipoRecuperar.Emitidas], default_value=TipoRecuperar.Recibidas, key="tipo_recuperar", size=(10, 1)), |
||
454 | |||
455 | sg.CalendarButton("Inicio:", format=CALENDAR_FECHA_FMT, title="Inicio", no_titlebar=False, target="fecha_inicial", pad=TEXT_PADDING, |
||
456 | border_width=0), |
||
457 | sg.Input((datetime.now() - timedelta(days=40)).strftime(CALENDAR_FECHA_FMT), size=(12, 1), key="fecha_inicial"), |
||
458 | |||
459 | sg.CalendarButton("Final:", format=CALENDAR_FECHA_FMT, title="Final", no_titlebar=False, target="fecha_final", pad=TEXT_PADDING, |
||
460 | border_width=0), |
||
461 | sg.Input(datetime.now().strftime(CALENDAR_FECHA_FMT), size=(12, 1), key="fecha_final"), |
||
462 | |||
463 | sg.Text("Tipo:", pad=TEXT_PADDING), |
||
464 | sg.Combo([TipoDescargaMasivaTerceros.CFDI, TipoDescargaMasivaTerceros.METADATA], default_value=TipoDescargaMasivaTerceros.CFDI, |
||
465 | key="tipo_solicitud", size=(10, 1)), |
||
466 | |||
467 | sg.Button("Nueva Solicitud", key="nueva_solicitud", border_width=0), |
||
468 | ]], |
||
469 | expand_x=True |
||
470 | ) |
||
471 | ], |
||
472 | [ |
||
473 | MyTable( |
||
474 | key="solicitudes_table", |
||
475 | headings=[ |
||
476 | "#", |
||
477 | "IdSolicitud", |
||
478 | "Mensaje", |
||
479 | "EstadoSolicitud", |
||
480 | "FechaInicial", |
||
481 | "FechaFinal", |
||
482 | "TipoSolicitud", |
||
483 | "RfcReceptor", |
||
484 | "RfcEmisor", |
||
485 | ], |
||
486 | row_fn=lambda i, r: [ |
||
487 | i, |
||
488 | r["response"]["IdSolicitud"], |
||
489 | r["response"]["Mensaje"], |
||
490 | r["response"].get("EstadoSolicitud", ""), |
||
491 | r["request"]["fecha_inicial"].strftime(CALENDAR_FECHA_FMT), |
||
492 | r["request"]["fecha_final"].strftime(CALENDAR_FECHA_FMT), |
||
493 | r["request"]["tipo_solicitud"], |
||
494 | r["request"]["rfc_receptor"] or "", |
||
495 | r["request"]["rfc_emisor"] or "", |
||
496 | ] |
||
497 | ) |
||
498 | ] |
||
499 | ], |
||
500 | key='solicitudes_tab', |
||
501 | # visible=has_fiel |
||
502 | ), |
||
503 | sg.Tab( |
||
504 | 'Contabilidad '.center(13), |
||
505 | [[ |
||
506 | sg.Column([[ |
||
507 | sg.Text("Periodo:", pad=TEXT_PADDING), |
||
508 | sg.Input(date.today().strftime(PERIODO_FMT), size=(11, 1), key="periodo"), |
||
509 | sg.Button(image_data=EXCEL_ICON, key="ver_excel", border_width=0, button_color=BUTTON_COLOR), |
||
510 | sg.Button(image_data=FOLDER_ICON, key="ver_carpeta", border_width=0, button_color=BUTTON_COLOR), |
||
511 | ]]) |
||
512 | ]], |
||
513 | key='contabilidad_tab', |
||
514 | ), |
||
515 | sg.Tab( |
||
516 | 'Consola'.center(13), |
||
517 | [ |
||
518 | [ |
||
519 | sg.Push(), |
||
520 | sg.Button(image_data=ABOUT_ICON, key="about", border_width=0, button_color=BUTTON_COLOR), |
||
521 | ], |
||
522 | [sg.Multiline( |
||
523 | expand_x=True, |
||
524 | expand_y=True, |
||
525 | key="console", |
||
526 | write_only=True, |
||
527 | autoscroll=True, |
||
528 | reroute_stdout=True |
||
529 | )] |
||
530 | ], |
||
531 | key='errores_tab', |
||
532 | ), |
||
533 | sg.Tab( |
||
534 | 'Configuracion'.center(13), |
||
535 | [ |
||
536 | [ |
||
537 | sg.Column([[ |
||
538 | sg.Button(image_data=EDIT_ICON, key="editar_configurar", border_width=0, button_color=BUTTON_COLOR), |
||
539 | sg.Button(image_data=CONFIG_ICON, key="ver_config", border_width=0, button_color=BUTTON_COLOR), |
||
540 | ]]) |
||
541 | ], |
||
542 | [ |
||
543 | sg.Column([[ |
||
544 | sg.Text(" Proxima Factura:", pad=TEXT_PADDING), |
||
545 | sg.Text("Serie:", pad=TEXT_PADDING), |
||
546 | sg.Input("", key="serie", size=(8, 1)), |
||
547 | sg.Text("Folio:", pad=TEXT_PADDING), |
||
548 | sg.Input("", key="folio", size=(8, 1)), |
||
549 | ]], |
||
550 | expand_x=True |
||
551 | ) |
||
552 | ], |
||
553 | [ |
||
554 | sg.Column([[ |
||
555 | sg.Text("Complemento Pago:", pad=TEXT_PADDING), |
||
556 | sg.Text("Serie:", pad=TEXT_PADDING), |
||
557 | sg.Input("", key="serie_pago", size=(8, 1)), |
||
558 | sg.Text("", key="folio_pago", pad=TEXT_PADDING), |
||
559 | ]], |
||
560 | expand_x=True |
||
561 | ) |
||
562 | ], |
||
563 | [ |
||
564 | sg.Column([[]], size=(40, 40)) |
||
565 | ], |
||
566 | [ |
||
567 | sg.Column([[ |
||
568 | sg.Button("Organizar Facturas", key="organizar_facturas", border_width=0), |
||
569 | ]], |
||
570 | expand_x=True |
||
571 | ) |
||
572 | ], |
||
573 | [ |
||
574 | sg.Column([[ |
||
575 | sg.Button("Exportar Metadata ", key="exportar_metadata", border_width=0), |
||
576 | sg.Button("Importar Metadata ", key="importar_metadata", border_width=0), |
||
577 | ]], |
||
578 | expand_x=True |
||
579 | ) |
||
580 | ] |
||
581 | ], |
||
582 | key='configuracion_tab', |
||
583 | ), |
||
584 | ]], |
||
585 | expand_x=True, |
||
586 | expand_y=True, |
||
587 | enable_events=True, |
||
588 | key="main_tab_group", |
||
589 | ) |
||
590 | ], |
||
591 | [ |
||
592 | sg.Column([[ |
||
593 | sg.Push(), |
||
594 | sg.Text("Factura:", pad=TEXT_PADDING), |
||
595 | sg.Text("", key="serie_folio", pad=TEXT_PADDING), |
||
596 | sg.Button(image_data=PREVIEW_ICON, key="ver_preview", border_width=0, button_color=BUTTON_COLOR, disabled=True), |
||
597 | sg.Button("".center(22), disabled=True, key="crear_facturas", border_width=0, button_color=sg.theme_background_color()), |
||
598 | sg.Sizegrip(), |
||
599 | ]], |
||
600 | expand_x=True, |
||
601 | ), |
||
648 |