tributus-engine 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tributus_engine/__init__.py +9 -0
- tributus_engine/engine.py +623 -0
- tributus_engine/implementations/__init__.py +20 -0
- tributus_engine/implementations/cofins.py +56 -0
- tributus_engine/implementations/ibs_cbs.py +103 -0
- tributus_engine/implementations/icms/__init__.py +27 -0
- tributus_engine/implementations/icms/base.py +84 -0
- tributus_engine/implementations/icms/cst.py +515 -0
- tributus_engine/implementations/icms/fcp.py +36 -0
- tributus_engine/implementations/ipi.py +49 -0
- tributus_engine/implementations/pis.py +56 -0
- tributus_engine/interfaces/__init__.py +25 -0
- tributus_engine/interfaces/protocols.py +124 -0
- tributus_engine-0.2.0.dist-info/METADATA +186 -0
- tributus_engine-0.2.0.dist-info/RECORD +17 -0
- tributus_engine-0.2.0.dist-info/WHEEL +5 -0
- tributus_engine-0.2.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
from dataclasses import dataclass, field
|
|
2
|
+
from decimal import Decimal, ROUND_HALF_EVEN
|
|
3
|
+
|
|
4
|
+
from ..interfaces import ICofins01_02, ICofins03
|
|
5
|
+
|
|
6
|
+
@dataclass
|
|
7
|
+
class BaseCofins:
|
|
8
|
+
valor_produto: Decimal
|
|
9
|
+
valor_frete: Decimal
|
|
10
|
+
valor_seguro: Decimal
|
|
11
|
+
despesas_acessorias: Decimal
|
|
12
|
+
valor_desconto: Decimal
|
|
13
|
+
valor_icms: Decimal = Decimal('0')
|
|
14
|
+
|
|
15
|
+
def calcular_base_cofins(self) -> Decimal:
|
|
16
|
+
base_cofins = (
|
|
17
|
+
self.valor_produto +
|
|
18
|
+
self.valor_frete +
|
|
19
|
+
self.valor_seguro +
|
|
20
|
+
self.despesas_acessorias -
|
|
21
|
+
self.valor_desconto
|
|
22
|
+
)
|
|
23
|
+
base_cofins = base_cofins - self.valor_icms
|
|
24
|
+
return base_cofins.quantize(Decimal('0.01'), rounding=ROUND_HALF_EVEN)
|
|
25
|
+
|
|
26
|
+
@dataclass
|
|
27
|
+
class Cofins01_02(ICofins01_02):
|
|
28
|
+
valor_produto: Decimal
|
|
29
|
+
valor_frete: Decimal
|
|
30
|
+
valor_seguro: Decimal
|
|
31
|
+
despesas_acessorias: Decimal
|
|
32
|
+
valor_desconto: Decimal
|
|
33
|
+
aliquota_cofins: Decimal
|
|
34
|
+
valor_icms: Decimal = Decimal('0')
|
|
35
|
+
|
|
36
|
+
_base_cofins: BaseCofins = field(init=False)
|
|
37
|
+
|
|
38
|
+
def __post_init__(self):
|
|
39
|
+
self._base_cofins = BaseCofins(
|
|
40
|
+
self.valor_produto, self.valor_frete, self.valor_seguro,
|
|
41
|
+
self.despesas_acessorias, self.valor_desconto, self.valor_icms
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
def base_cofins(self) -> Decimal:
|
|
45
|
+
return self._base_cofins.calcular_base_cofins()
|
|
46
|
+
|
|
47
|
+
def valor_cofins(self) -> Decimal:
|
|
48
|
+
return (self.base_cofins() * (self.aliquota_cofins / 100)).quantize(Decimal('0.01'), rounding=ROUND_HALF_EVEN)
|
|
49
|
+
|
|
50
|
+
@dataclass
|
|
51
|
+
class Cofins03(ICofins03):
|
|
52
|
+
base_calculo: Decimal
|
|
53
|
+
aliquota_por_unidade: Decimal
|
|
54
|
+
|
|
55
|
+
def valor_cofins(self) -> Decimal:
|
|
56
|
+
return (self.aliquota_por_unidade * self.base_calculo).quantize(Decimal('0.01'), rounding=ROUND_HALF_EVEN)
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
from dataclasses import dataclass, field
|
|
2
|
+
from decimal import Decimal, ROUND_HALF_EVEN
|
|
3
|
+
|
|
4
|
+
from ..interfaces import ICbs, IIbsUf
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@dataclass
|
|
8
|
+
class BaseIbsCbs:
|
|
9
|
+
valor_produto: Decimal
|
|
10
|
+
valor_frete: Decimal
|
|
11
|
+
valor_seguro: Decimal
|
|
12
|
+
despesas_acessorias: Decimal
|
|
13
|
+
|
|
14
|
+
def calcular_base_ibs_cbs(self) -> Decimal:
|
|
15
|
+
base_ibs_cbs = (
|
|
16
|
+
self.valor_produto +
|
|
17
|
+
self.valor_frete +
|
|
18
|
+
self.valor_seguro +
|
|
19
|
+
self.despesas_acessorias
|
|
20
|
+
)
|
|
21
|
+
return base_ibs_cbs.quantize(Decimal('0.01'), rounding=ROUND_HALF_EVEN)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@dataclass
|
|
25
|
+
class Cbs(ICbs):
|
|
26
|
+
valor_produto: Decimal
|
|
27
|
+
valor_frete: Decimal
|
|
28
|
+
valor_seguro: Decimal
|
|
29
|
+
despesas_acessorias: Decimal
|
|
30
|
+
aliquota_efetiva_percentual: Decimal
|
|
31
|
+
percentual_diferimento: Decimal = Decimal('0')
|
|
32
|
+
|
|
33
|
+
_base_ibs_cbs: BaseIbsCbs = field(init=False)
|
|
34
|
+
|
|
35
|
+
def __post_init__(self):
|
|
36
|
+
self._base_ibs_cbs = BaseIbsCbs(
|
|
37
|
+
self.valor_produto,
|
|
38
|
+
self.valor_frete,
|
|
39
|
+
self.valor_seguro,
|
|
40
|
+
self.despesas_acessorias,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
def valor_base_ibs_cbs(self) -> Decimal:
|
|
44
|
+
return self._base_ibs_cbs.calcular_base_ibs_cbs()
|
|
45
|
+
|
|
46
|
+
def aliquota_efetiva(self) -> Decimal:
|
|
47
|
+
return self.aliquota_efetiva_percentual
|
|
48
|
+
|
|
49
|
+
def _valor_cbs_bruto(self) -> Decimal:
|
|
50
|
+
return (self.valor_base_ibs_cbs() * (self.aliquota_efetiva() / 100)).quantize(
|
|
51
|
+
Decimal('0.01'), rounding=ROUND_HALF_EVEN
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
def diferimento(self) -> Decimal:
|
|
55
|
+
return (self._valor_cbs_bruto() * (self.percentual_diferimento / 100)).quantize(
|
|
56
|
+
Decimal('0.01'), rounding=ROUND_HALF_EVEN
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
def valor_cbs(self) -> Decimal:
|
|
60
|
+
return (self._valor_cbs_bruto() - self.diferimento()).quantize(
|
|
61
|
+
Decimal('0.01'), rounding=ROUND_HALF_EVEN
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
@dataclass
|
|
66
|
+
class IbsUf(IIbsUf):
|
|
67
|
+
valor_produto: Decimal
|
|
68
|
+
valor_frete: Decimal
|
|
69
|
+
valor_seguro: Decimal
|
|
70
|
+
despesas_acessorias: Decimal
|
|
71
|
+
aliquota_efetiva_percentual: Decimal
|
|
72
|
+
percentual_diferimento: Decimal = Decimal('0')
|
|
73
|
+
|
|
74
|
+
_base_ibs_cbs: BaseIbsCbs = field(init=False)
|
|
75
|
+
|
|
76
|
+
def __post_init__(self):
|
|
77
|
+
self._base_ibs_cbs = BaseIbsCbs(
|
|
78
|
+
self.valor_produto,
|
|
79
|
+
self.valor_frete,
|
|
80
|
+
self.valor_seguro,
|
|
81
|
+
self.despesas_acessorias,
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
def valor_base_ibs_cbs(self) -> Decimal:
|
|
85
|
+
return self._base_ibs_cbs.calcular_base_ibs_cbs()
|
|
86
|
+
|
|
87
|
+
def aliquota_efetiva(self) -> Decimal:
|
|
88
|
+
return self.aliquota_efetiva_percentual
|
|
89
|
+
|
|
90
|
+
def _valor_ibs_uf_bruto(self) -> Decimal:
|
|
91
|
+
return (self.valor_base_ibs_cbs() * (self.aliquota_efetiva() / 100)).quantize(
|
|
92
|
+
Decimal('0.01'), rounding=ROUND_HALF_EVEN
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
def diferimento(self) -> Decimal:
|
|
96
|
+
return (self._valor_ibs_uf_bruto() * (self.percentual_diferimento / 100)).quantize(
|
|
97
|
+
Decimal('0.01'), rounding=ROUND_HALF_EVEN
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
def valor_ibs_uf(self) -> Decimal:
|
|
101
|
+
return (self._valor_ibs_uf_bruto() - self.diferimento()).quantize(
|
|
102
|
+
Decimal('0.01'), rounding=ROUND_HALF_EVEN
|
|
103
|
+
)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from .base import (
|
|
2
|
+
BaseIcmsProprio,
|
|
3
|
+
BaseIcmsST,
|
|
4
|
+
BaseReduzidaIcmsProprio,
|
|
5
|
+
BaseReduzidaIcmsST,
|
|
6
|
+
ValorIcmsProprio,
|
|
7
|
+
ValorIcmsST,
|
|
8
|
+
)
|
|
9
|
+
from .fcp import (
|
|
10
|
+
Fcp,
|
|
11
|
+
FcpDiferido,
|
|
12
|
+
FcpEfetivo,
|
|
13
|
+
FcpST,
|
|
14
|
+
)
|
|
15
|
+
from .cst import (
|
|
16
|
+
Icms00,
|
|
17
|
+
Icms10,
|
|
18
|
+
Icms20,
|
|
19
|
+
Icms30,
|
|
20
|
+
Icms51,
|
|
21
|
+
Icms70,
|
|
22
|
+
Icms90,
|
|
23
|
+
Icms101,
|
|
24
|
+
Icms201,
|
|
25
|
+
Icms202_203,
|
|
26
|
+
Icms900,
|
|
27
|
+
)
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from decimal import Decimal, ROUND_HALF_EVEN
|
|
3
|
+
|
|
4
|
+
@dataclass
|
|
5
|
+
class BaseIcmsProprio:
|
|
6
|
+
valor_produto: Decimal
|
|
7
|
+
valor_frete: Decimal
|
|
8
|
+
valor_seguro: Decimal
|
|
9
|
+
despesas_acessorias: Decimal
|
|
10
|
+
valor_desconto: Decimal
|
|
11
|
+
valor_ipi: Decimal = Decimal('0')
|
|
12
|
+
|
|
13
|
+
def calcular_base_icms_proprio(self) -> Decimal:
|
|
14
|
+
base_icms_proprio = (
|
|
15
|
+
self.valor_produto +
|
|
16
|
+
self.valor_frete +
|
|
17
|
+
self.valor_seguro +
|
|
18
|
+
self.despesas_acessorias +
|
|
19
|
+
self.valor_ipi -
|
|
20
|
+
self.valor_desconto
|
|
21
|
+
)
|
|
22
|
+
return base_icms_proprio.quantize(Decimal('0.01'), rounding=ROUND_HALF_EVEN)
|
|
23
|
+
|
|
24
|
+
@dataclass
|
|
25
|
+
class BaseIcmsST:
|
|
26
|
+
base_icms_proprio: Decimal
|
|
27
|
+
mva: Decimal
|
|
28
|
+
valor_ipi: Decimal = Decimal('0')
|
|
29
|
+
|
|
30
|
+
def calcular_base_icms_st(self) -> Decimal:
|
|
31
|
+
result = (self.base_icms_proprio + self.valor_ipi) * (1 + (self.mva / 100))
|
|
32
|
+
return result.quantize(Decimal('0.01'), rounding=ROUND_HALF_EVEN)
|
|
33
|
+
|
|
34
|
+
@dataclass
|
|
35
|
+
class BaseReduzidaIcmsProprio:
|
|
36
|
+
valor_produto: Decimal
|
|
37
|
+
valor_frete: Decimal
|
|
38
|
+
valor_seguro: Decimal
|
|
39
|
+
despesas_acessorias: Decimal
|
|
40
|
+
valor_desconto: Decimal
|
|
41
|
+
percentual_reducao: Decimal
|
|
42
|
+
valor_ipi: Decimal = Decimal('0')
|
|
43
|
+
|
|
44
|
+
def calcular_base_reduzida_icms_proprio(self) -> Decimal:
|
|
45
|
+
base_icms = (
|
|
46
|
+
self.valor_produto +
|
|
47
|
+
self.valor_frete +
|
|
48
|
+
self.valor_seguro +
|
|
49
|
+
self.despesas_acessorias -
|
|
50
|
+
self.valor_desconto
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
result = (base_icms - (base_icms * (self.percentual_reducao / 100))) + self.valor_ipi
|
|
54
|
+
return result.quantize(Decimal('0.01'), rounding=ROUND_HALF_EVEN)
|
|
55
|
+
|
|
56
|
+
@dataclass
|
|
57
|
+
class BaseReduzidaIcmsST:
|
|
58
|
+
base_icms_proprio: Decimal
|
|
59
|
+
mva: Decimal
|
|
60
|
+
percentual_reducao_st: Decimal
|
|
61
|
+
valor_ipi: Decimal = Decimal('0')
|
|
62
|
+
|
|
63
|
+
def calcular_base_reduzida_icms_st(self) -> Decimal:
|
|
64
|
+
base_st = self.base_icms_proprio * (1 + (self.mva / 100))
|
|
65
|
+
base_st = base_st - (base_st * (self.percentual_reducao_st / 100))
|
|
66
|
+
base_st_reduzida = base_st + self.valor_ipi
|
|
67
|
+
return base_st_reduzida.quantize(Decimal('0.01'), rounding=ROUND_HALF_EVEN)
|
|
68
|
+
|
|
69
|
+
@dataclass
|
|
70
|
+
class ValorIcmsProprio:
|
|
71
|
+
base_calculo: Decimal
|
|
72
|
+
aliquota_icms_proprio: Decimal
|
|
73
|
+
|
|
74
|
+
def calcular_valor_icms_proprio(self) -> Decimal:
|
|
75
|
+
return (self.aliquota_icms_proprio / 100 * self.base_calculo).quantize(Decimal('0.01'), rounding=ROUND_HALF_EVEN)
|
|
76
|
+
|
|
77
|
+
@dataclass
|
|
78
|
+
class ValorIcmsST:
|
|
79
|
+
base_calculo_st: Decimal
|
|
80
|
+
aliquota_icms_st: Decimal
|
|
81
|
+
valor_icms_proprio: Decimal
|
|
82
|
+
|
|
83
|
+
def calcular_valor_icms_st(self) -> Decimal:
|
|
84
|
+
return ((self.base_calculo_st * (self.aliquota_icms_st / 100)) - self.valor_icms_proprio).quantize(Decimal('0.01'), rounding=ROUND_HALF_EVEN)
|