From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Sun, 21 Apr 2024 04:44:31 +0000 (-0700) Subject: Fix: monetary field with null values X-Git-Tag: v2.8.0~3^2~26 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d002ae2e059d17ccf0b5692e7cc4b68c249e926c;p=thirdparty%2Fpaperless-ngx.git Fix: monetary field with null values --- diff --git a/src-ui/src/app/components/common/input/monetary/monetary.component.spec.ts b/src-ui/src/app/components/common/input/monetary/monetary.component.spec.ts index 60df717424..f22a3f53d2 100644 --- a/src-ui/src/app/components/common/input/monetary/monetary.component.spec.ts +++ b/src-ui/src/app/components/common/input/monetary/monetary.component.spec.ts @@ -46,4 +46,32 @@ describe('MonetaryComponent', () => { component = new MonetaryComponent('pt-BR') expect(component.defaultCurrencyCode).toEqual('BRL') }) + + it('should parse monetary value correctly', () => { + expect(component['parseMonetaryValue']('123.4')).toEqual('123.4') + expect(component['parseMonetaryValue']('123.4', true)).toEqual('123.40') + expect(component['parseMonetaryValue']('123.4', false)).toEqual('123.4') + }) + + it('should handle currency change', () => { + component.writeValue('USD123.4') + component.currency = 'EUR' + component.currencyChange() + expect(component.currency).toEqual('EUR') + expect(component.monetaryValue).toEqual('123.40') + }) + + it('should handle monetary value change', () => { + component.writeValue('USD123.4') + component.monetaryValue = '123.4' + component.monetaryValueChange() + expect(component.monetaryValue).toEqual('123.4') + expect(component.value).toEqual('USD123.40') + }) + + it('should handle null values', () => { + component.writeValue(null) + expect(component.currency).toEqual('USD') + expect(component.monetaryValue).toEqual('') + }) }) diff --git a/src-ui/src/app/components/common/input/monetary/monetary.component.ts b/src-ui/src/app/components/common/input/monetary/monetary.component.ts index edaad3859e..4ed32e7a15 100644 --- a/src-ui/src/app/components/common/input/monetary/monetary.component.ts +++ b/src-ui/src/app/components/common/input/monetary/monetary.component.ts @@ -56,6 +56,9 @@ export class MonetaryComponent extends AbstractInputComponent { } private parseMonetaryValue(value: string, fixed: boolean = false): string { + if (!value) { + return '' + } const val: number = parseFloat(value.toString().replace(/[^0-9.,-]+/g, '')) return fixed ? val.toFixed(2) : val.toString() }