diff --git a/source/engine/treat.js b/source/engine/treat.js index f47ff05ce..c575757bf 100644 --- a/source/engine/treat.js +++ b/source/engine/treat.js @@ -27,7 +27,8 @@ import { Node } from './mecanismViews/common' import { treatVariable, treatNegatedVariable, - treatFilteredVariable + treatFilteredVariable, + treatPeriodTransform } from './treatVariable' import { treat } from './traverse' import knownMecanisms from './known-mecanisms.yaml' @@ -90,9 +91,13 @@ export let treatString = (rules, rule) => rawNode => { ) if (parseResult.category == 'variable') - return treatVariable(rules, rule)(parseResult) + return treatPeriodTransform(rules, rule)( + treatVariable(rules, rule)(parseResult) + ) if (parseResult.category == 'filteredVariable') - return treatFilteredVariable(rules, rule) + return treatPeriodTransform(rules, rule)( + treatFilteredVariable(rules, rule)(parseResult) + ) if (parseResult.category == 'negatedVariable') return treatNegatedVariable( treatVariable(rules, rule)(parseResult.variable) @@ -154,10 +159,19 @@ export let treatString = (rules, rule) => rawNode => { let explanation = parseResult.explanation.map( cond([ - [propEq('category', 'variable'), treatVariable(rules, rule)], + [ + propEq('category', 'variable'), + parseResult => + treatPeriodTransform(rules, rule)( + treatVariable(rules, rule)(parseResult) + ) + ], [ propEq('category', 'filteredVariable'), - treatFilteredVariable(rules, rule) + parseResult => + treatPeriodTransform(rules, rule)( + treatFilteredVariable(rules, rule)(parseResult) + ) ], [ propEq('category', 'value'), diff --git a/source/engine/treatVariable.js b/source/engine/treatVariable.js index 5bb09ecb8..0022b8162 100644 --- a/source/engine/treatVariable.js +++ b/source/engine/treatVariable.js @@ -5,8 +5,9 @@ import { evaluateNode, rewriteNode, makeJsx } from './evaluation' import { getSituationValue } from './variables' import { Trans } from 'react-i18next' -export let treatVariable = (rules, rule, filter) => parseResult => { - let variable = treatVariableTimeless(rules, rule, filter)(parseResult) +// This function is a wrapper that can apply temporal transformations to the value of the variable. +// See the période.yaml test suite for details +export let treatPeriodTransform = (rules, rule) => variable => { let evaluate = (cache, situation, parsedRules, node) => { let explanation = evaluateNode( cache, @@ -55,7 +56,7 @@ export let treatVariable = (rules, rule, filter) => parseResult => { } } -export let treatVariableTimeless = (rules, rule, filter) => parseResult => { +export let treatVariable = (rules, rule, filter) => parseResult => { let evaluate = (cache, situation, parsedRules, node) => { let dottedName = node.dottedName, // On va vérifier dans le cache courant, dict, si la variable n'a pas été déjà évaluée diff --git a/source/selectors/ficheDePaieSelectors.js b/source/selectors/ficheDePaieSelectors.js index a50a44f75..452108fc6 100644 --- a/source/selectors/ficheDePaieSelectors.js +++ b/source/selectors/ficheDePaieSelectors.js @@ -123,8 +123,11 @@ const analysisToCotisations = ( 'contrat salarié . cotisations patronales' ] .map(name => analysis.cache[name]) + // the last 'explanation' is because variables are wrapped in a period transform node .map(pathOr([], ['explanation', 'formule', 'explanation', 'explanation'])) .reduce(concat, []) + .map(prop('explanation')) + const cotisations = pipe( groupBy(prop('dottedName')), values,