forked from kelvins/design-patterns-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
78 lines (61 loc) · 1.63 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from datetime import date
class Item:
def __init__(self, descricao, valor):
self.__descricao = descricao
self.__valor = valor
@property
def descricao(self):
return self.__descricao
@property
def valor(self):
return self.__valor
class NotaFiscal:
def __init__(
self,
razao_social,
cnpj,
itens,
data_de_emissao=date.today(),
detalhes='',
):
self.__razao_social = razao_social
self.__cnpj = cnpj
self.__data_de_emissao = data_de_emissao
if len(detalhes) > 20:
raise Exception(
'Detalhes da nota fiscal nao pode ter mais que 20 chars'
)
self.__detalhes = detalhes
self.__itens = itens
@property
def razao_social(self):
return self.__razao_social
@property
def cnpj(self):
return self.__cnpj
@property
def data_de_emissao(self):
return self.__data_de_emissao
@property
def detalhes(self):
return self.__detalhes
@property
def itens(self):
return self.__itens
if __name__ == '__main__':
from criador_de_nota_fiscal import CriadorNotaFiscal
itens = [Item('ITEM A', 100), Item('ITEM B', 200)]
nota_fiscal = NotaFiscal(
razao_social='FHSA Limitada',
cnpj='01928391827321',
itens=itens,
data_de_emissao=date.today(),
detalhes='',
)
nota_fiscal_criada_com_builder = (
CriadorNotaFiscal()
.com_razao_social('FHSA Limitada')
.com_cnpj('01928391827321')
.com_itens(itens)
.constroi()
)