diff --git a/modele-social/règles/dirigeant.yaml b/modele-social/règles/dirigeant.yaml index 1d463c755..fd9acc9c2 100644 --- a/modele-social/règles/dirigeant.yaml +++ b/modele-social/règles/dirigeant.yaml @@ -942,6 +942,7 @@ dirigeant . indépendant . cotisations et contributions . début activité: règle: cotisations et contributions avec: assiette des cotisations: assiette forfaitaire + situation personnelle . RSA: non références: Fiche Urssaf: https://www.urssaf.fr/portail/home/independant/mes-cotisations/les-etapes-de-calcul/le-mode-de-calcul/lajustement-et-la-regularisation.html diff --git a/publicodes/core/source/mecanisms/recalcul.ts b/publicodes/core/source/mecanisms/recalcul.ts index 3b7ce082e..f24f2aec8 100644 --- a/publicodes/core/source/mecanisms/recalcul.ts +++ b/publicodes/core/source/mecanisms/recalcul.ts @@ -31,35 +31,24 @@ const evaluateRecalcul: EvaluationFunction<'recalcul'> = function (node) { serializeUnit(originRule.unit) !== serializeUnit(replacement.unit) ) as Array<[ReferenceNode & EvaluatedNode, EvaluatedNode]> - const originalCache = this.cache - const originalSituation = this.parsedSituation - // Optimisation : no need for recalcul if situation is the same - const invalidateCache = Object.keys(amendedSituation).length > 0 - if (invalidateCache) { - this.resetCache() - this.cache._meta.inRecalcul = true - } - - this.parsedSituation = { - ...this.parsedSituation, - ...Object.fromEntries( - amendedSituation.map(([reference, replacement]) => [ - disambiguateRuleReference( - this.parsedRules, - reference.contextDottedName, - reference.name + const engine = amendedSituation.length + ? this.shallowCopy().setSituation({ + ...this.parsedSituation, + ...Object.fromEntries( + amendedSituation.map(([reference, replacement]) => [ + disambiguateRuleReference( + this.parsedRules, + reference.contextDottedName, + reference.name + ), + replacement, + ]) as any ), - replacement, - ]) as any - ), - } - - const evaluatedNode = this.evaluate(node.explanation.recalcul) - - this.parsedSituation = originalSituation - if (invalidateCache) { - this.cache = originalCache - } + }) + : this + engine.cache._meta.inRecalcul = true + const evaluatedNode = engine.evaluate(node.explanation.recalcul) + engine.cache._meta.inRecalcul = false return { ...node,