Test Failed
Push — main ( 7896a5...57c1a0 )
by Sat CFDI
03:17
created

ConfirmPagoButtonManager.set_confirm_pago()   A

Complexity

Conditions 1

Size

Total Lines 5
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nop 2
1
from datetime import date, timedelta
2
3
import PySimpleGUI as sg
4
# noinspection PyUnresolvedReferences
5
from satcfdi.transform.catalog import CATALOGS
6
7
from .log_tools import *
8
9
logging.basicConfig(level=logging.DEBUG)
10
logger = LogAdapter(logging.getLogger())
11
12
FORMA_PAGO = CATALOGS['{http://www.sat.gob.mx/sitio_internet/cfd/catalogos}c_FormaPago']
13
TEXT_PADDING = ((5, 0), 3)
14
RTEXT_PADDING = ((0, 0), 3)
15
16
17
def make_layout():
18
    # LAYOUT
19
    button_column = [
20
        sg.Button("Preparar Facturas", key="prepare_facturas"),
21
        sg.Text("Año-Mes:", pad=TEXT_PADDING),
22
        sg.Input(date.today().strftime('%Y-%m'), size=(8, 1), key="periodo", change_submits=True),
23
        sg.Text("De La:", pad=TEXT_PADDING),
24
        sg.Input("1", key="inicio", size=(4, 1), change_submits=True),
25
        sg.Text("Hasta:", pad=TEXT_PADDING),
26
        sg.Input("", key="final", size=(4, 1), change_submits=True),
27
    ]
28
29
    c_second = [
30
        sg.Column(
31
            [
32
                [
33
                    sg.Text("Factura:", pad=TEXT_PADDING),
34
                    sg.Input("", size=(30, 1), key="factura_pagar", change_submits=True),
35
                ],
36
                [
37
                    sg.Button("Status", key="status_sat"),
38
                    sg.Button("Descarga", key="descarga"),
39
                    sg.Button("Pago PUE", key="pago_pue"),
40
                ]
41
            ],
42
            pad=0
43
        ),
44
        sg.VSeparator(),
45
        sg.Column(
46
            [
47
                [
48
                    sg.CalendarButton("FechaPago:", format='%Y-%m-%d', title="FechaPago", no_titlebar=False, target="fecha_pago", pad=TEXT_PADDING),
49
                    sg.Input("", size=(12, 1), key="fecha_pago", change_submits=True),
50
                    sg.Text("FormaPago:", pad=TEXT_PADDING),
51
                    sg.Combo([Code(k, v) for k, v in FORMA_PAGO.items()], default_value=Code("03", FORMA_PAGO["03"]), key="forma_pago", change_submits=True, size=(34, 1))
52
                ],
53
                [
54
                    sg.Button("Comprobante Pago", key="prepare_pago"),
55
                ]
56
            ],
57
            pad=0
58
        )
59
    ]
60
61
    button_column_third = [
62
        sg.Button("Preparar Correos", key="prepare_correos"),
63
        sg.Button("Facturas Pendientes", key="facturas_pendientes"),
64
        sg.Checkbox("Ver Detallado", default=False, key="detallado"),
65
        sg.VSeparator(),
66
        sg.Button("Ajuste Anual", key="preparar_ajuste_anual"),
67
        sg.Text("Año-Mes:", pad=TEXT_PADDING),
68
        sg.Input((date.today() + timedelta(days=31)).strftime('%Y-%m'), size=(8, 1), key="anio_mes_ajuste"),
69
        sg.Text("Ajuste:", pad=TEXT_PADDING),
70
        sg.Input("", size=(6, 1), key="ajuste_porcentaje"),
71
        sg.Text("%", pad=RTEXT_PADDING),
72
        sg.VSeparator(),
73
        sg.Text("Recuperar:", pad=TEXT_PADDING),
74
        sg.Button("Emitidas", key="recuperar_emitidas"),
75
        sg.Button("Recibidas", key="recuperar_recibidas"),
76
        sg.Text("Dias:", pad=TEXT_PADDING),
77
        sg.Input("40", size=(4, 1), key="recuperar_dias"),
78
    ]
79
80
    button_column_low = [
81
        sg.Button("Validar Clientes", key="validate_clientes"),
82
        sg.Button("Crear Facturas", disabled=True, key="crear_facturas"),
83
        sg.Button("Enviar Correos", disabled=True, key="enviar_correos"),
84
        sg.Button("Confirmar Pago", disabled=True, key="confirm_pago_button"),
85
86
    ]
87
88
    # ----- Full layout -----
89
    return [
90
        button_column,
91
        [sg.HSeparator()],
92
        c_second,
93
        [sg.HSeparator()],
94
        button_column_third,
95
        [sg.Output(expand_x=True, expand_y=True, key="console")],
96
        button_column_low
97
    ]
98
99
100
class InvoiceButtonManager:
101
    def __init__(self, button, detallado):
102
        self._cfdis = []
103
        self.button = button
104
        self.detallado = detallado
105
106
    def set_invoices(self, invoices):
107
        self._cfdis = invoices
108
        for i, cfdi in enumerate(self._cfdis, start=1):
109
            log_item(f"FACTURA NUMERO: {i}")
110
            log_cfdi(cfdi, detailed=self.detallado.get())
111
112
        self.style_button()
113
114
    def clear(self):
115
        cfdis = self._cfdis
116
        self._cfdis = []
117
        self.style_button()
118
        return cfdis
119
120
    def style_button(self):
121
        self.button.update(
122
            disabled=len(self._cfdis) == 0
123
        )
124
125
126
class EmailButtonManager:
127
    def __init__(self, button):
128
        self._emails = {}
129
        self.button = button
130
131
    def set_invoices(self, invoices):
132
        self._emails = invoices
133
134
        for i, (receptor, notify_invoices, facturas_pendientes) in enumerate(invoices, start=1):
135
            log_item(f"CORREO NUMERO: {i}")
136
            log_email(receptor, notify_invoices, facturas_pendientes)
137
138
        self.style_button()
139
140
    def clear(self):
141
        emails = self._emails
142
        self._emails = {}
143
        self.style_button()
144
        return emails
145
146
    def style_button(self):
147
        self.button.update(
148
            disabled=len(self._emails) == 0
149
        )
150
151
152
class ConfirmPagoButtonManager:
153
    def __init__(self, button, detallado):
154
        self._confirm_pago = None
155
        self.button = button
156
        self.detallado = detallado
157
158
    def set_confirm_pago(self, confirm_pago):
159
        self._confirm_pago = confirm_pago
160
        log_item(f"PAGO PUE")
161
        log_cfdi(self._confirm_pago, detailed=self.detallado.get())
162
        self.style_button()
163
164
    def clear(self):
165
        confirm_pago = self._confirm_pago
166
        self._confirm_pago = None
167
        self.style_button()
168
        return confirm_pago
169
170
    def style_button(self):
171
        self.button.update(
172
            disabled=not self._confirm_pago
173
        )
174