]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Fix: allow 0 in monetary field (#6658)
authorshamoon <4887959+shamoon@users.noreply.github.com>
Thu, 9 May 2024 17:43:27 +0000 (10:43 -0700)
committerGitHub <noreply@github.com>
Thu, 9 May 2024 17:43:27 +0000 (10:43 -0700)
src-ui/src/app/components/common/input/monetary/monetary.component.spec.ts
src-ui/src/app/components/common/input/monetary/monetary.component.ts

index f22a3f53d2961a40cc77b4b1296282865e0bde28..30b78dde7b19a96f8b3ce30b2fc7d38eaff310b7 100644 (file)
@@ -74,4 +74,13 @@ describe('MonetaryComponent', () => {
     expect(component.currency).toEqual('USD')
     expect(component.monetaryValue).toEqual('')
   })
+
+  it('should handle zero values', () => {
+    component.writeValue('USD0.00')
+    expect(component.currency).toEqual('USD')
+    expect(component.monetaryValue).toEqual('0.00')
+    component.monetaryValue = '0'
+    component.monetaryValueChange()
+    expect(component.value).toEqual('USD0.00')
+  })
 })
index 56f0dd28e7e8cb8c2e6df541908e11b7f8ee9712..256dc8c18ffc2933ed86487c13c15c634876bd03 100644 (file)
@@ -22,8 +22,9 @@ export class MonetaryComponent extends AbstractInputComponent<string> {
   public get monetaryValue(): string {
     return this._monetaryValue
   }
-  public set monetaryValue(value: string) {
-    if (value) this._monetaryValue = value
+  public set monetaryValue(value: any) {
+    if (value || value?.toString() === '0')
+      this._monetaryValue = value.toString()
   }
 
   defaultCurrencyCode: string
@@ -44,6 +45,9 @@ export class MonetaryComponent extends AbstractInputComponent<string> {
 
   public monetaryValueChange(fixed: boolean = false): void {
     this.monetaryValue = this.parseMonetaryValue(this.monetaryValue, fixed)
+    if (this.monetaryValue === '0') {
+      this.monetaryValue = '0.00'
+    }
     this.onChange(this.currency + this.monetaryValue)
   }