]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Fix: make backend monetary validation accept unpadded decimals (#6626)
authorshamoon <4887959+shamoon@users.noreply.github.com>
Tue, 7 May 2024 21:38:52 +0000 (14:38 -0700)
committerGitHub <noreply@github.com>
Tue, 7 May 2024 21:38:52 +0000 (21:38 +0000)
src-ui/src/app/components/common/input/monetary/monetary.component.ts
src/documents/serialisers.py
src/documents/tests/test_api_custom_fields.py

index 4ed32e7a15a19723c82d3e93adbdec642df19d41..56f0dd28e7e8cb8c2e6df541908e11b7f8ee9712 100644 (file)
@@ -17,7 +17,15 @@ import { getLocaleCurrencyCode } from '@angular/common'
 })
 export class MonetaryComponent extends AbstractInputComponent<string> {
   public currency: string = ''
-  public monetaryValue: string = ''
+
+  public _monetaryValue: string = ''
+  public get monetaryValue(): string {
+    return this._monetaryValue
+  }
+  public set monetaryValue(value: string) {
+    if (value) this._monetaryValue = value
+  }
+
   defaultCurrencyCode: string
 
   constructor(@Inject(LOCALE_ID) currentLocale: string) {
index b3eace7c9c8ec1c488c83ef30e228ea4e88307ab..213e3cc27400dc0c5a552bae2c14196d7da754e8 100644 (file)
@@ -547,7 +547,7 @@ class CustomFieldInstanceSerializer(serializers.ModelSerializer):
                 except Exception:
                     # If that fails, try to validate as a monetary string
                     RegexValidator(
-                        regex=r"^[A-Z]{3}-?\d+(\.\d{2,2})$",
+                        regex=r"^[A-Z]{3}-?\d+(\.\d{1,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:
index 2885d9071706afb4e32a0fe5ae22c9592f83877d..0b2f99b35df22763348d1233475419fe968b1863 100644 (file)
@@ -499,22 +499,6 @@ class TestCustomFieldsAPI(DirectoriesMixin, APITestCase):
 
         self.assertEqual(resp.status_code, status.HTTP_400_BAD_REQUEST)
 
-        resp = self.client.patch(
-            f"/api/documents/{doc.id}/",
-            data={
-                "custom_fields": [
-                    {
-                        "field": custom_field_money.id,
-                        # Too few places past decimal
-                        "value": "GBP12.1",
-                    },
-                ],
-            },
-            format="json",
-        )
-
-        self.assertEqual(resp.status_code, status.HTTP_400_BAD_REQUEST)
-
         resp = self.client.patch(
             f"/api/documents/{doc.id}/",
             data={