mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-17 10:13:56 -05:00
Fix: make backend monetary validation accept unpadded decimals (#6626)
This commit is contained in:
parent
caec0ed4d1
commit
6ea25a96a3
@ -17,7 +17,15 @@ import { getLocaleCurrencyCode } from '@angular/common'
|
|||||||
})
|
})
|
||||||
export class MonetaryComponent extends AbstractInputComponent<string> {
|
export class MonetaryComponent extends AbstractInputComponent<string> {
|
||||||
public currency: 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
|
defaultCurrencyCode: string
|
||||||
|
|
||||||
constructor(@Inject(LOCALE_ID) currentLocale: string) {
|
constructor(@Inject(LOCALE_ID) currentLocale: string) {
|
||||||
|
@ -547,7 +547,7 @@ class CustomFieldInstanceSerializer(serializers.ModelSerializer):
|
|||||||
except Exception:
|
except Exception:
|
||||||
# If that fails, try to validate as a monetary string
|
# If that fails, try to validate as a monetary string
|
||||||
RegexValidator(
|
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",
|
message="Must be a two-decimal number with optional currency code e.g. GBP123.45",
|
||||||
)(data["value"])
|
)(data["value"])
|
||||||
elif field.data_type == CustomField.FieldDataType.STRING:
|
elif field.data_type == CustomField.FieldDataType.STRING:
|
||||||
|
@ -499,22 +499,6 @@ class TestCustomFieldsAPI(DirectoriesMixin, APITestCase):
|
|||||||
|
|
||||||
self.assertEqual(resp.status_code, status.HTTP_400_BAD_REQUEST)
|
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(
|
resp = self.client.patch(
|
||||||
f"/api/documents/{doc.id}/",
|
f"/api/documents/{doc.id}/",
|
||||||
data={
|
data={
|
||||||
|
Loading…
x
Reference in New Issue
Block a user