mirror of
https://github.com/actualbudget/actual.git
synced 2026-04-29 19:14:22 -05:00
fix HyperFormula custom functions and add FIXED formula (#6645)
* fix custom HyperFormula functions * add FIXED formula * note * [autofix.ci] apply automated fixes --------- Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
import * as dateFns from 'date-fns';
|
||||
import * as Handlebars from 'handlebars';
|
||||
import { HyperFormula } from 'hyperformula';
|
||||
import enUS from 'hyperformula/i18n/languages/enUS';
|
||||
|
||||
import { amountToInteger } from 'loot-core/shared/util';
|
||||
|
||||
@@ -10,9 +11,18 @@ import { currentDay, format, parseDate } from '../../shared/months';
|
||||
import { FIELD_TYPES } from '../../shared/rules';
|
||||
import { type TransactionForRules } from '../transactions/transaction-rules';
|
||||
|
||||
import { CustomFunctionsPlugin } from './customFunctions';
|
||||
import {
|
||||
CustomFunctionsPlugin,
|
||||
customFunctionsTranslations,
|
||||
} from './customFunctions';
|
||||
import { assert } from './rule-utils';
|
||||
|
||||
HyperFormula.registerLanguage('enUS', enUS);
|
||||
HyperFormula.registerFunctionPlugin(
|
||||
CustomFunctionsPlugin,
|
||||
customFunctionsTranslations,
|
||||
);
|
||||
|
||||
const ACTION_OPS = [
|
||||
'set',
|
||||
'set-split-amount',
|
||||
@@ -258,10 +268,9 @@ export class Action {
|
||||
}
|
||||
|
||||
try {
|
||||
HyperFormula.registerFunctionPlugin(CustomFunctionsPlugin);
|
||||
|
||||
hfInstance = HyperFormula.buildEmpty({
|
||||
licenseKey: 'gpl-v3',
|
||||
language: 'enUS',
|
||||
});
|
||||
|
||||
const sheetName = hfInstance.addSheet('Sheet1');
|
||||
|
||||
@@ -15,6 +15,17 @@ export class CustomFunctionsPlugin extends FunctionPlugin {
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
fixed(ast: ProcedureAst, state: InterpreterState) {
|
||||
return this.runFunction(
|
||||
ast.args,
|
||||
state,
|
||||
this.metadata('FIXED'),
|
||||
(number: number, decimals: number = 0) => {
|
||||
return Number(number).toFixed(decimals);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
CustomFunctionsPlugin.implementedFunctions = {
|
||||
@@ -29,4 +40,22 @@ CustomFunctionsPlugin.implementedFunctions = {
|
||||
},
|
||||
],
|
||||
},
|
||||
FIXED: {
|
||||
method: 'fixed',
|
||||
parameters: [
|
||||
{ argumentType: FunctionArgumentType.NUMBER },
|
||||
{
|
||||
argumentType: FunctionArgumentType.NUMBER,
|
||||
optionalArg: true,
|
||||
defaultValue: 0,
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
export const customFunctionsTranslations = {
|
||||
enUS: {
|
||||
INTEGER_TO_AMOUNT: 'INTEGER_TO_AMOUNT',
|
||||
FIXED: 'FIXED',
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user