| Conditions | 6 |
| Total Lines | 243 |
| Code Lines | 198 |
| 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 |
||
| 113 | def make_layout(has_fiel, local_db): |
||
| 114 | # LAYOUT |
||
| 115 | button_column = [ |
||
| 116 | sg.Button(image_data=CONFIG_ICON, key="ver_config", border_width=0, button_color=BUTTON_COLOR), |
||
| 117 | sg.Text("Periodo:", pad=TEXT_PADDING), |
||
| 118 | sg.Input(date.today().strftime('%Y-%m'), size=(11, 1), key="periodo"), |
||
| 119 | sg.Button(image_data=FOLDER_ICON, key="ver_carpeta", border_width=0, button_color=BUTTON_COLOR), |
||
| 120 | sg.Button(image_data=EXCEL_ICON, key="ver_excel", border_width=0, button_color=BUTTON_COLOR), |
||
| 121 | sg.Button(image_data=HTML_ICON, key="ver_html", border_width=0, button_color=BUTTON_COLOR), |
||
| 122 | |||
| 123 | sg.Push(), |
||
| 124 | sg.Text("Factura:", pad=TEXT_PADDING), |
||
| 125 | sg.Text("", key="serie", pad=TEXT_PADDING, text_color="black"), |
||
| 126 | sg.Input("", key="folio", size=(8, 1), enable_events=True), |
||
| 127 | sg.Button("".center(22), disabled=True, key="crear_facturas", border_width=0, button_color=sg.theme_background_color()), |
||
| 128 | ] |
||
| 129 | |||
| 130 | # ----- Full layout ----- |
||
| 131 | return [ |
||
| 132 | button_column, |
||
| 133 | [ |
||
| 134 | sg.TabGroup( |
||
| 135 | [[ |
||
| 136 | sg.Tab( |
||
| 137 | 'Consola'.center(13), |
||
| 138 | [ |
||
| 139 | [ |
||
| 140 | sg.Push(), |
||
| 141 | sg.Button(image_data=ABOUT_ICON, key="about", border_width=0, button_color=BUTTON_COLOR), |
||
| 142 | ], |
||
| 143 | [sg.Multiline( |
||
| 144 | expand_x=True, |
||
| 145 | expand_y=True, |
||
| 146 | key="console", |
||
| 147 | write_only=True, |
||
| 148 | autoscroll=True, |
||
| 149 | reroute_stdout=True |
||
| 150 | )] |
||
| 151 | ], |
||
| 152 | key='console_tab', |
||
| 153 | ), |
||
| 154 | sg.Tab( |
||
| 155 | 'Clientes'.center(13), |
||
| 156 | [ |
||
| 157 | [ |
||
| 158 | sg.Button("Refrescar", key="refresh_clientes", border_width=0), |
||
| 159 | sg.Push(), |
||
| 160 | sg.Button(image_data=EDIT_ICON, key="editar_clientes", border_width=0, button_color=BUTTON_COLOR), |
||
| 161 | ], |
||
| 162 | [ |
||
| 163 | MyTable( |
||
| 164 | key="clientes_table", |
||
| 165 | headings=[ |
||
| 166 | "#", |
||
| 167 | "Razon Social", |
||
| 168 | "Rfc", |
||
| 169 | "Reg", |
||
| 170 | "CP" |
||
| 171 | ], |
||
| 172 | row_fn=lambda i, r: [ |
||
| 173 | i, |
||
| 174 | r["RazonSocial"], |
||
| 175 | r["Rfc"], |
||
| 176 | r["RegimenFiscal"].code, |
||
| 177 | r["CodigoPostal"] |
||
| 178 | ] |
||
| 179 | ) |
||
| 180 | ]], |
||
| 181 | key='clients_tab', |
||
| 182 | ), |
||
| 183 | sg.Tab( |
||
| 184 | 'Facturas'.center(13), |
||
| 185 | [ |
||
| 186 | [ |
||
| 187 | sg.Button("Refrescar", key="refresh_facturas", border_width=0, ), |
||
| 188 | sg.Text("", pad=TEXT_PADDING, key="preparar_facturas_text"), |
||
| 189 | sg.Push(), |
||
| 190 | sg.Button(image_data=EDIT_ICON, key="editar_facturas", border_width=0, button_color=BUTTON_COLOR), |
||
| 191 | ], |
||
| 192 | [ |
||
| 193 | MyTable( |
||
| 194 | key="facturas_table", |
||
| 195 | headings=[ |
||
| 196 | '#', |
||
| 197 | 'EReg', |
||
| 198 | 'Receptor Razon Social', |
||
| 199 | 'Recep. Rfc', |
||
| 200 | "Tipo", |
||
| 201 | "Subtotal", |
||
| 202 | "Total" |
||
| 203 | ], |
||
| 204 | row_fn=lambda i, r: [ |
||
| 205 | i, |
||
| 206 | r['Emisor']['RegimenFiscal'].code, |
||
| 207 | r['Receptor']['Nombre'], |
||
| 208 | r['Receptor']['Rfc'], |
||
| 209 | mf_pago_fmt(r), |
||
| 210 | r['SubTotal'], |
||
| 211 | r['Total'] |
||
| 212 | ] |
||
| 213 | ) |
||
| 214 | ]], |
||
| 215 | key='facturas_tab', |
||
| 216 | ), |
||
| 217 | sg.Tab( |
||
| 218 | 'Emitidas'.center(13), |
||
| 219 | [ |
||
| 220 | [ |
||
| 221 | sg.Button("Pendientes", key="facturas_pendientes", border_width=0), |
||
| 222 | sg.Button("Todas", key="facturas_emitidas", border_width=0), |
||
| 223 | sg.Button(image_data=SEARCH_ICON, key="emitidas_search_enter", border_width=0, button_color=BUTTON_COLOR), |
||
| 224 | sg.Input("", size=(20, 1), key="emitidas_search", border_width=0), |
||
| 225 | sg.Text("", pad=TEXT_PADDING, key="emitidas_text"), |
||
| 226 | ], |
||
| 227 | [ |
||
| 228 | sg.Column([[ |
||
| 229 | sg.Button("".ljust(10), key="status_sat", border_width=0, button_color=sg.theme_background_color()), |
||
| 230 | sg.Button("".ljust(10), key="email_notificada", border_width=0, button_color=sg.theme_background_color()), |
||
| 231 | sg.Button("".ljust(10), key="pendiente_pago", border_width=0, button_color=sg.theme_background_color()), |
||
| 232 | ]]), |
||
| 233 | sg.VSeparator(), |
||
| 234 | sg.Column([[ |
||
| 235 | sg.CalendarButton("FechaPago:", format='%Y-%m-%d', title="FechaPago", no_titlebar=False, target="fecha_pago", pad=TEXT_PADDING, |
||
| 236 | border_width=0, |
||
| 237 | key="fecha_pago_select"), |
||
| 238 | sg.Input(datetime.now().strftime('%Y-%m-%d'), size=(12, 1), key="fecha_pago", border_width=0), |
||
| 239 | sg.Combo([Code(k, v) for k, v in FORMA_PAGO.items()], default_value=Code("03", FORMA_PAGO["03"]), key="forma_pago", size=(28, 1)), |
||
|
|
|||
| 240 | sg.Text("ImpPagado:", pad=TEXT_PADDING, key="imp_pagado_text", border_width=0), |
||
| 241 | sg.Input("", size=(12, 1), key="importe_pago", border_width=0), |
||
| 242 | sg.Button("Comprobante Pago", key="prepare_pago", border_width=0), |
||
| 243 | sg.Button(image_data=PREVIEW_ICON, key="ver_html_pago", border_width=0, button_color=BUTTON_COLOR), |
||
| 244 | ]], visible=False, key="ppd_action_items"), |
||
| 245 | ], |
||
| 246 | [ |
||
| 247 | MyTable( |
||
| 248 | key="emitidas_table", |
||
| 249 | headings=[ |
||
| 250 | '#', |
||
| 251 | 'Receptor Razon Social', |
||
| 252 | 'Recep. Rfc', |
||
| 253 | 'Factura', |
||
| 254 | "Fecha", |
||
| 255 | "Total", |
||
| 256 | "Pagada", |
||
| 257 | "Tipo", |
||
| 258 | ], |
||
| 259 | row_fn=lambda i, r: [ |
||
| 260 | i, |
||
| 261 | r['Receptor'].get('Nombre', ''), |
||
| 262 | r['Receptor']['Rfc'], |
||
| 263 | r.name, |
||
| 264 | r["Fecha"].strftime("%Y-%m-%d"), |
||
| 265 | r["Total"], |
||
| 266 | local_db.liquidated_state(r), |
||
| 267 | mf_pago_fmt(r) |
||
| 268 | ] |
||
| 269 | ) |
||
| 270 | ]], |
||
| 271 | key='emitidas_tab', |
||
| 272 | ), |
||
| 273 | sg.Tab( |
||
| 274 | 'Correos'.center(13), |
||
| 275 | [ |
||
| 276 | [ |
||
| 277 | sg.Button("Refrescar", key="refresh_correos", border_width=0, ), |
||
| 278 | ], |
||
| 279 | [ |
||
| 280 | MyTable( |
||
| 281 | key="correos_table", |
||
| 282 | headings=[ |
||
| 283 | '#', |
||
| 284 | 'Receptor Razon Social', |
||
| 285 | 'Recep. Rfc', |
||
| 286 | 'Facturas', |
||
| 287 | 'Pendientes Emitidas Meses Anteriores' |
||
| 288 | ], |
||
| 289 | row_fn=lambda i, r: [ |
||
| 290 | i, |
||
| 291 | r[0]["RazonSocial"][0:36], |
||
| 292 | r[0]["Rfc"], |
||
| 293 | ",".join(n.name for n in r[1]), |
||
| 294 | ",".join(n.name for n in r[2]) |
||
| 295 | ] |
||
| 296 | ) |
||
| 297 | ]], |
||
| 298 | key='correos_tab', |
||
| 299 | ), |
||
| 300 | sg.Tab( |
||
| 301 | 'Ajustes'.center(13), |
||
| 302 | [ |
||
| 303 | [ |
||
| 304 | sg.Button("Refrescar", key="refresh_ajustes", border_width=0, ), |
||
| 305 | sg.Text("", pad=TEXT_PADDING, key="preparar_ajustes_text"), |
||
| 306 | ], |
||
| 307 | [ |
||
| 308 | MyTable( |
||
| 309 | key="ajustes_table", |
||
| 310 | headings=[ |
||
| 311 | "#", |
||
| 312 | "Receptor Razon Social", |
||
| 313 | "Recep. Rfc", |
||
| 314 | "Actual", |
||
| 315 | "Nuevo", |
||
| 316 | "Ajuste %", |
||
| 317 | "Periodo", |
||
| 318 | "Meses", |
||
| 319 | "Ajuste Efectivo" |
||
| 320 | ], |
||
| 321 | row_fn=lambda i, r: [ |
||
| 322 | i, |
||
| 323 | r["receptor"]["RazonSocial"], |
||
| 324 | r["receptor"]["Rfc"], |
||
| 325 | r["valor_unitario"], |
||
| 326 | r["valor_unitario_nuevo"], |
||
| 327 | r["ajuste_porcentaje"].split(' ')[0], |
||
| 328 | r["periodo"], |
||
| 329 | r["meses"], |
||
| 330 | r["efectivo_periodo_desc"] |
||
| 331 | ] |
||
| 332 | ) |
||
| 333 | ]], |
||
| 334 | key='ajustes_tab' |
||
| 335 | ), |
||
| 336 | sg.Tab( |
||
| 337 | 'Recuperar'.center(13), |
||
| 338 | [ |
||
| 339 | [ |
||
| 340 | sg.Button("SAT Status", key="sat_status_todas", border_width=0), |
||
| 341 | sg.Text("Recuperar:", pad=TEXT_PADDING), |
||
| 342 | sg.Button("Emitidas ", key="recuperar_emitidas", border_width=0), |
||
| 343 | sg.Button("Recibidas", key="recuperar_recibidas", border_width=0), |
||
| 344 | sg.Text("Dias:", pad=TEXT_PADDING), |
||
| 345 | sg.Input("40", size=(4, 1), key="recuperar_dias"), |
||
| 346 | ] |
||
| 347 | ], |
||
| 348 | key='recuperar_tab', |
||
| 349 | visible=has_fiel |
||
| 350 | ), |
||
| 351 | ]], |
||
| 352 | expand_x=True, |
||
| 353 | expand_y=True, |
||
| 354 | enable_events=True, |
||
| 355 | key="main_tab_group", |
||
| 356 | ) |
||
| 389 |