mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-07-30 15:45:58 +00:00
Fix: normalize monetary decimal symbol by locale
This commit is contained in:
+5
@@ -68,6 +68,11 @@
|
||||
></ng-select>
|
||||
} @else if (getCustomFieldByID(atom.field)?.data_type === CustomFieldDataType.DocumentLink) {
|
||||
<pngx-input-document-link [(ngModel)]="atom.value" class="w-25 form-select doc-link-select p-0" placeholder="Search docs..." i18n-placeholder [minimal]="true"></pngx-input-document-link>
|
||||
} @else if (getCustomFieldByID(atom.field)?.data_type === CustomFieldDataType.Monetary) {
|
||||
<input class="w-25 form-control rounded-end" type="text" inputmode="decimal"
|
||||
[ngModel]="atom.value"
|
||||
(ngModelChange)="setMonetaryValue(atom, $event)"
|
||||
[disabled]="disabled">
|
||||
} @else {
|
||||
<input class="w-25 form-control rounded-end" type="text" [(ngModel)]="atom.value" [disabled]="disabled">
|
||||
}
|
||||
|
||||
+24
@@ -1,5 +1,6 @@
|
||||
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'
|
||||
import { provideHttpClientTesting } from '@angular/common/http/testing'
|
||||
import { LOCALE_ID } from '@angular/core'
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing'
|
||||
import { FormsModule, ReactiveFormsModule } from '@angular/forms'
|
||||
import { NgbDropdownModule } from '@ng-bootstrap/ng-bootstrap'
|
||||
@@ -41,6 +42,12 @@ const customFields = [
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
name: 'Test Monetary Field',
|
||||
data_type: CustomFieldDataType.Monetary,
|
||||
extra_data: { default_currency: 'EUR' },
|
||||
},
|
||||
]
|
||||
|
||||
describe('CustomFieldsQueryDropdownComponent', () => {
|
||||
@@ -61,6 +68,7 @@ describe('CustomFieldsQueryDropdownComponent', () => {
|
||||
providers: [
|
||||
provideHttpClient(withInterceptorsFromDi()),
|
||||
provideHttpClientTesting(),
|
||||
{ provide: LOCALE_ID, useValue: 'de' },
|
||||
],
|
||||
}).compileComponents()
|
||||
|
||||
@@ -150,6 +158,22 @@ describe('CustomFieldsQueryDropdownComponent', () => {
|
||||
expect(options2).toEqual([])
|
||||
})
|
||||
|
||||
it('should normalize localized monetary comparison values', () => {
|
||||
const atom = new CustomFieldQueryAtom([3, 'exact', null])
|
||||
|
||||
component.setMonetaryComparisonValue(atom, '1.234,56')
|
||||
|
||||
expect(atom.value).toEqual('1234.56')
|
||||
})
|
||||
|
||||
it('should preserve API-formatted monetary comparison values', () => {
|
||||
const atom = new CustomFieldQueryAtom([3, 'exact', null])
|
||||
|
||||
component.setMonetaryComparisonValue(atom, '1234.56')
|
||||
|
||||
expect(atom.value).toEqual('1234.56')
|
||||
})
|
||||
|
||||
it('should remove an element from the selection model', () => {
|
||||
const expression = new CustomFieldQueryExpression()
|
||||
const atom = new CustomFieldQueryAtom()
|
||||
|
||||
+21
-1
@@ -1,9 +1,14 @@
|
||||
import { NgTemplateOutlet } from '@angular/common'
|
||||
import {
|
||||
getLocaleNumberSymbol,
|
||||
NgTemplateOutlet,
|
||||
NumberSymbol,
|
||||
} from '@angular/common'
|
||||
import {
|
||||
Component,
|
||||
EventEmitter,
|
||||
inject,
|
||||
Input,
|
||||
LOCALE_ID,
|
||||
Output,
|
||||
QueryList,
|
||||
signal,
|
||||
@@ -212,6 +217,7 @@ export class CustomFieldQueriesModel {
|
||||
})
|
||||
export class CustomFieldsQueryDropdownComponent extends LoadingComponentWithPermissions {
|
||||
protected customFieldsService = inject(CustomFieldsService)
|
||||
private locale = inject(LOCALE_ID)
|
||||
|
||||
public CustomFieldQueryComponentType = CustomFieldQueryElementType
|
||||
public CustomFieldQueryOperator = CustomFieldQueryOperator
|
||||
@@ -376,4 +382,18 @@ export class CustomFieldsQueryDropdownComponent extends LoadingComponentWithPerm
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
setMonetaryValue(atom: CustomFieldQueryAtom, value: string) {
|
||||
// Normalize the decimal symbol e.g. . vs , by locale
|
||||
const decimalSymbol = getLocaleNumberSymbol(
|
||||
this.locale,
|
||||
NumberSymbol.Decimal
|
||||
)
|
||||
if (decimalSymbol !== '.' && value.includes(decimalSymbol)) {
|
||||
const groupSymbol = getLocaleNumberSymbol(this.locale, NumberSymbol.Group)
|
||||
value = value.split(groupSymbol).join('').split(decimalSymbol).join('.')
|
||||
}
|
||||
|
||||
atom.value = value
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user