mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-15 10:13:15 -05:00
Fix: consistent monetary field display in list and cards (#6645)
This commit is contained in:
parent
e1f5edc0a1
commit
e7a5ebc64c
@ -17,7 +17,7 @@ const document: Document = {
|
|||||||
title: 'Doc 1',
|
title: 'Doc 1',
|
||||||
custom_fields: [
|
custom_fields: [
|
||||||
{ field: 1, document: 1, created: null, value: 'Text value' },
|
{ field: 1, document: 1, created: null, value: 'Text value' },
|
||||||
{ field: 2, document: 1, created: null, value: '100 USD' },
|
{ field: 2, document: 1, created: null, value: 'USD100' },
|
||||||
{ field: 3, document: 1, created: null, value: '1,2,3' },
|
{ field: 3, document: 1, created: null, value: '1,2,3' },
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
@ -86,4 +86,16 @@ describe('CustomFieldDisplayComponent', () => {
|
|||||||
expect(title2).toEqual('Document 2')
|
expect(title2).toEqual('Document 2')
|
||||||
expect(title3).toEqual('Document 3')
|
expect(title3).toEqual('Document 3')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should fallback to default currency', () => {
|
||||||
|
component['defaultCurrencyCode'] = 'EUR' // mock default locale injection
|
||||||
|
component.fieldId = 2
|
||||||
|
component.document = {
|
||||||
|
id: 1,
|
||||||
|
title: 'Doc 1',
|
||||||
|
custom_fields: [{ field: 2, document: 1, created: null, value: '100' }],
|
||||||
|
}
|
||||||
|
expect(component.currency).toEqual('EUR')
|
||||||
|
expect(component.value).toEqual(100)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@ -1,4 +1,12 @@
|
|||||||
import { Component, Input, OnDestroy, OnInit } from '@angular/core'
|
import { getLocaleCurrencyCode } from '@angular/common'
|
||||||
|
import {
|
||||||
|
Component,
|
||||||
|
Inject,
|
||||||
|
Input,
|
||||||
|
LOCALE_ID,
|
||||||
|
OnDestroy,
|
||||||
|
OnInit,
|
||||||
|
} from '@angular/core'
|
||||||
import { Subject, takeUntil } from 'rxjs'
|
import { Subject, takeUntil } from 'rxjs'
|
||||||
import { CustomField, CustomFieldDataType } from 'src/app/data/custom-field'
|
import { CustomField, CustomFieldDataType } from 'src/app/data/custom-field'
|
||||||
import { DisplayField, Document } from 'src/app/data/document'
|
import { DisplayField, Document } from 'src/app/data/document'
|
||||||
@ -54,11 +62,14 @@ export class CustomFieldDisplayComponent implements OnInit, OnDestroy {
|
|||||||
private docLinkDocuments: Document[] = []
|
private docLinkDocuments: Document[] = []
|
||||||
|
|
||||||
private unsubscribeNotifier: Subject<any> = new Subject()
|
private unsubscribeNotifier: Subject<any> = new Subject()
|
||||||
|
private defaultCurrencyCode: any
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private customFieldService: CustomFieldsService,
|
private customFieldService: CustomFieldsService,
|
||||||
private documentService: DocumentService
|
private documentService: DocumentService,
|
||||||
|
@Inject(LOCALE_ID) currentLocale: string
|
||||||
) {
|
) {
|
||||||
|
this.defaultCurrencyCode = getLocaleCurrencyCode(currentLocale)
|
||||||
this.customFieldService.listAll().subscribe((r) => {
|
this.customFieldService.listAll().subscribe((r) => {
|
||||||
this.customFields = r.results
|
this.customFields = r.results
|
||||||
this.init()
|
this.init()
|
||||||
@ -78,7 +89,8 @@ export class CustomFieldDisplayComponent implements OnInit, OnDestroy {
|
|||||||
(f) => f.field === this._fieldId
|
(f) => f.field === this._fieldId
|
||||||
)?.value
|
)?.value
|
||||||
if (this.value && this.field.data_type === CustomFieldDataType.Monetary) {
|
if (this.value && this.field.data_type === CustomFieldDataType.Monetary) {
|
||||||
this.currency = this.value.match(/([A-Z]{3})/)?.[0]
|
this.currency =
|
||||||
|
this.value.match(/([A-Z]{3})/)?.[0] ?? this.defaultCurrencyCode
|
||||||
this.value = parseFloat(this.value.replace(this.currency, ''))
|
this.value = parseFloat(this.value.replace(this.currency, ''))
|
||||||
} else if (
|
} else if (
|
||||||
this.value?.length &&
|
this.value?.length &&
|
||||||
|
Loading…
x
Reference in New Issue
Block a user