tcapelle commited on
Commit
b60b332
1 Parent(s): 01448ae

initial commit

Browse files
Files changed (5) hide show
  1. README.md +4 -2
  2. app.py +37 -0
  3. calc.ipynb +270 -0
  4. impuestos.py +46 -0
  5. requirements.txt +2 -0
README.md CHANGED
@@ -6,8 +6,10 @@ colorTo: green
6
  sdk: streamlit
7
  sdk_version: 1.10.0
8
  app_file: app.py
9
- pinned: false
10
  license: mit
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
6
  sdk: streamlit
7
  sdk_version: 1.10.0
8
  app_file: app.py
9
+ pinned: true
10
  license: mit
11
  ---
12
 
13
+ Ingresa tu renta y presiona enter!
14
+
15
+ Los datos de tramos actuales usados los puedes encontrar [aqui][https://www.sii.cl/valores_y_fechas/impuesto_2da_categoria/impuesto2022.htm] y los de la reforma [aca](https://chocale.cl/2022/07/reforma-tributaria-gobierno-claves-proyecto-impuestos/)
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pathlib import Path
2
+ import streamlit as st
3
+
4
+ from impuestos import TRAMOS, TRAMOS_REFORMA, get_table
5
+
6
+
7
+
8
+
9
+ def main() -> None:
10
+ st.header("Calcula tu impuesto a la renta :moneybag: :dollar: :bar_chart:")
11
+
12
+ with st.expander("Como se usa esta cosa?"):
13
+ st.write(Path("README.md").read_text())
14
+
15
+ st.subheader("Ingresa tus datos")
16
+ sueldo_bruto = st.number_input("Sueldo Bruto Mensual", value=1800000, min_value=300000)
17
+
18
+ st.subheader("Tabla de Impuestos Actual")
19
+ table = get_table(sueldo_bruto, TRAMOS)
20
+ st.dataframe(table)
21
+ total = table["Impuesto"].sum()
22
+ st.text(f"Pagaras en Total: ${total}")
23
+
24
+ st.subheader("Tabla de Impuestos Reforma")
25
+ table = get_table(sueldo_bruto, TRAMOS_REFORMA)
26
+ st.dataframe(table)
27
+ total = table["Impuesto"].sum()
28
+ st.text(f"Con la reforma pagaras en Total: ${total}")
29
+
30
+ if __name__ == "__main__":
31
+ st.set_page_config(
32
+ "Calculador de impuestos",
33
+ "📊",
34
+ initial_sidebar_state="expanded",
35
+ layout="wide",
36
+ )
37
+ main()
calc.ipynb ADDED
@@ -0,0 +1,270 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "from impuestos import *"
10
+ ]
11
+ },
12
+ {
13
+ "cell_type": "code",
14
+ "execution_count": 2,
15
+ "metadata": {},
16
+ "outputs": [
17
+ {
18
+ "name": "stdout",
19
+ "output_type": "stream",
20
+ "text": [
21
+ "786384 0\n",
22
+ "1747440 0.04\n"
23
+ ]
24
+ }
25
+ ],
26
+ "source": [
27
+ "sueldo_bruto = 1_200_000\n",
28
+ "\n",
29
+ "impuesto = 0\n",
30
+ "for tramo, rate in TRAMOS.items():\n",
31
+ " print(tramo, rate)\n",
32
+ " delta = sueldo_bruto - tramo\n",
33
+ " if delta < 0:\n",
34
+ " break\n",
35
+ " impuesto += delta*rate"
36
+ ]
37
+ },
38
+ {
39
+ "cell_type": "code",
40
+ "execution_count": 3,
41
+ "metadata": {},
42
+ "outputs": [
43
+ {
44
+ "data": {
45
+ "text/plain": [
46
+ "[786384, 1747440, 2912400, 4077360, 5242320, 6989760, 18056880, 99999999]"
47
+ ]
48
+ },
49
+ "execution_count": 3,
50
+ "metadata": {},
51
+ "output_type": "execute_result"
52
+ }
53
+ ],
54
+ "source": [
55
+ "list(TRAMOS.keys())"
56
+ ]
57
+ },
58
+ {
59
+ "cell_type": "code",
60
+ "execution_count": 18,
61
+ "metadata": {},
62
+ "outputs": [],
63
+ "source": [
64
+ "def descomponer_en_tramos(sueldo_bruto, tramos=TRAMOS):\n",
65
+ " descomp = []\n",
66
+ " impuestos = []\n",
67
+ " tramo_anterior = 0\n",
68
+ " for tramo, descuento in tramos.items():\n",
69
+ " delta = min(sueldo_bruto, tramo) - tramo_anterior\n",
70
+ " if delta>0:\n",
71
+ " descomp.append(delta)\n",
72
+ " impuestos.append(int(delta*descuento))\n",
73
+ " tramo_anterior = tramo\n",
74
+ " return descomp, impuestos"
75
+ ]
76
+ },
77
+ {
78
+ "cell_type": "code",
79
+ "execution_count": 19,
80
+ "metadata": {},
81
+ "outputs": [
82
+ {
83
+ "data": {
84
+ "text/plain": [
85
+ "([786384, 413616], [0, 16544])"
86
+ ]
87
+ },
88
+ "execution_count": 19,
89
+ "metadata": {},
90
+ "output_type": "execute_result"
91
+ }
92
+ ],
93
+ "source": [
94
+ "sueldo_bruto = 1_200_000\n",
95
+ "descomponer_en_tramos(sueldo_bruto, TRAMOS)"
96
+ ]
97
+ },
98
+ {
99
+ "cell_type": "code",
100
+ "execution_count": 20,
101
+ "metadata": {},
102
+ "outputs": [],
103
+ "source": [
104
+ "import pandas as pd\n"
105
+ ]
106
+ },
107
+ {
108
+ "cell_type": "code",
109
+ "execution_count": 21,
110
+ "metadata": {},
111
+ "outputs": [],
112
+ "source": [
113
+ "def get_table(sueldo_bruto, tramos=TRAMOS):\n",
114
+ " _tramos = [0]+list(tramos.keys())\n",
115
+ " tasas = tramos.values()\n",
116
+ " data = [[desde, hasta, monto, tasa, impuesto] for desde, hasta, tasa, monto, impuesto in zip(_tramos[:-1], _tramos[1:], tasas, *descomponer_en_tramos(sueldo_bruto))]\n",
117
+ " df = pd.DataFrame(data=data, columns=[\"Desde\", \"Hasta\", \"Monto\", \"Tasa\", \"Impuesto\"])\n",
118
+ " return df"
119
+ ]
120
+ },
121
+ {
122
+ "cell_type": "code",
123
+ "execution_count": 22,
124
+ "metadata": {},
125
+ "outputs": [
126
+ {
127
+ "data": {
128
+ "text/html": [
129
+ "<div>\n",
130
+ "<style scoped>\n",
131
+ " .dataframe tbody tr th:only-of-type {\n",
132
+ " vertical-align: middle;\n",
133
+ " }\n",
134
+ "\n",
135
+ " .dataframe tbody tr th {\n",
136
+ " vertical-align: top;\n",
137
+ " }\n",
138
+ "\n",
139
+ " .dataframe thead th {\n",
140
+ " text-align: right;\n",
141
+ " }\n",
142
+ "</style>\n",
143
+ "<table border=\"1\" class=\"dataframe\">\n",
144
+ " <thead>\n",
145
+ " <tr style=\"text-align: right;\">\n",
146
+ " <th></th>\n",
147
+ " <th>Desde</th>\n",
148
+ " <th>Hasta</th>\n",
149
+ " <th>Monto</th>\n",
150
+ " <th>Tasa</th>\n",
151
+ " <th>Impuesto</th>\n",
152
+ " </tr>\n",
153
+ " </thead>\n",
154
+ " <tbody>\n",
155
+ " <tr>\n",
156
+ " <th>0</th>\n",
157
+ " <td>0</td>\n",
158
+ " <td>786384</td>\n",
159
+ " <td>786384</td>\n",
160
+ " <td>0.000</td>\n",
161
+ " <td>0</td>\n",
162
+ " </tr>\n",
163
+ " <tr>\n",
164
+ " <th>1</th>\n",
165
+ " <td>786384</td>\n",
166
+ " <td>1747440</td>\n",
167
+ " <td>961056</td>\n",
168
+ " <td>0.040</td>\n",
169
+ " <td>38442</td>\n",
170
+ " </tr>\n",
171
+ " <tr>\n",
172
+ " <th>2</th>\n",
173
+ " <td>1747440</td>\n",
174
+ " <td>2912400</td>\n",
175
+ " <td>1164960</td>\n",
176
+ " <td>0.080</td>\n",
177
+ " <td>93196</td>\n",
178
+ " </tr>\n",
179
+ " <tr>\n",
180
+ " <th>3</th>\n",
181
+ " <td>2912400</td>\n",
182
+ " <td>4077360</td>\n",
183
+ " <td>1164960</td>\n",
184
+ " <td>0.135</td>\n",
185
+ " <td>157269</td>\n",
186
+ " </tr>\n",
187
+ " <tr>\n",
188
+ " <th>4</th>\n",
189
+ " <td>4077360</td>\n",
190
+ " <td>5242320</td>\n",
191
+ " <td>1164960</td>\n",
192
+ " <td>0.230</td>\n",
193
+ " <td>267940</td>\n",
194
+ " </tr>\n",
195
+ " <tr>\n",
196
+ " <th>5</th>\n",
197
+ " <td>5242320</td>\n",
198
+ " <td>6989760</td>\n",
199
+ " <td>1747440</td>\n",
200
+ " <td>0.304</td>\n",
201
+ " <td>531221</td>\n",
202
+ " </tr>\n",
203
+ " <tr>\n",
204
+ " <th>6</th>\n",
205
+ " <td>6989760</td>\n",
206
+ " <td>18056880</td>\n",
207
+ " <td>3010240</td>\n",
208
+ " <td>0.350</td>\n",
209
+ " <td>1053584</td>\n",
210
+ " </tr>\n",
211
+ " </tbody>\n",
212
+ "</table>\n",
213
+ "</div>"
214
+ ],
215
+ "text/plain": [
216
+ " Desde Hasta Monto Tasa Impuesto\n",
217
+ "0 0 786384 786384 0.000 0\n",
218
+ "1 786384 1747440 961056 0.040 38442\n",
219
+ "2 1747440 2912400 1164960 0.080 93196\n",
220
+ "3 2912400 4077360 1164960 0.135 157269\n",
221
+ "4 4077360 5242320 1164960 0.230 267940\n",
222
+ "5 5242320 6989760 1747440 0.304 531221\n",
223
+ "6 6989760 18056880 3010240 0.350 1053584"
224
+ ]
225
+ },
226
+ "execution_count": 22,
227
+ "metadata": {},
228
+ "output_type": "execute_result"
229
+ }
230
+ ],
231
+ "source": [
232
+ "get_table(10000000)"
233
+ ]
234
+ },
235
+ {
236
+ "cell_type": "code",
237
+ "execution_count": null,
238
+ "metadata": {},
239
+ "outputs": [],
240
+ "source": []
241
+ }
242
+ ],
243
+ "metadata": {
244
+ "kernelspec": {
245
+ "display_name": "Python 3.10.2 ('st')",
246
+ "language": "python",
247
+ "name": "python3"
248
+ },
249
+ "language_info": {
250
+ "codemirror_mode": {
251
+ "name": "ipython",
252
+ "version": 3
253
+ },
254
+ "file_extension": ".py",
255
+ "mimetype": "text/x-python",
256
+ "name": "python",
257
+ "nbconvert_exporter": "python",
258
+ "pygments_lexer": "ipython3",
259
+ "version": "3.10.2"
260
+ },
261
+ "orig_nbformat": 4,
262
+ "vscode": {
263
+ "interpreter": {
264
+ "hash": "885b610356171de8141a812cff200370cfd21ab3bf3d712138f61360bb82c1dd"
265
+ }
266
+ }
267
+ },
268
+ "nbformat": 4,
269
+ "nbformat_minor": 2
270
+ }
impuestos.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+
3
+ #Valores de Junio 2022
4
+ TRAMOS = { 777000 :0,
5
+ 1727000 :0.04,
6
+ 2878000 :0.08,
7
+ 4029000 :0.135,
8
+ 5180000 :0.23,
9
+ 6906000 :0.304,
10
+ 17842000 :0.35,
11
+ 99999999 :0.4}
12
+
13
+ TRAMOS_REFORMA = {
14
+ 777000 :0,
15
+ 1727000 :0.04,
16
+ 2878000 :0.08,
17
+ 4030000 :0.135,
18
+ 5242320 :0.26,
19
+ 6331000 :0.35,
20
+ 8057000 :0.40,
21
+ 99999999 :0.43}
22
+
23
+ def descomponer_en_tramos(sueldo_bruto, tramos=TRAMOS):
24
+ """
25
+ Descompone un sueldo bruto en tramos de impuesto
26
+ """
27
+ descomp = []
28
+ impuestos = []
29
+ tramo_anterior = 0
30
+ for tramo, descuento in tramos.items():
31
+ delta = min(sueldo_bruto, tramo) - tramo_anterior
32
+ if delta>0:
33
+ descomp.append(delta)
34
+ impuestos.append(int(delta*descuento))
35
+ tramo_anterior = tramo
36
+ return descomp, impuestos
37
+
38
+ def get_table(sueldo_bruto, tramos=TRAMOS):
39
+ """
40
+ Tabla de Impuestos por tramo
41
+ """
42
+ _tramos = [0]+list(tramos.keys())
43
+ tasas = tramos.values()
44
+ data = list(zip(_tramos[:-1], _tramos[1:], tasas, *descomponer_en_tramos(sueldo_bruto, tramos)))
45
+ df = pd.DataFrame(data=data, columns=["Desde", "Hasta", "Tasa", "Monto sujeto a impuesto", "Impuesto"])
46
+ return df
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ streamlit
2
+ pandas