From c6778416d34c9e458d6e10c8b0974d24a9832e1d Mon Sep 17 00:00:00 2001 From: Jack Anderson Date: Thu, 26 Sep 2024 11:04:37 +0100 Subject: [PATCH] Fix #478 - Add from format check on toUserFormat --- .../field-logic/update-value/update-value.action.ts | 3 ++- .../currency/currency-formatter.service.ts | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/core/app/core/src/lib/fields/field-logic/update-value/update-value.action.ts b/core/app/core/src/lib/fields/field-logic/update-value/update-value.action.ts index d72e9286d..a50a51084 100644 --- a/core/app/core/src/lib/fields/field-logic/update-value/update-value.action.ts +++ b/core/app/core/src/lib/fields/field-logic/update-value/update-value.action.ts @@ -81,7 +81,8 @@ export class UpdateValueAction extends FieldLogicActionHandler { if (this.isCurrencyField(field)) { const options = { - mode: 'edit' as ViewMode + mode: 'edit' as ViewMode, + fromFormat: 'system' } value = this.currencyFormatter.toUserFormat(value, options); } diff --git a/core/app/core/src/lib/services/formatters/currency/currency-formatter.service.ts b/core/app/core/src/lib/services/formatters/currency/currency-formatter.service.ts index d34f17789..38f9e4588 100644 --- a/core/app/core/src/lib/services/formatters/currency/currency-formatter.service.ts +++ b/core/app/core/src/lib/services/formatters/currency/currency-formatter.service.ts @@ -29,7 +29,8 @@ import {UserPreferenceStore} from '../../../store/user-preference/user-preferenc import {formatCurrency, formatNumber} from '@angular/common'; import {NumberFormatter} from '../number/number-formatter.service'; import {FormatOptions, Formatter} from '../formatter.model'; -import {isVoid} from '../../../common/utils/value-utils'; +import {isVoid} from 'common'; +import {SystemConfigStore} from "../../../store/system-config/system-config.store"; export interface CurrencyFormat { iso4217: string; @@ -44,6 +45,7 @@ export class CurrencyFormatter implements Formatter { constructor( protected preferences: UserPreferenceStore, + protected configs: SystemConfigStore, protected numberFormatter: NumberFormatter, @Inject(LOCALE_ID) public locale: string ) { @@ -57,6 +59,7 @@ export class CurrencyFormatter implements Formatter { const symbol = (options && options.symbol) || this.getSymbol(); const code = (options && options.code) || this.getCode(); + const defaultGroup = this.configs.getConfigValue('default_number_grouping_seperator'); let digits = null; if (options && options.digits !== null && isFinite(options.digits)) { digits = options.digits; @@ -64,7 +67,12 @@ export class CurrencyFormatter implements Formatter { const digitsInfo = this.getDigitsInfo(digits); let formatted: string; - value = this.replaceSeparatorsToInternalFormat(value); + + if (options?.fromFormat === 'system' && value.includes(defaultGroup)){ + value = value.replace(defaultGroup, ''); + } else { + value = this.replaceSeparatorsToInternalFormat(value); + } if (options && options.mode === 'edit') { formatted = formatNumber(Number(value), this.locale, digitsInfo);