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