Fix #478 - Add from format check on toUserFormat

This commit is contained in:
Jack Anderson 2024-09-26 11:04:37 +01:00 committed by y.yerli
parent 464830fd9d
commit c6778416d3
2 changed files with 12 additions and 3 deletions

View file

@ -81,7 +81,8 @@ export class UpdateValueAction extends FieldLogicActionHandler {
if (this.isCurrencyField(field)) { if (this.isCurrencyField(field)) {
const options = { const options = {
mode: 'edit' as ViewMode mode: 'edit' as ViewMode,
fromFormat: 'system'
} }
value = this.currencyFormatter.toUserFormat(value, options); value = this.currencyFormatter.toUserFormat(value, options);
} }

View file

@ -29,7 +29,8 @@ import {UserPreferenceStore} from '../../../store/user-preference/user-preferenc
import {formatCurrency, formatNumber} from '@angular/common'; import {formatCurrency, formatNumber} from '@angular/common';
import {NumberFormatter} from '../number/number-formatter.service'; import {NumberFormatter} from '../number/number-formatter.service';
import {FormatOptions, Formatter} from '../formatter.model'; 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 { export interface CurrencyFormat {
iso4217: string; iso4217: string;
@ -44,6 +45,7 @@ export class CurrencyFormatter implements Formatter {
constructor( constructor(
protected preferences: UserPreferenceStore, protected preferences: UserPreferenceStore,
protected configs: SystemConfigStore,
protected numberFormatter: NumberFormatter, protected numberFormatter: NumberFormatter,
@Inject(LOCALE_ID) public locale: string @Inject(LOCALE_ID) public locale: string
) { ) {
@ -57,6 +59,7 @@ export class CurrencyFormatter implements Formatter {
const symbol = (options && options.symbol) || this.getSymbol(); const symbol = (options && options.symbol) || this.getSymbol();
const code = (options && options.code) || this.getCode(); const code = (options && options.code) || this.getCode();
const defaultGroup = this.configs.getConfigValue('default_number_grouping_seperator');
let digits = null; let digits = null;
if (options && options.digits !== null && isFinite(options.digits)) { if (options && options.digits !== null && isFinite(options.digits)) {
digits = options.digits; digits = options.digits;
@ -64,7 +67,12 @@ export class CurrencyFormatter implements Formatter {
const digitsInfo = this.getDigitsInfo(digits); const digitsInfo = this.getDigitsInfo(digits);
let formatted: string; 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') { if (options && options.mode === 'edit') {
formatted = formatNumber(Number(value), this.locale, digitsInfo); formatted = formatNumber(Number(value), this.locale, digitsInfo);