Test Failed
Push — main ( 8fee32...5bd83b )
by Sat CFDI
03:17
created

satdigitalinvoice.local.LocalDBSatCFDI.describe()   A

Complexity

Conditions 1

Size

Total Lines 6
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nop 2
1
import logging
2
from uuid import UUID
3
4
import diskcache
5
from satcfdi.accounting import SatCFDI
6
from satcfdi.pacs import sat
7
from satdigitalinvoice.log_tools import LogAdapter
8
9
from satdigitalinvoice.file_data_managers import ConfigManager
10
11
PUE_PAGADA = 0
12
PPD_IGNORAR = 1
13
EMAIL_NOTIFICADA = 2
14
STATUS_SAT = 3
15
16
config = ConfigManager()
17
sat_manager = sat.SAT()
18
19
logger = LogAdapter(logging.getLogger())
20
21
22
class LocalDB:
23
    def __init__(self):
24
        self.local_storage = diskcache.Cache('.data/local')
25
26
    def pue_pagada(self, uuid: UUID):
27
        return self.local_storage.get(
28
            (PUE_PAGADA, uuid), False
29
        )
30
31
    def pue_pagada_set(self, uuid: UUID, value: bool):
32
        if value:
33
            self.local_storage[(PUE_PAGADA, uuid)] = value
34
        else:
35
            try:
36
                del self.local_storage[(PUE_PAGADA, uuid)]
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable PUE_PAGADA does not seem to be defined.
Loading history...
37
            except KeyError:
38
                pass
39
40
    def ppd_ignorar(self, uuid: UUID):
41
        return self.local_storage.get(
42
            (PPD_IGNORAR, uuid), False
43
        )
44
45
    def ppd_ignorar_set(self, uuid: UUID, value: bool):
46
        if value:
47
            self.local_storage[(PPD_IGNORAR, uuid)] = value
48
        else:
49
            try:
50
                del self.local_storage[(PPD_IGNORAR, uuid)]
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable PPD_IGNORAR does not seem to be defined.
Loading history...
51
            except KeyError:
52
                pass
53
54
    def email_notificada(self, uuid: UUID):
55
        return self.local_storage.get(
56
            (EMAIL_NOTIFICADA, uuid), False
57
        )
58
59
    def email_notificada_set(self, uuid: UUID, value: bool):
60
        if value:
61
            self.local_storage[(EMAIL_NOTIFICADA, uuid)] = value
62
        else:
63
            try:
64
                del self.local_storage[(EMAIL_NOTIFICADA, uuid)]
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable EMAIL_NOTIFICADA does not seem to be defined.
Loading history...
65
            except KeyError:
66
                pass
67
68
    def status_sat(self, uuid: UUID):
69
        return self.local_storage.get(
70
            (STATUS_SAT, uuid), {}
71
        )
72
73
    def status_sat_set(self, uuid: UUID, value: dict):
74
        if value:
75
            self.local_storage[(STATUS_SAT, uuid)] = value
76
        else:
77
            try:
78
                del self.local_storage[(STATUS_SAT, uuid)]
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable STATUS_SAT does not seem to be defined.
Loading history...
79
            except KeyError:
80
                pass
81
82
83
class LocalDBSatCFDI(LocalDB):
84
    def email_notificada(self, cfdi: SatCFDI):
85
        if cfdi["Fecha"] <= config['email_notificada_hasta']:
86
            return True
87
        return super().email_notificada(cfdi.uuid)
88
89
    def pue_pagada(self, cfdi: SatCFDI):
90
        if cfdi["Fecha"] <= config['pue_pagada_hasta']:
91
            return True
92
        return super().pue_pagada(cfdi.uuid)
93
94
    def ppd_ignorar(self, cfdi: SatCFDI):
95
        if cfdi["Fecha"] <= config['ppd_ignorar_hasta']:
96
            return True
97
        return super().ppd_ignorar(cfdi.uuid)
98
99
    def status_sat(self, cfdi: SatCFDI, update=False):
100
        if update:
101
            res = sat_manager.status(cfdi)
102
            if res["ValidacionEFOS"] == "200":
103
                self.status_sat_set(cfdi.uuid, res)
104
            return res
105
        else:
106
            return super().status_sat(cfdi.uuid)
107
108
    def describe(self, cfdi: SatCFDI):
109
        logger.info_yaml({
110
            'pue_pagada': self.pue_pagada(cfdi),
111
            'ppd_ignorar': self.ppd_ignorar(cfdi),
112
            'email_notificada': self.email_notificada(cfdi),
113
            'status_sat': self.status_sat(cfdi)
114
        })
115