Skip to content

Commit 714fcba

Browse files
committed
Add vat
1 parent c0dd174 commit 714fcba

2 files changed

Lines changed: 68 additions & 23 deletions

File tree

packages/donnees-reglementaires/bin/fetch.ts

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import fs from "node:fs/promises";
22
import path from "node:path";
33
import { differenceInYears } from "date-fns/differenceInYears";
4+
import { subYears } from "date-fns/subYears";
45
import merge from "lodash.merge";
56
import set from "lodash.set";
67
import { parse } from "yaml";
@@ -80,6 +81,10 @@ async function fetchFromOpenFiscaFrance() {
8081
"taxation_societes/impot_societe/seuil_superieur_benefices_taux_reduit",
8182
"taxation_societes/impot_societe/taux_normal",
8283
"taxation_societes/impot_societe/taux_reduit",
84+
"taxation_indirecte/tva/taux_reduit",
85+
"taxation_indirecte/tva/taux_intermediaire",
86+
"taxation_indirecte/tva/taux_normal",
87+
"taxation_indirecte/tva/taux_particulier_super_reduit",
8388
];
8489

8590
for (const regle of regles) {
@@ -104,12 +109,14 @@ async function fetchFromOpenFiscaFrance() {
104109
) & {
105110
description: string;
106111
metadata: {
107-
last_value_still_valid_on: string;
112+
last_value_still_valid_on?: string;
108113
};
109114
};
110115

111116
const lastValueStillValidOn = new Date(
112-
json.metadata.last_value_still_valid_on,
117+
json.metadata.last_value_still_valid_on ??
118+
// TODO: récupérer la dernière date de mise à jour de la valeur à défaut de "last_value_still_valid_on"
119+
subYears(aujourdhui, 30),
113120
);
114121
const lastValueInvalidSinceYears = differenceInYears(
115122
aujourdhui,
@@ -118,31 +125,42 @@ async function fetchFromOpenFiscaFrance() {
118125

119126
if (lastValueInvalidSinceYears >= 1) {
120127
warnings.push(
121-
`⚠️ ${regle} a été vérifiée il y a au moins ${lastValueInvalidSinceYears} an(s)`,
128+
`⚠️ ${regle} a été vérifiée pour la dernière fois il y a ${lastValueInvalidSinceYears} an(s)`,
129+
);
130+
}
131+
132+
const value =
133+
"values" in json
134+
? getLatestValue(json.values)
135+
: json.brackets
136+
.filter((bracket) =>
137+
Object.values(bracket).some(
138+
(value) => getLatestValue(value) != null,
139+
),
140+
)
141+
.map((bracket) =>
142+
Object.entries(bracket).reduce<Record<string, LeafValue>>(
143+
(acc, [key, value]) =>
144+
Object.assign(acc, {
145+
[key]: getLatestValue(value),
146+
}),
147+
{},
148+
),
149+
);
150+
151+
if (
152+
(Array.isArray(value) && value.some((value) => value == null)) ||
153+
value == null
154+
) {
155+
warnings.push(
156+
`⚠️ ${regle} a produit des valeurs vides qui suggèrent qu'elle n'est plus applicable`,
122157
);
123158
}
124159

125160
set(output, regle.split("/").join("."), {
126161
url: fileUrl,
127162
description: json.description,
128-
value:
129-
"values" in json
130-
? getLatestValue(json.values)
131-
: json.brackets
132-
.filter((bracket) =>
133-
Object.values(bracket).some(
134-
(value) => getLatestValue(value) != null,
135-
),
136-
)
137-
.map((bracket) =>
138-
Object.entries(bracket).reduce(
139-
(acc, [key, value]) =>
140-
Object.assign(acc, {
141-
[key]: getLatestValue(value),
142-
}),
143-
{},
144-
),
145-
),
163+
value: value,
146164
});
147165

148166
await new Promise((resolve) => setTimeout(resolve, 100));
@@ -186,11 +204,11 @@ function stringify(parent: Branch): string {
186204
`* {@link ${child.url} Source}`,
187205
`*/`,
188206
`${key}: ${
189-
typeof child.value === "number"
207+
child.value == null || typeof child.value === "number"
190208
? `${child.value},`
191209
: [
192210
`[`,
193-
...child.value!.flatMap((value) => [
211+
...child.value.flatMap((value) => [
194212
`{`,
195213
...Object.entries(value).map(
196214
([key, value]) => `${key}: ${value},`,

packages/donnees-reglementaires/src/index.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,4 +341,31 @@ export default {
341341
taux_reduit: 0.15,
342342
},
343343
},
344+
taxation_indirecte: {
345+
tva: {
346+
/**
347+
* @description Taux réduit de la taxe sur la valeur ajoutée (TVA)
348+
* {@link https://raw.githubusercontent.com/openfisca/openfisca-france/refs/heads/master/openfisca_france/parameters/taxation_indirecte/tva/taux_reduit.yaml Source}
349+
*/
350+
taux_reduit: 0.055,
351+
352+
/**
353+
* @description Taux intermédiaire de la taxe sur la valeur ajoutée (TVA)
354+
* {@link https://raw.githubusercontent.com/openfisca/openfisca-france/refs/heads/master/openfisca_france/parameters/taxation_indirecte/tva/taux_intermediaire.yaml Source}
355+
*/
356+
taux_intermediaire: 0.1,
357+
358+
/**
359+
* @description Taux normal de la taxe sur la valeur ajoutée (TVA)
360+
* {@link https://raw.githubusercontent.com/openfisca/openfisca-france/refs/heads/master/openfisca_france/parameters/taxation_indirecte/tva/taux_normal.yaml Source}
361+
*/
362+
taux_normal: 0.2,
363+
364+
/**
365+
* @description Taux particulier ("super réduit") de la taxe sur la valeur ajoutée (TVA)
366+
* {@link https://raw.githubusercontent.com/openfisca/openfisca-france/refs/heads/master/openfisca_france/parameters/taxation_indirecte/tva/taux_particulier_super_reduit.yaml Source}
367+
*/
368+
taux_particulier_super_reduit: 0.021,
369+
},
370+
},
344371
} as const;

0 commit comments

Comments
 (0)