-
Notifications
You must be signed in to change notification settings - Fork 97
/
ir.py
3512 lines (2858 loc) · 140 KB
/
ir.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
import logging
from numpy import datetime64, timedelta64, logical_xor as xor_, round as round_, around
from numpy.core.defchararray import startswith
from openfisca_core.model_api import *
from openfisca_france.model.base import *
log = logging.getLogger(__name__)
# TODO: 8ti et 8tk (cerfa 2047)
# TODO: CSG, CRDS et prélèvements sociaux sur revenu du patrimione, d'activité et de remplacement
# TODO: finir RPNS (prise en compte des plafonds / cases non codées : codées pour certaines années mais pas pour
# d'autres - car des cases sont réutilisées pour des variables différentes suivant les années)
# zetrf = zeros(taille)
# jeune_veuf = zeros(taille, dtype = bool)
# Reprise du crédit d'impôt en faveur des jeunes, des accomptes et des versements mensues de prime pour l'emploi
# reprise = zeros(taille) # TODO : reprise=J80
# Pcredit = P.credits_impots
# if hasattr(P.reductions_impots,'saldom'): Pcredit.saldom = P.reductions_impots.saldom
# credits_impot = Credits(Pcredit, table)
# Réduction d'impôt
# reductions = Reductions(IPnet, P.reductions_impots)
# def mcirra():
# # impôt sur le revenu
# mcirra = -((IMP<=-8)*IMP)
# mciria = max_(0,(IMP>=0)*IMP)
# # mciria = max_(0,(IMP>=0)*IMP - credimp_etranger - cont_rev_loc - ( f8to + f8tb + f8tc ))
#
# # Dans l'ERFS, les prelevement libératoire sur les montants non déclarés
# # sont intégrés. Pas possible de le recalculer.
#
# # impot sur le revenu du foyer (hors prélèvement libératoire, revenus au quotient)
# irpp = -(mciria + ppetot - mcirra )
class jour_xyz(Variable):
value_type = int
default_value = 360
entity = FoyerFiscal
label = "Jours décomptés au titre de cette déclaration"
definition_period = YEAR
###############################################################################
# # Initialisation de quelques variables utiles pour la suite
###############################################################################
class age(Variable):
unit = 'years'
value_type = int
default_value = -9999
entity = Individu
label = "Âge (en années) au premier jour du mois"
definition_period = MONTH
is_period_size_independent = True
set_input = set_input_dispatch_by_period
def formula(individu, period, parameters):
has_birth = individu.get_holder('date_naissance').get_known_periods()
if not has_birth:
has_age_en_mois = bool(individu.get_holder('age_en_mois').get_known_periods())
if has_age_en_mois:
return individu('age_en_mois', period) // 12
# If age is known at the same day of another year, compute the new age from it.
holder = individu.get_holder('age')
start = period.start
known_periods = holder.get_known_periods()
if known_periods:
for last_period in sorted(known_periods, reverse = True):
last_start = last_period.start
if last_start.day == start.day:
last_array = holder.get_array(last_period)
return (
last_array
+ int(
start.year
- last_start.year
+ (start.month - last_start.month) / 12
)
)
date_naissance = individu('date_naissance', period)
epsilon = timedelta64(1)
return (datetime64(period.start) - date_naissance + epsilon).astype('timedelta64[Y]')
class age_en_mois(Variable):
value_type = int
default_value = -9999
unit = 'months'
entity = Individu
label = "Âge (en mois)"
is_period_size_independent = True
definition_period = MONTH
def formula(individu, period, parameters):
# If age_en_mois is known at the same day of another month, compute the new age_en_mois from it.
holder = individu.get_holder('age_en_mois')
start = period.start
known_periods = holder.get_known_periods()
for last_period in sorted(known_periods, reverse = True):
last_start = last_period.start
if last_start.day == start.day:
last_array = holder.get_array(last_period)
return last_array + ((start.year - last_start.year) * 12 + (start.month - last_start.month))
has_birth = individu.get_holder('date_naissance').get_known_periods()
if not has_birth:
has_age = bool(individu.get_holder('age').get_known_periods())
if has_age:
return individu('age', period) * 12
date_naissance = individu('date_naissance', period)
epsilon = timedelta64(1)
return (datetime64(period.start) - date_naissance + epsilon).astype('timedelta64[M]')
class depcom_foyer(Variable):
value_type = str
max_length = 5
entity = FoyerFiscal
default_value = "00000"
label = "Code AFT du lieu de domicile fiscal"
definition_period = YEAR
set_input = set_input_dispatch_by_period
# Cette variable est similaire à la variable "depcom" qui est le lieu de domicile du ménage tandis que "depcom_foyer" est le lieu de résidence fiscale du foyer fiscal.
class residence_fiscale_guadeloupe(Variable):
value_type = bool
entity = FoyerFiscal
definition_period = YEAR
def formula(foyer_fiscal, period, parameters):
depcom_foyer = foyer_fiscal('depcom_foyer', period)
return startswith(depcom_foyer, b'971')
class residence_fiscale_martinique(Variable):
value_type = bool
entity = FoyerFiscal
definition_period = YEAR
def formula(foyer_fiscal, period, parameters):
depcom_foyer = foyer_fiscal('depcom_foyer', period)
return startswith(depcom_foyer, b'972')
class residence_fiscale_guyane(Variable):
value_type = bool
entity = FoyerFiscal
definition_period = YEAR
def formula(foyer_fiscal, period, parameters):
depcom_foyer = foyer_fiscal('depcom_foyer', period)
return startswith(depcom_foyer, b'973')
class residence_fiscale_reunion(Variable):
value_type = bool
entity = FoyerFiscal
definition_period = YEAR
def formula(foyer_fiscal, period, parameters):
depcom_foyer = foyer_fiscal('depcom_foyer', period)
return startswith(depcom_foyer, b'974')
class residence_fiscale_mayotte(Variable):
value_type = bool
entity = FoyerFiscal
definition_period = YEAR
def formula(foyer_fiscal, period, parameters):
depcom_foyer = foyer_fiscal('depcom_foyer', period)
return startswith(depcom_foyer, b'976')
class nb_adult(Variable):
value_type = float
entity = FoyerFiscal
label = "Nombre d'adulte(s) déclarants dans le foyer fiscal"
definition_period = YEAR
def formula(foyer_fiscal, period, parameters):
maries_ou_pacses = foyer_fiscal('maries_ou_pacses', period)
celibataire_ou_divorce = foyer_fiscal('celibataire_ou_divorce', period)
veuf = foyer_fiscal('veuf', period)
return 2 * maries_ou_pacses + 1 * (celibataire_ou_divorce | veuf)
class nb_pac(Variable):
value_type = float
entity = FoyerFiscal
label = "Nombre de personnes à charge dans le foyer fiscal"
definition_period = YEAR
def formula(foyer_fiscal, period, parameters):
nbF = foyer_fiscal('nbF', period)
nbJ = foyer_fiscal('nbJ', period)
nbR = foyer_fiscal('nbR', period)
return nbF + nbJ + nbR
class enfant_a_charge(Variable):
value_type = bool
entity = Individu
label = "Enfant à charge non marié, de moins de 18 ans au 1er janvier de l'année de perception des" \
" revenus, ou né durant la même année, ou handicapés quel que soit son âge"
definition_period = YEAR
def formula(individu, period):
janvier = period.first_month
decembre = janvier.offset(11, 'month')
age = individu('age', janvier)
handicap = individu('handicap', decembre)
is_pac = individu.has_role(FoyerFiscal.PERSONNE_A_CHARGE)
return is_pac * ((age < 18) + handicap)
class nbF(Variable):
cerfa_field = 'F'
entity = FoyerFiscal
value_type = float
label = "Nombre d'enfants à charge non mariés, qui ne sont pas en résidence alternée, de moins de 18 ans au 1er janvier de l'année de perception des" \
" revenus, ou nés durant la même année ou handicapés quel que soit leur âge"
definition_period = YEAR
def formula(foyer_fiscal, period, parameters):
janvier = period.first_month
enfant_a_charge = foyer_fiscal.members('enfant_a_charge', period)
garde_alternee = foyer_fiscal.members('garde_alternee', janvier)
return foyer_fiscal.sum(enfant_a_charge * not_(garde_alternee))
class nbG(Variable):
cerfa_field = 'G'
entity = FoyerFiscal
value_type = float
label = "Nombre d'enfants qui ne sont pas en résidence alternée à charge titulaires de la carte d'invalidité."
definition_period = YEAR
def formula(foyer_fiscal, period, parameters):
janvier = period.first_month
enfant_a_charge = foyer_fiscal.members('enfant_a_charge', period)
garde_alternee = foyer_fiscal.members('garde_alternee', janvier)
invalidite = foyer_fiscal.members('invalidite', janvier)
return foyer_fiscal.sum(enfant_a_charge * not_(garde_alternee) * invalidite)
class nbH(Variable):
cerfa_field = 'H'
entity = FoyerFiscal
value_type = float
label = "Nombre d'enfants à charge en résidence alternée, non mariés de moins de 18 ans au 1er janvier de l'année de perception des revenus, ou nés durant la même année ou handicapés quel que soit leur âge"
definition_period = YEAR
def formula(foyer_fiscal, period, parameters):
janvier = period.first_month
enfant_a_charge = foyer_fiscal.members('enfant_a_charge', period)
garde_alternee = foyer_fiscal.members('garde_alternee', janvier)
return foyer_fiscal.sum(enfant_a_charge * garde_alternee)
class nbI(Variable):
cerfa_field = 'I'
entity = FoyerFiscal
value_type = float
label = "Nombre d'enfants à charge en résidence alternée titulaires de la carte d'invalidité"
definition_period = YEAR
def formula(foyer_fiscal, period, parameters):
janvier = period.first_month
enfant_a_charge = foyer_fiscal.members('enfant_a_charge', period)
garde_alternee = foyer_fiscal.members('garde_alternee', janvier)
invalidite = foyer_fiscal.members('invalidite', janvier)
return foyer_fiscal.sum(enfant_a_charge * garde_alternee * invalidite)
class enfant_majeur_celibataire_sans_enfant(Variable):
value_type = bool
entity = Individu
label = "Enfant majeur célibataire sans enfant"
definition_period = YEAR
def formula(individu, period):
janvier = period.first_month
age = individu('age', janvier)
handicap = individu('handicap', janvier)
is_pac = individu.has_role(FoyerFiscal.PERSONNE_A_CHARGE)
return is_pac * (age >= 18) * not_(handicap)
class nbJ(Variable):
cerfa_field = 'J'
entity = FoyerFiscal
label = "Nombre d'enfants majeurs célibataires sans enfant"
value_type = int
definition_period = YEAR
def formula(foyer_fiscal, period):
enfant_majeur_celibataire_sans_enfant = foyer_fiscal.members('enfant_majeur_celibataire_sans_enfant', period)
return foyer_fiscal.sum(enfant_majeur_celibataire_sans_enfant)
class nombre_enfants_majeurs_celibataires_sans_enfant(Variable):
entity = Menage
label = "Nombre d'enfants majeurs célibataires sans enfant"
value_type = int
definition_period = YEAR
def formula(menage, period):
enfant_majeur_celibataire_sans_enfant = menage.members('enfant_majeur_celibataire_sans_enfant', period)
return menage.sum(enfant_majeur_celibataire_sans_enfant)
class maries_ou_pacses(Variable):
value_type = bool
entity = FoyerFiscal
label = "Déclarants mariés ou pacsés"
definition_period = YEAR
def formula(foyer_fiscal, period):
statut_marital = foyer_fiscal.declarant_principal('statut_marital', period.first_month)
marie_ou_pacse = (statut_marital == TypesStatutMarital.marie) | (statut_marital == TypesStatutMarital.pacse)
return marie_ou_pacse
class celibataire_ou_divorce(Variable):
value_type = bool
entity = FoyerFiscal
label = "Déclarant célibataire ou divorcé"
definition_period = YEAR
def formula(foyer_fiscal, period):
statut_marital = foyer_fiscal.declarant_principal('statut_marital', period.first_month)
celibataire_ou_divorce = (statut_marital == TypesStatutMarital.celibataire) | (
statut_marital == TypesStatutMarital.divorce
)
return celibataire_ou_divorce
class veuf(Variable):
value_type = bool
entity = FoyerFiscal
label = "Déclarant veuf"
definition_period = YEAR
def formula(foyer_fiscal, period):
statut_marital = foyer_fiscal.declarant_principal('statut_marital', period.first_month)
veuf = (statut_marital == TypesStatutMarital.veuf)
return veuf
class jeune_veuf(Variable):
value_type = bool
entity = FoyerFiscal
label = "Déclarant jeune veuf"
definition_period = YEAR
def formula(foyer_fiscal, period):
statut_marital = foyer_fiscal.declarant_principal('statut_marital', period.first_month)
jeune_veuf = (statut_marital == TypesStatutMarital.jeune_veuf)
return jeune_veuf
###############################################################################
# # Revenus catégoriels
###############################################################################
class revenu_assimile_salaire(Variable):
value_type = float
entity = Individu
label = "Revenu imposé comme des salaires (salaires, mais aussi 3vj, 3vk)"
definition_period = YEAR
def formula(individu, period, parameters):
salaire_imposable = individu('salaire_imposable', period, options = [ADD])
chomage_imposable = individu('chomage_imposable', period, options = [ADD])
f1tt = individu('f1tt', period)
f3vj = individu('f3vj', period)
return salaire_imposable + chomage_imposable + f1tt + f3vj
class revenu_assimile_salaire_apres_abattements(Variable):
value_type = float
entity = Individu
label = "Salaires et chômage imposables après abattements"
definition_period = YEAR
def formula(individu, period, parameters):
revenu_assimile_salaire = individu('revenu_assimile_salaire', period)
chomeur_longue_duree = individu('chomeur_longue_duree', period)
frais_reels = individu('frais_reels', period)
abatpro = parameters(period).impot_revenu.tspr.abatpro
abattement_minimum = where(chomeur_longue_duree, abatpro.min2, abatpro.min)
abatfor = round_(min_(max_(abatpro.taux * revenu_assimile_salaire, abattement_minimum), abatpro.max))
return (
(frais_reels > abatfor)
* (revenu_assimile_salaire - frais_reels)
+ (frais_reels <= abatfor)
* max_(0, revenu_assimile_salaire - abatfor)
)
class revenu_assimile_pension(Variable):
value_type = float
entity = Individu
label = "Revenu imposé comme des pensions (retraites, pensions alimentaires, etc.)"
definition_period = YEAR
def formula(individu, period):
pensions_alimentaires_percues = individu('pensions_alimentaires_percues', period, options = [ADD])
pensions_alimentaires_percues_decl = individu('pensions_alimentaires_percues_decl', period, options = [ADD])
retraite_imposable = individu('retraite_imposable', period, options = [ADD])
pension_invalidite = individu('pensions_invalidite', period, options = [ADD])
return pensions_alimentaires_percues * pensions_alimentaires_percues_decl + retraite_imposable + pension_invalidite
class revenu_assimile_pension_apres_abattements(Variable):
value_type = float
entity = Individu
label = "Pensions après abattements"
definition_period = YEAR
def formula(individu, period, parameters):
revenu_assimile_pension = individu('revenu_assimile_pension', period)
abatpen = parameters(period).impot_revenu.tspr.abatpen
# TODO: problème car les pensions sont majorées au niveau du foyer
# d11 = ( AS + BS + CS + DS + ES +
# AO + BO + CO + DO + EO )
# penv2 = (d11-f11> abatpen.max)*(penv + (d11-f11-abatpen.max)) + (d11-f11<= abatpen.max)*penv
# Plus d'abatement de 20% en 2006
return max_(0, revenu_assimile_pension - round_(max_(abatpen.taux * revenu_assimile_pension, abatpen.min)))
# return max_(0, revenu_assimile_pension - min_(round_(max_(abatpen.taux*revenu_assimile_pension , abatpen.min)), abatpen.max)) le max se met au niveau du foyer
class indu_plaf_abat_pen(Variable):
value_type = float
entity = FoyerFiscal
label = "Plafonnement de l'abattement de 10% sur les pensions du foyer"
definition_period = YEAR
def formula(foyer_fiscal, period, parameters):
rev_pen_i = foyer_fiscal.members('revenu_assimile_pension', period)
pen_net_i = foyer_fiscal.members('revenu_assimile_pension_apres_abattements', period)
abatpen = parameters(period).impot_revenu.tspr.abatpen
revenu_assimile_pension_apres_abattements = foyer_fiscal.sum(pen_net_i)
revenu_assimile_pension = foyer_fiscal.sum(rev_pen_i)
abat = revenu_assimile_pension - revenu_assimile_pension_apres_abattements
return abat - min_(abat, abatpen.max)
class abattement_salaires_pensions(Variable):
value_type = float
entity = Individu
label = "Abattement de 20% sur les salaires et pensions, en vigueur jusqu'à 2006"
end = '2005-12-31'
definition_period = YEAR
def formula(individu, period, parameters):
revenu_assimile_salaire_apres_abattements = individu('revenu_assimile_salaire_apres_abattements', period)
revenu_assimile_pension_apres_abattements = individu('revenu_assimile_pension_apres_abattements', period)
abatsalpen = parameters(period).impot_revenu.tspr.abatsalpen
return min_(abatsalpen.taux * max_(revenu_assimile_salaire_apres_abattements + revenu_assimile_pension_apres_abattements, 0), abatsalpen.max)
class rente_viagere_titre_onereux(Variable):
"""Rentes viagères à titre onéreux (avant abattements)
Annuel pour les impôts mais mensuel pour la base ressource des minimas sociaux donc mensuel.
"""
calculate_output = calculate_output_add
value_type = float
entity = FoyerFiscal
label = "Rentes viagères (rentes à titre onéreux)"
set_input = set_input_divide_by_period
reference = "http://fr.wikipedia.org/wiki/Rente_viagère"
definition_period = MONTH
def formula(foyer_fiscal, period, parameters):
year = period.this_year
f1aw = foyer_fiscal('f1aw', year)
f1bw = foyer_fiscal('f1bw', year)
f1cw = foyer_fiscal('f1cw', year)
f1dw = foyer_fiscal('f1dw', year)
return (f1aw + f1bw + f1cw + f1dw) / 12
class rente_viagere_titre_onereux_net(Variable):
value_type = float
entity = FoyerFiscal
label = "Rentes viagères après abattements"
reference = "http://www.lafinancepourtous.fr/Vie-professionnelle-et-retraite/Retraite/Epargne-retraite/La-rente-viagere/La-fiscalite-de-la-rente-viagere"
definition_period = YEAR
def formula(foyer_fiscal, period, parameters):
'''
Selon la législation, le taux d'abattement appliqué dépend de l'âge du bénéficiaire lors du premier versement
de la rente. Il y a quatre taux possibles. On suppoose que la case 1aw bénéficie du taux associé à l'âge le
moins élevé, et ainsi de suite jusqu'à la case 1dw qui bénéficie du taux associé à l'âge le plus élevé.
'''
f1aw = foyer_fiscal('f1aw', period)
f1bw = foyer_fiscal('f1bw', period)
f1cw = foyer_fiscal('f1cw', period)
f1dw = foyer_fiscal('f1dw', period)
abatviag = parameters(period).impot_revenu.tspr.abatviag
return round_(
+ abatviag.taux1 * f1aw
+ abatviag.taux2 * f1bw
+ abatviag.taux3 * f1cw
+ abatviag.taux4 * f1dw
)
class traitements_salaires_pensions_rentes(Variable):
value_type = float
entity = Individu
label = "Traitements salaires pensions et rentes individuelles"
definition_period = YEAR
def formula(individu, period):
revenu_assimile_salaire_apres_abattements = individu('revenu_assimile_salaire_apres_abattements', period)
revenu_assimile_pension_apres_abattements = individu('revenu_assimile_pension_apres_abattements', period)
abattement_salaires_pensions = individu('abattement_salaires_pensions', period)
# Quand tspr est calculé sur une année glissante, rente_viagere_titre_onereux_net est calculé sur l'année légale
# correspondante.
rente_viagere_titre_onereux_net = individu.foyer_fiscal('rente_viagere_titre_onereux_net', period.offset('first-of'))
rente_viagere_titre_onereux_net_declarant1 = rente_viagere_titre_onereux_net * individu.has_role(FoyerFiscal.DECLARANT_PRINCIPAL)
return (
+ revenu_assimile_salaire_apres_abattements
+ revenu_assimile_pension_apres_abattements
+ rente_viagere_titre_onereux_net_declarant1
- abattement_salaires_pensions
)
class revenu_categoriel_plus_values(Variable):
value_type = float
entity = FoyerFiscal
label = "Revenu catégoriel - Plus-values"
reference = "http://www.insee.fr/fr/methodes/default.asp?page=definitions/revenus-categoriesl.htm"
definition_period = YEAR
def formula_2013_01_01(foyer_fiscal, period, parameters):
f3sb = foyer_fiscal('f3sb', period)
f3vg = foyer_fiscal('f3vg', period)
f3vl = foyer_fiscal('f3vl', period)
f3wb = foyer_fiscal('f3wb', period)
return f3sb + f3vg + f3vl + f3wb
def formula_2014_01_01(foyer_fiscal, period, parameters):
f3sb = foyer_fiscal('f3sb', period)
f3vg = foyer_fiscal('f3vg', period)
f3wb = foyer_fiscal('f3wb', period)
return f3sb + f3vg + f3wb
def formula_2017_01_01(foyer_fiscal, period, parameters):
f3sb = foyer_fiscal('f3sb', period)
f3vg = foyer_fiscal('f3vg', period)
f3wb = foyer_fiscal('f3wb', period)
f3ua = foyer_fiscal('f3ua', period) # Cette case existant avant, mais ses montants étaient inclus dans 3vg.
return f3sb + f3vg + f3wb + f3ua
def formula_2018_01_01(foyer_fiscal, period, parameters):
f3wb = foyer_fiscal('f3wb', period)
return f3wb
class revenu_categoriel_tspr(Variable):
value_type = float
entity = FoyerFiscal
label = "Revenu catégoriel - Traitements, salaires, pensions et rentes"
reference = "http://www.insee.fr/fr/methodes/default.asp?page=definitions/revenus-categoriesl.htm"
definition_period = YEAR
def formula(foyer_fiscal, period, parameters):
tspr_i = foyer_fiscal.members('traitements_salaires_pensions_rentes', period)
indu_plaf_abat_pen = foyer_fiscal('indu_plaf_abat_pen', period)
traitements_salaires_pensions_rentes = foyer_fiscal.sum(tspr_i)
return traitements_salaires_pensions_rentes + indu_plaf_abat_pen
class deficit_rcm(Variable):
value_type = float
entity = FoyerFiscal
label = "Deficit capitaux mobiliers"
reference = "http://www.lefigaro.fr/impots/2008/04/25/05003-20080425ARTFIG00254-les-subtilites-des-revenus-de-capitaux-mobiliers-.php"
definition_period = YEAR
def formula_2009_01_01(foyer_fiscal, period, parameters):
f2aa = foyer_fiscal('f2aa', period)
f2al = foyer_fiscal('f2al', period)
f2am = foyer_fiscal('f2am', period)
f2an = foyer_fiscal('f2an', period)
f2aq = foyer_fiscal('f2aq', period)
f2ar = foyer_fiscal('f2ar', period)
return f2aa + f2al + f2am + f2an + f2aq + f2ar
class revenu_categoriel_capital(Variable):
value_type = float
entity = FoyerFiscal
label = "Revenu catégoriel - Capitaux"
reference = "http://www.insee.fr/fr/methodes/default.asp?page=definitions/revenus-categoriesl.htm"
definition_period = YEAR
def formula_2002_01_01(foyer_fiscal, period, parameters):
"""
Revenus des valeurs et capitaux mobiliers
"""
maries_ou_pacses = foyer_fiscal('maries_ou_pacses', period)
deficit_rcm = foyer_fiscal('deficit_rcm', period)
f2ch = foyer_fiscal('f2ch', period)
f2dc = foyer_fiscal('f2dc', period)
f2ts = foyer_fiscal('f2ts', period)
f2ca = foyer_fiscal('f2ca', period)
f2fu = foyer_fiscal('f2fu', period)
f2go = foyer_fiscal('f2go', period)
f2gr = foyer_fiscal('f2gr', period)
f2tr = foyer_fiscal('f2tr', period)
rvcm = parameters(period).impot_revenu.rvcm
f2dc_bis = f2dc
f2tr_bis = f2tr
# # Calcul du revenu catégoriel
# 1.2 Revenus des valeurs et capitaux mobiliers
b12 = min_(f2ch, rvcm.abat_assvie * (1 + maries_ou_pacses))
TOT1 = f2ch - b12 # c12
# Part des frais s'imputant sur les revenus déclarés case DC
den = ((f2dc_bis + f2ts) != 0) * (f2dc_bis + f2ts) + ((f2dc_bis + f2ts) == 0)
F1 = f2ca / den * f2dc_bis # f12
# Revenus de capitaux mobiliers nets de frais, ouvrant droit à abattement
# partie négative (à déduire des autres revenus nets de frais d'abattements
g12a = -min_(f2dc_bis * (1 - rvcm.taux_abattement_capitaux_mobiliers) - F1, 0)
# partie positive
g12b = max_(f2dc_bis * (1 - rvcm.taux_abattement_capitaux_mobiliers) - F1, 0)
rev = g12b + f2gr + f2fu * (1 - rvcm.taux_abattement_capitaux_mobiliers)
# Abattements, limité au revenu
h12 = rvcm.abatmob * (1 + maries_ou_pacses)
TOT2 = max_(0, rev - h12)
# i121= -min_(0,rev - h12)
# Part des frais s'imputant sur les revenus déclarés ligne TS
F2 = f2ca - F1
TOT3 = (f2ts - F2) + f2go * rvcm.majoration_revenus_reputes_distribues + f2tr_bis - g12a
DEF = deficit_rcm
return max_(TOT1 + TOT2 + TOT3 - DEF, 0)
def formula_2005_01_01(foyer_fiscal, period, parameters):
"""
Revenus des valeurs et capitaux mobiliers
"""
maries_ou_pacses = foyer_fiscal('maries_ou_pacses', period)
deficit_rcm = foyer_fiscal('deficit_rcm', period)
f2ch = foyer_fiscal('f2ch', period)
f2da = foyer_fiscal('f2da', period)
f2dc = foyer_fiscal('f2dc', period)
f2ts = foyer_fiscal('f2ts', period)
f2ca = foyer_fiscal('f2ca', period)
f2fu = foyer_fiscal('f2fu', period)
f2go = foyer_fiscal('f2go', period)
f2gr = foyer_fiscal('f2gr', period)
f2tr = foyer_fiscal('f2tr', period)
parameter_rvcm = parameters(period).impot_revenu.rvcm
part_frais_imputes_sur_f2dc = f2ca / max_(1, f2dc + f2ts) * f2dc
part_frais_restant_a_imputer = -min_(f2dc * (1 - parameter_rvcm.taux_abattement_capitaux_mobiliers * (f2da == 0)) - part_frais_imputes_sur_f2dc, 0)
dividendes_apres_abattements = max_(f2dc * (1 - parameter_rvcm.taux_abattement_capitaux_mobiliers * (f2da == 0)) - part_frais_imputes_sur_f2dc, 0)
revenus_assurance_vie_apres_abattements = f2ch - min_(f2ch, parameter_rvcm.abat_assvie * (1 + maries_ou_pacses))
rvcm_apres_abattements_proportionnels = (
revenus_assurance_vie_apres_abattements
+ dividendes_apres_abattements
+ f2gr
+ f2fu * (1 - parameter_rvcm.taux_abattement_capitaux_mobiliers * (f2da == 0))
)
rvcm_apres_abattements_proportionnels_et_fixes = max_(0, rvcm_apres_abattements_proportionnels - parameter_rvcm.abatmob * (1 + maries_ou_pacses))
autres_rvcm_sans_abattements = (
f2ts - (f2ca - part_frais_imputes_sur_f2dc)
+ f2go * parameter_rvcm.majoration_revenus_reputes_distribues
+ f2tr - part_frais_restant_a_imputer
)
return max_(rvcm_apres_abattements_proportionnels_et_fixes + autres_rvcm_sans_abattements - deficit_rcm, 0)
def formula_2013_01_01(foyer_fiscal, period, parameters):
"""
Revenus des valeurs et capitaux mobiliers
"""
maries_ou_pacses = foyer_fiscal('maries_ou_pacses', period)
deficit_rcm = foyer_fiscal('deficit_rcm', period)
f2ca = foyer_fiscal('f2ca', period)
f2ch = foyer_fiscal('f2ch', period)
f2dc = foyer_fiscal('f2dc', period)
f2fu = foyer_fiscal('f2fu', period)
f2go = foyer_fiscal('f2go', period)
f2tr = foyer_fiscal('f2tr', period)
f2ts = foyer_fiscal('f2ts', period)
P = parameters(period).impot_revenu.rvcm
# Revenus après abatemment
abattement_dividende = (f2fu + f2dc) * P.taux_abattement_capitaux_mobiliers
abattement_assurance_vie = P.abat_assvie * (1 + maries_ou_pacses)
rvcm_apres_abattement = (
f2fu + f2dc - abattement_dividende
+ f2ch - min_(f2ch, abattement_assurance_vie)
+ f2ts + f2tr + f2go * P.majoration_revenus_reputes_distribues
)
return max_(0, rvcm_apres_abattement - f2ca - deficit_rcm)
def formula_2016_01_01(foyer_fiscal, period, parameters):
"""
Revenus des valeurs et capitaux mobiliers
"""
maries_ou_pacses = foyer_fiscal('maries_ou_pacses', period)
deficit_rcm = foyer_fiscal('deficit_rcm', period)
f2ca = foyer_fiscal('f2ca', period)
f2ch = foyer_fiscal('f2ch', period)
f2dc = foyer_fiscal('f2dc', period)
f2fu = foyer_fiscal('f2fu', period)
f2go = foyer_fiscal('f2go', period)
f2tr = foyer_fiscal('f2tr', period)
f2ts = foyer_fiscal('f2ts', period)
f2tt_2016 = foyer_fiscal('f2tt_2016', period)
f2tu_2016 = foyer_fiscal('f2tu_2016', period)
P = parameters(period).impot_revenu.rvcm
# Revenus après abatemment
abattement_dividende = (f2fu + f2dc) * P.taux_abattement_capitaux_mobiliers
abattement_assurance_vie = P.abat_assvie * (1 + maries_ou_pacses)
rvcm_apres_abattement = (
f2fu + f2dc - abattement_dividende
+ f2ch - min_(f2ch, abattement_assurance_vie)
+ f2ts + f2tr + max_(0, f2tt_2016 - f2tu_2016) + f2go * P.majoration_revenus_reputes_distribues
)
return max_(0, rvcm_apres_abattement - f2ca - deficit_rcm)
def formula_2017_01_01(foyer_fiscal, period, parameters):
"""
Revenus des valeurs et capitaux mobiliers
Seule différence avec la formule précédente :
On enlève la case 2TU. En 2016, 2TT contient les intérêts avant pertes
et 2TU les pertes déductibles des intérêts inscrits en 2TT (si le montant en 2TU est > à celui en 2TT,
la perte excédentaire est reportable sur les cinq années suivantes). En 2017, 2TT contient les intérêts
après déduction des pertes. 2TU, et aussi 2TV, contiennent des pertes excéndentaires à reporter.
Sources :
- Brochure pratique de l'IR 2018 sur revenus 2017 : https://www.impots.gouv.fr/portail/www2/fichiers/documentation/brochure/ir_2018/files/assets/common/downloads/Brochure%20IR%202018.pdf
- Brochure pratique de l'IR 2017 sur revenus 2016 : https://www.impots.gouv.fr/portail/www2/fichiers/documentation/brochure/ir_2017/files/assets/common/downloads/publication.pdf
"""
maries_ou_pacses = foyer_fiscal('maries_ou_pacses', period)
deficit_rcm = foyer_fiscal('deficit_rcm', period)
f2ca = foyer_fiscal('f2ca', period)
f2ch = foyer_fiscal('f2ch', period)
f2dc = foyer_fiscal('f2dc', period)
f2fu = foyer_fiscal('f2fu', period)
f2go = foyer_fiscal('f2go', period)
f2tr = foyer_fiscal('f2tr', period)
f2ts = foyer_fiscal('f2ts', period)
f2tt = foyer_fiscal('f2tt', period)
P = parameters(period).impot_revenu.rvcm
# Revenus après abatemment
abattement_dividende = (f2fu + f2dc) * P.taux_abattement_capitaux_mobiliers
abattement_assurance_vie = P.abat_assvie * (1 + maries_ou_pacses)
rvcm_apres_abattement = (
f2fu + f2dc - abattement_dividende
+ f2ch - min_(f2ch, abattement_assurance_vie)
+ f2ts + f2tr + f2tt + f2go * P.majoration_revenus_reputes_distribues
)
return max_(0, rvcm_apres_abattement - f2ca - deficit_rcm)
def formula_2018_01_01(foyer_fiscal, period, parameters):
"""
Revenus des valeurs et capitaux mobiliers
NB : La mise en place du PFU supprime la taxation au barème de la plupart des revenus des valeurs et capitaux mobiliers.
Ces revenus sortent donc de la variable `revenu_categoriel_capital` et entrent dans la variable `revenus_capitaux_prelevement_forfaitaire_unique_ir`.
"""
maries_ou_pacses = foyer_fiscal('maries_ou_pacses', period)
deficit_rcm = foyer_fiscal('deficit_rcm', period)
f2ch = foyer_fiscal('f2ch', period)
f2yy = foyer_fiscal('f2yy', period)
P = parameters(period).impot_revenu.rvcm
abattement_assurance_vie = P.abat_assvie * (1 + maries_ou_pacses)
rvcm_apres_abattement = (
f2yy
+ f2ch - min_(f2ch, abattement_assurance_vie)
)
return max_(0, rvcm_apres_abattement - deficit_rcm)
class rfr_rvcm_abattements_a_reintegrer(Variable):
value_type = float
entity = FoyerFiscal
label = "Abattement sur revenus des valeurs et capitaux mobiliers à réintégrer dans le calcul du revenu fiscal de référence"
definition_period = YEAR
def formula(foyer_fiscal, period, parameters):
maries_ou_pacses = foyer_fiscal('maries_ou_pacses', period)
f2da = foyer_fiscal('f2da', period)
f2dc = foyer_fiscal('f2dc', period)
f2ts = foyer_fiscal('f2ts', period)
f2ca = foyer_fiscal('f2ca', period)
f2gr = foyer_fiscal('f2gr', period)
f2fu = foyer_fiscal('f2fu', period)
f2da = foyer_fiscal('f2da', period) # noqa F841
rvcm = parameters(period).impot_revenu.rvcm
# Calcul de i121
# Part des frais s'imputant sur les revenus déclarés case DC
den = ((f2dc + f2ts) != 0) * (f2dc + f2ts) + ((f2dc + f2ts) == 0)
F1 = f2ca / den * f2dc # f12
# Revenus de capitaux mobiliers nets de frais, ouvrant droit à abattement
# partie positive
g12b = max_(f2dc * (1 - rvcm.taux_abattement_capitaux_mobiliers * (f2da == 0)) - F1, 0)
rev = g12b + f2gr + f2fu * (1 - rvcm.taux_abattement_capitaux_mobiliers * (f2da == 0))
# Abattements, limité au revenu
h12 = rvcm.abatmob * (1 + maries_ou_pacses)
i121 = - min_(0, rev - h12)
return max_((rvcm.taux_abattement_capitaux_mobiliers) * (f2dc + f2fu) * (f2da == 0) - i121, 0)
def formula_2013_01_01(foyer_fiscal, period, parameters):
f2dc = foyer_fiscal('f2dc', period)
f2fu = foyer_fiscal('f2fu', period)
P = parameters(period).impot_revenu.rvcm
abattement_dividende = (f2fu + f2dc) * P.taux_abattement_capitaux_mobiliers
return abattement_dividende
def formula_2018_01_01(foyer_fiscal, period, parameters):
"""
2 remarques :
- L'abattement sur les dividendes devrait être intégré dans cette formule (il s'ajoute au RFR) mais on attends pour cela de coder l'option pour l'imposition au barème des dividendes.
- À partir de 2018, les revenus de l'assurance-vie sont taxés au PFU et entrent dans le calcul du RFR via `revenus_capitaux_prelevement_forfaitaire_unique_ir`.
Cette variable est brute d'abattement. Or, l'abattement sur les assurance-vie se déduit bien du RFR (contrairement à celui sur les dividendes). On le rajoute donc ici en négatif.
"""
maries_ou_pacses = foyer_fiscal('maries_ou_pacses', period)
f2ch = foyer_fiscal('f2ch', period)
f2dh = foyer_fiscal('f2dh', period)
f2vv = foyer_fiscal('f2vv', period)
f2ww = foyer_fiscal('f2ww', period)
P = parameters(period).impot_revenu.rvcm
abattement_assurance_vie = (
(f2ch < P.abat_assvie * (1 + maries_ou_pacses)) * max_(0, min_(f2vv + f2ww, P.abat_assvie * (1 + maries_ou_pacses) - f2ch - f2dh))
)
return - abattement_assurance_vie
class revenu_categoriel_foncier(Variable):
value_type = float
entity = FoyerFiscal
label = "Revenu catégoriel - Foncier"
reference = "http://www.insee.fr/fr/methodes/default.asp?page=definitions/revenus-categoriesl.htm"
definition_period = YEAR
def formula(foyer_fiscal, period, parameters):
"""
Revenus fonciers
"""
f4ba = foyer_fiscal('f4ba', period)
f4bb = foyer_fiscal('f4bb', period)
f4bc = foyer_fiscal('f4bc', period)
f4bd = foyer_fiscal('f4bd', period)
f4be = foyer_fiscal('f4be', period)
microfoncier = parameters(period).impot_revenu.rpns.micro.microfoncier
# Messages d'erreurs
if ((f4ba != 0) & ((f4bb != 0) | (f4bc != 0))).any():
log.error(("Problème de déclarations des revenus : incompatibilité de la déclaration des revenus fonciers (f4ba) et de déficits (f4bb, f4bc)"))
if ((f4be != 0) & ((f4ba != 0) | (f4bb != 0) | (f4bc != 0))).any():
log.error(("Problème de déclarations des revenus : incompatibilité de la déclaration des revenus fonciers (f4ba, f4bb, f4bc) et microfonciers (f4be)"))
if (f4be > microfoncier.max).any():
log.error(("Problème de déclarations des revenus : les revenus microfonciers (f4be) dépassent le maximum légal"))
micro = min_(f4be, microfoncier.max) * (1 - microfoncier.taux)
# Conditions
deficit = (f4bc > 0) | (f4bb > 0)
micro = f4be > 0
# Calculs
si_deficit = -f4bc
si_micro = min_(f4be, microfoncier.max) * (1 - microfoncier.taux)
sinon = max_(0, f4ba - f4bd)
return select([deficit, micro],
[si_deficit, si_micro], sinon)
class revenu_categoriel_non_salarial(Variable):
value_type = float
entity = FoyerFiscal
label = "Revenu catégoriel - Revenus personnels non salariés"
reference = "http://www.insee.fr/fr/methodes/default.asp?page=definitions/revenus-categoriesl.htm"
definition_period = YEAR
def formula(foyer_fiscal, period, parameters):
nbnc_pvce_i = foyer_fiscal.members('nbnc_pvce', period)
rpns_i = foyer_fiscal.members('rpns_individu', period)
nbnc_pvce = foyer_fiscal.sum(nbnc_pvce_i)
rpns = foyer_fiscal.sum(rpns_i)
defrag = foyer_fiscal('defrag', period)
defacc = foyer_fiscal('defacc', period)
defncn = foyer_fiscal('defncn', period)
defmeu = foyer_fiscal('defmeu', period)
cga = parameters(period).impot_revenu.rpns.cga_taux2
return (
rpns
- (1 + cga) * nbnc_pvce
- defrag
- defncn
- defacc
- defmeu
)
class revenu_categoriel(Variable):
value_type = float
entity = FoyerFiscal
label = "Revenus catégoriels"
reference = "http://www.insee.fr/fr/methodes/default.asp?page=definitions/revenus-categoriesl.htm"
definition_period = YEAR
def formula(foyer_fiscal, period, parameters):
'''
Revenus Categoriels
'''
rev_cat_tspr = foyer_fiscal('revenu_categoriel_tspr', period)
rev_cat_rvcm = foyer_fiscal('revenu_categoriel_capital', period)
rev_cat_rfon = foyer_fiscal('revenu_categoriel_foncier', period)
rev_cat_rpns = foyer_fiscal('revenu_categoriel_non_salarial', period)
rev_cat_pv = foyer_fiscal('revenu_categoriel_plus_values', period)
return rev_cat_tspr + rev_cat_rvcm + rev_cat_rfon + rev_cat_rpns + rev_cat_pv
###############################################################################
# # Déroulé du calcul de l'irpp
###############################################################################
class deficit_ante(Variable):
value_type = float
entity = FoyerFiscal