Merge pull request #592 from dod-ccpo/clin-decimals-fixes
CLIN Input field bugfixes
This commit is contained in:
commit
f67f5d15a4
@ -12,14 +12,6 @@ def iconSvg(name):
|
|||||||
|
|
||||||
|
|
||||||
def dollars(value):
|
def dollars(value):
|
||||||
try:
|
|
||||||
numberValue = float(value)
|
|
||||||
except ValueError:
|
|
||||||
numberValue = 0
|
|
||||||
return "${:,.0f}".format(numberValue)
|
|
||||||
|
|
||||||
|
|
||||||
def dollarsWithCents(value):
|
|
||||||
try:
|
try:
|
||||||
numberValue = float(value)
|
numberValue = float(value)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
@ -107,7 +99,6 @@ def normalizeOrder(title):
|
|||||||
def register_filters(app):
|
def register_filters(app):
|
||||||
app.jinja_env.filters["iconSvg"] = iconSvg
|
app.jinja_env.filters["iconSvg"] = iconSvg
|
||||||
app.jinja_env.filters["dollars"] = dollars
|
app.jinja_env.filters["dollars"] = dollars
|
||||||
app.jinja_env.filters["dollarsWithCents"] = dollarsWithCents
|
|
||||||
app.jinja_env.filters["usPhone"] = usPhone
|
app.jinja_env.filters["usPhone"] = usPhone
|
||||||
app.jinja_env.filters["readableInteger"] = readableInteger
|
app.jinja_env.filters["readableInteger"] = readableInteger
|
||||||
app.jinja_env.filters["getOptionLabel"] = getOptionLabel
|
app.jinja_env.filters["getOptionLabel"] = getOptionLabel
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import MaskedInput, { conformToMask } from 'vue-text-mask'
|
import MaskedInput, { conformToMask } from 'vue-text-mask'
|
||||||
import inputValidations from '../lib/input_validations'
|
import inputValidations from '../lib/input_validations'
|
||||||
|
import { formatDollars } from '../lib/dollars'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'textinput',
|
name: 'textinput',
|
||||||
@ -78,6 +79,9 @@ export default {
|
|||||||
onChange: function(e) {
|
onChange: function(e) {
|
||||||
// Only invalidate the field when it blurs
|
// Only invalidate the field when it blurs
|
||||||
this._checkIfValid({ value: e.target.value, invalidate: true })
|
this._checkIfValid({ value: e.target.value, invalidate: true })
|
||||||
|
if (this.validation === 'dollars') {
|
||||||
|
this.value = formatDollars(this._rawValue(e.target.value))
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -1,8 +1,14 @@
|
|||||||
export const formatDollars = (value, cents = true) => {
|
export const formatDollars = (value, cents = true) => {
|
||||||
if (typeof value === 'number') {
|
if (typeof value === 'number') {
|
||||||
return cents
|
return value.toLocaleString('us-US', {
|
||||||
? `$${value.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,')}`
|
style: 'currency',
|
||||||
: `$${value.toFixed(0).replace(/\d(?=(\d{3})+(?!\d))/g, '$&,')}`
|
currency: 'USD',
|
||||||
|
})
|
||||||
|
} else if (typeof value === 'string') {
|
||||||
|
return parseFloat(value).toLocaleString('us-US', {
|
||||||
|
style: 'currency',
|
||||||
|
currency: 'USD',
|
||||||
|
})
|
||||||
}
|
}
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
|
@ -154,7 +154,7 @@
|
|||||||
<td><h4>{{ "task_orders.new.review.to_value"| translate }}</h4></td>
|
<td><h4>{{ "task_orders.new.review.to_value"| translate }}</h4></td>
|
||||||
<td class="table-cell--align-right">
|
<td class="table-cell--align-right">
|
||||||
{% if task_order.budget %}
|
{% if task_order.budget %}
|
||||||
{{ task_order.budget | dollarsWithCents }}
|
{{ task_order.budget | dollars }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@ -162,7 +162,7 @@
|
|||||||
<td><h4 class='task-order-form__heading funding-summary__td'>{{ "task_orders.new.review.clin_1"| translate }}</h4></td>
|
<td><h4 class='task-order-form__heading funding-summary__td'>{{ "task_orders.new.review.clin_1"| translate }}</h4></td>
|
||||||
<td class="table-cell--align-right">
|
<td class="table-cell--align-right">
|
||||||
{% if task_order.clin_01 %}
|
{% if task_order.clin_01 %}
|
||||||
{{ task_order.clin_01 | dollarsWithCents }}
|
{{ task_order.clin_01 | dollars }}
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ RequiredLabel() }}
|
{{ RequiredLabel() }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@ -177,7 +177,7 @@
|
|||||||
</h4></td>
|
</h4></td>
|
||||||
<td class="table-cell--align-right">
|
<td class="table-cell--align-right">
|
||||||
{% if task_order.clin_02 and config.CLASSIFIED %}
|
{% if task_order.clin_02 and config.CLASSIFIED %}
|
||||||
{{ task_order.clin_02 | dollarsWithCents or RequiredLabel() }}
|
{{ task_order.clin_02 | dollars or RequiredLabel() }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@ -185,7 +185,7 @@
|
|||||||
<td><h4 class='task-order-form__heading funding-summary__td'>{{ "task_orders.new.review.clin_3"| translate }}</h4></td>
|
<td><h4 class='task-order-form__heading funding-summary__td'>{{ "task_orders.new.review.clin_3"| translate }}</h4></td>
|
||||||
<td class="table-cell--align-right">
|
<td class="table-cell--align-right">
|
||||||
{% if task_order.clin_03 %}
|
{% if task_order.clin_03 %}
|
||||||
{{ task_order.clin_03 | dollarsWithCents or RequiredLabel() }}
|
{{ task_order.clin_03 | dollars or RequiredLabel() }}
|
||||||
{% else %}
|
{% else %}
|
||||||
{{ RequiredLabel() }}
|
{{ RequiredLabel() }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@ -200,7 +200,7 @@
|
|||||||
</h4></td>
|
</h4></td>
|
||||||
<td class="table-cell--align-right">
|
<td class="table-cell--align-right">
|
||||||
{% if task_order.clin_04 and config.CLASSIFIED %}
|
{% if task_order.clin_04 and config.CLASSIFIED %}
|
||||||
{{ task_order.clin_04 | dollarsWithCents or RequiredLabel() }}
|
{{ task_order.clin_04 | dollars or RequiredLabel() }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -7,11 +7,11 @@ from atst.models import AuditEvent
|
|||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"input,expected",
|
"input,expected",
|
||||||
[
|
[
|
||||||
("0", "$0"),
|
("0", "$0.00"),
|
||||||
("123.00", "$123"),
|
("123.00", "$123.00"),
|
||||||
("1234567", "$1,234,567"),
|
("1234567", "$1,234,567.00"),
|
||||||
("-1234", "$-1,234"),
|
("-1234", "$-1,234.00"),
|
||||||
("one", "$0"),
|
("one", "$0.00"),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_dollar_fomatter(input, expected):
|
def test_dollar_fomatter(input, expected):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user