Skip to content

Instantly share code, notes, and snippets.

@laginha
Last active August 4, 2016 10:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laginha/a1139640516549410b39f428313f2ae4 to your computer and use it in GitHub Desktop.
Save laginha/a1139640516549410b39f428313f2ae4 to your computer and use it in GitHub Desktop.
Descontos para trabalhadores independentes
# -*- coding: utf-8 -*-
class Imposto(object):
def __init__(self, rendimento_anual_bruto):
self.rendimento_anual_bruto = rendimento_anual_bruto
self.rendimento_anual_de_incidencia = self.rendimento_anual_bruto * self.TAXA_DE_INCIDENCIA
self.rendimento_mensal_bruto = rendimento_anual_bruto /12
self.rendimento_mensal_de_incidencia = self.rendimento_anual_de_incidencia /12
class SegurancaSocial(Imposto):
# http://www.financaspessoais.pt/seguranca-social/calculadora-seguranca-social-trabalhadores-independentes
TAXA_CONTRIBUTIVA = 0.296
IAS = 419.22
ESCALOES = [0.5, 1, 1.5, 2, 2.5, 3, 4, 5, 6, 8, 10, 12]
TAXA_DE_INCIDENCIA = 0.70
def possiveis_descontos(self):
value = self.rendimento_mensal_de_incidencia / self.IAS
contribuicao = lambda x: x * self.IAS * self.TAXA_CONTRIBUTIVA
return [contribuicao(each) for each in self.ESCALOES if each < value][-3:]
class IRS(Imposto):
TAXA_DE_INCIDENCIA = 0.75
RETENCAO_NA_FONTE = 0.25 - 0.0175
ESCALOES = [
{'taxa_aplicavel': 0.145, 'taxa_media': 0.145, 'maximo_rendimento': 7035},
{'taxa_aplicavel': 0.285, 'taxa_media': 0.236, 'maximo_rendimento': 20100},
{'taxa_aplicavel': 0.37, 'taxa_media': 0.303, 'maximo_rendimento': 40200},
{'taxa_aplicavel': 0.45, 'taxa_media': 0.3765, 'maximo_rendimento': 80000},
{'taxa_aplicavel': 0.48, 'taxa_media': None, 'maximo_rendimento': None},
]
@property
def rendimento_mensal_liquido_com_retencao_na_fonte(self):
return self.rendimento_mensal_bruto - self.rendimento_mensal_de_incidencia * self.RETENCAO_NA_FONTE
@property
def rendimento_mensal_liquido(self):
for i in range(1, len(self.ESCALOES)):
escalao = self.ESCALOES[i]
if self.rendimento_anual_de_incidencia <= escalao['maximo_rendimento'] or escalao['maximo_rendimento'] == None:
escalao_anterior = self.ESCALOES[i-1]
incidencia_no_ultimo_escalao = self.rendimento_anual_de_incidencia - escalao_anterior['maximo_rendimento']
desconto_total = escalao_anterior['maximo_rendimento'] * escalao_anterior['taxa_media']
desconto_total += incidencia_no_ultimo_escalao * escalao['taxa_aplicavel']
return (self.rendimento_anual_bruto - desconto_total) /12
if __name__ == "__main__":
MIN = 24000
MAX = 40000
STEP = 2000
for rendimento_anual_bruto in xrange(MIN, MAX, STEP):
irs = IRS( rendimento_anual_bruto=rendimento_anual_bruto )
ss = SegurancaSocial( rendimento_anual_bruto=rendimento_anual_bruto )
print '\n# Rendimento anual: {0}'.format( rendimento_anual_bruto )
print '# Rendimento mensal liquido:'
rendimento_mensal_liquido = irs.rendimento_mensal_liquido
for desconto in ss.possiveis_descontos():
rendimento = rendimento_mensal_liquido - desconto
print '=> {0} - {1} = {2}'.format( rendimento_mensal_liquido, desconto, rendimento )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment