⚙️ Utilise engine.shallowCopy dans recalcul

pull/1504/head
Johan Girod 2021-05-04 16:47:44 +02:00
parent 2e972fca44
commit f9fb6fc4b6
2 changed files with 18 additions and 28 deletions

View File

@ -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

View File

@ -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,