mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-09 09:58:20 -05:00
Fix: monetary field with null values
This commit is contained in:
parent
bf430865b4
commit
d002ae2e05
@ -46,4 +46,32 @@ describe('MonetaryComponent', () => {
|
|||||||
component = new MonetaryComponent('pt-BR')
|
component = new MonetaryComponent('pt-BR')
|
||||||
expect(component.defaultCurrencyCode).toEqual('BRL')
|
expect(component.defaultCurrencyCode).toEqual('BRL')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should parse monetary value correctly', () => {
|
||||||
|
expect(component['parseMonetaryValue']('123.4')).toEqual('123.4')
|
||||||
|
expect(component['parseMonetaryValue']('123.4', true)).toEqual('123.40')
|
||||||
|
expect(component['parseMonetaryValue']('123.4', false)).toEqual('123.4')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should handle currency change', () => {
|
||||||
|
component.writeValue('USD123.4')
|
||||||
|
component.currency = 'EUR'
|
||||||
|
component.currencyChange()
|
||||||
|
expect(component.currency).toEqual('EUR')
|
||||||
|
expect(component.monetaryValue).toEqual('123.40')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should handle monetary value change', () => {
|
||||||
|
component.writeValue('USD123.4')
|
||||||
|
component.monetaryValue = '123.4'
|
||||||
|
component.monetaryValueChange()
|
||||||
|
expect(component.monetaryValue).toEqual('123.4')
|
||||||
|
expect(component.value).toEqual('USD123.40')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should handle null values', () => {
|
||||||
|
component.writeValue(null)
|
||||||
|
expect(component.currency).toEqual('USD')
|
||||||
|
expect(component.monetaryValue).toEqual('')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@ -56,6 +56,9 @@ export class MonetaryComponent extends AbstractInputComponent<string> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private parseMonetaryValue(value: string, fixed: boolean = false): string {
|
private parseMonetaryValue(value: string, fixed: boolean = false): string {
|
||||||
|
if (!value) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
const val: number = parseFloat(value.toString().replace(/[^0-9.,-]+/g, ''))
|
const val: number = parseFloat(value.toString().replace(/[^0-9.,-]+/g, ''))
|
||||||
return fixed ? val.toFixed(2) : val.toString()
|
return fixed ? val.toFixed(2) : val.toString()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user