1
|
|
|
from uuid import UUID |
2
|
|
|
|
3
|
|
|
import diskcache |
4
|
|
|
from satcfdi.accounting import SatCFDI |
5
|
|
|
from satcfdi.pacs import sat |
6
|
|
|
|
7
|
|
|
from satdigitalinvoice.file_data_managers import ConfigManager |
8
|
|
|
|
9
|
|
|
PUE_PAGADA = 0 |
10
|
|
|
PPD_IGNORAR = 1 |
11
|
|
|
EMAIL_NOTIFICADA = 2 |
12
|
|
|
STATUS_SAT = 3 |
13
|
|
|
|
14
|
|
|
config = ConfigManager() |
15
|
|
|
sat_manager = sat.SAT() |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
class LocalDB: |
19
|
|
|
def __init__(self): |
20
|
|
|
self.local_storage = diskcache.Cache('.data/local') |
21
|
|
|
|
22
|
|
|
def pue_pagada(self, uuid: UUID): |
23
|
|
|
return self.local_storage.get( |
24
|
|
|
(PUE_PAGADA, uuid), False |
25
|
|
|
) |
26
|
|
|
|
27
|
|
|
def pue_pagada_set(self, uuid: UUID, value: bool): |
28
|
|
|
if value: |
29
|
|
|
self.local_storage[(PUE_PAGADA, uuid)] = value |
30
|
|
|
else: |
31
|
|
|
try: |
32
|
|
|
del self.local_storage[(PUE_PAGADA, uuid)] |
|
|
|
|
33
|
|
|
except KeyError: |
34
|
|
|
pass |
35
|
|
|
|
36
|
|
|
def ppd_ignorar(self, uuid: UUID): |
37
|
|
|
return self.local_storage.get( |
38
|
|
|
(PPD_IGNORAR, uuid), False |
39
|
|
|
) |
40
|
|
|
|
41
|
|
|
def ppd_ignorar_set(self, uuid: UUID, value: bool): |
42
|
|
|
if value: |
43
|
|
|
self.local_storage[(PPD_IGNORAR, uuid)] = value |
44
|
|
|
else: |
45
|
|
|
try: |
46
|
|
|
del self.local_storage[(PPD_IGNORAR, uuid)] |
|
|
|
|
47
|
|
|
except KeyError: |
48
|
|
|
pass |
49
|
|
|
|
50
|
|
|
def email_notificada(self, uuid: UUID): |
51
|
|
|
return self.local_storage.get( |
52
|
|
|
(EMAIL_NOTIFICADA, uuid), False |
53
|
|
|
) |
54
|
|
|
|
55
|
|
|
def email_notificada_set(self, uuid: UUID, value: bool): |
56
|
|
|
if value: |
57
|
|
|
self.local_storage[(EMAIL_NOTIFICADA, uuid)] = value |
58
|
|
|
else: |
59
|
|
|
try: |
60
|
|
|
del self.local_storage[(EMAIL_NOTIFICADA, uuid)] |
|
|
|
|
61
|
|
|
except KeyError: |
62
|
|
|
pass |
63
|
|
|
|
64
|
|
|
def status_sat(self, uuid: UUID): |
65
|
|
|
return self.local_storage.get( |
66
|
|
|
(STATUS_SAT, uuid), {} |
67
|
|
|
) |
68
|
|
|
|
69
|
|
|
def status_sat_set(self, uuid: UUID, value: dict): |
70
|
|
|
if value: |
71
|
|
|
self.local_storage[(STATUS_SAT, uuid)] = value |
72
|
|
|
else: |
73
|
|
|
try: |
74
|
|
|
del self.local_storage[(STATUS_SAT, uuid)] |
|
|
|
|
75
|
|
|
except KeyError: |
76
|
|
|
pass |
77
|
|
|
|
78
|
|
|
|
79
|
|
|
class LocalDBSatCFDI(LocalDB): |
80
|
|
|
def email_notificada(self, cfdi: SatCFDI): |
81
|
|
|
if cfdi["Fecha"] <= config['email_notificada_hasta']: |
82
|
|
|
return True |
83
|
|
|
return super().email_notificada(cfdi.uuid) |
84
|
|
|
|
85
|
|
|
def pue_pagada(self, cfdi: SatCFDI): |
86
|
|
|
if cfdi["Fecha"] <= config['pue_pagada_hasta']: |
87
|
|
|
return True |
88
|
|
|
return super().pue_pagada(cfdi.uuid) |
89
|
|
|
|
90
|
|
|
def ppd_ignorar(self, cfdi: SatCFDI): |
91
|
|
|
if cfdi["Fecha"] <= config['ppd_ignorar_hasta']: |
92
|
|
|
return True |
93
|
|
|
return super().ppd_ignorar(cfdi.uuid) |
94
|
|
|
|
95
|
|
|
def status_sat(self, cfdi: SatCFDI, update=False): |
96
|
|
|
if update: |
97
|
|
|
res = sat_manager.status(cfdi) |
98
|
|
|
if res["ValidacionEFOS"] == "200": |
99
|
|
|
self.status_sat_set(cfdi.uuid, res) |
100
|
|
|
return res |
101
|
|
|
else: |
102
|
|
|
return super().status_sat(cfdi.uuid) |
103
|
|
|
|