Enhancement: allow specifying default currency for Monetary custom field (#7381)

This commit is contained in:
shamoon
2024-08-05 17:02:03 -07:00
committed by GitHub
parent 0ee85aae21
commit 15554322dd
13 changed files with 168 additions and 29 deletions

View File

@@ -20,6 +20,12 @@ const customFields: CustomField[] = [
select_options: ['Option 1', 'Option 2', 'Option 3'],
},
},
{
id: 5,
name: 'Field 5',
data_type: CustomFieldDataType.Monetary,
extra_data: { default_currency: 'JPY' },
},
]
const document: Document = {
id: 1,
@@ -112,6 +118,18 @@ describe('CustomFieldDisplayComponent', () => {
expect(component.value).toEqual(100)
})
it('should respect explicit default currency', () => {
component['defaultCurrencyCode'] = 'EUR' // mock default locale injection
component.fieldId = 5
component.document = {
id: 1,
title: 'Doc 1',
custom_fields: [{ field: 5, document: 1, created: null, value: '100' }],
}
expect(component.currency).toEqual('JPY')
expect(component.value).toEqual(100)
})
it('should show select value', () => {
expect(component.getSelectValue(customFields[3], 2)).toEqual('Option 3')
})

View File

@@ -90,7 +90,9 @@ export class CustomFieldDisplayComponent implements OnInit, OnDestroy {
)?.value
if (this.value && this.field.data_type === CustomFieldDataType.Monetary) {
this.currency =
this.value.match(/([A-Z]{3})/)?.[0] ?? this.defaultCurrencyCode
this.value.match(/([A-Z]{3})/)?.[0] ??
this.field.extra_data?.default_currency ??
this.defaultCurrencyCode
this.value = parseFloat(this.value.replace(this.currency, ''))
} else if (
this.value?.length &&