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