]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Fix: Allow negative monetary values with a current code (#6358)
authorTrenton H <797416+stumpylog@users.noreply.github.com>
Wed, 10 Apr 2024 14:33:13 +0000 (07:33 -0700)
committerGitHub <noreply@github.com>
Wed, 10 Apr 2024 14:33:13 +0000 (07:33 -0700)
* Updates the currency validation to allow an optional negative

* Update frontend regex

---------

Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
src-ui/src/app/components/common/input/monetary/monetary.component.ts
src/documents/serialisers.py

index ebfd9b6bf7c6eed315d13a8dbf74494301b5477e..6c17b2c7693f982374d274b5e5df328bc8b81b1e 100644 (file)
@@ -51,7 +51,7 @@ export class MonetaryComponent extends AbstractInputComponent<string> {
   get monetaryValue(): string {
     if (!this.value) return null
     const focused = document.activeElement === this.inputField?.nativeElement
-    const val = parseFloat(this.value.toString().replace(/[^0-9.,]+/g, ''))
+    const val = parseFloat(this.value.toString().replace(/[^0-9.,-]+/g, ''))
     return focused ? val.toString() : val.toFixed(2)
   }
 
index f8537726f85aeac306fc42da81ddbbbb79b58729..26930ccec5a86afe3fee6dad9b23e1422270fd71 100644 (file)
@@ -546,7 +546,7 @@ class CustomFieldInstanceSerializer(serializers.ModelSerializer):
                 except Exception:
                     # If that fails, try to validate as a monetary string
                     RegexValidator(
-                        regex=r"^[A-Z][A-Z][A-Z]\d+(\.\d{2,2})$",
+                        regex=r"^[A-Z]{3}-?\d+(\.\d{2,2})$",
                         message="Must be a two-decimal number with optional currency code e.g. GBP123.45",
                     )(data["value"])
             elif field.data_type == CustomField.FieldDataType.STRING: