fix: show formatted percent, currency & float in grid

This commit is contained in:
Shariq Ansari 2025-04-28 16:47:52 +05:30
parent 7ded0a0742
commit 5228755f7f
3 changed files with 35 additions and 1 deletions

View File

@ -185,6 +185,35 @@
:value="row[field.fieldname]"
@change="fieldChange($event.target.value, field, row)"
/>
<FormControl
v-else-if="field.fieldtype === 'Float'"
class="[&_input]:text-right"
type="text"
variant="outline"
:value="getFormattedFloat(field.fieldname, row)"
:disabled="Boolean(field.read_only)"
@change="row[field.fieldname] = flt($event.target.value)"
/>
<FormControl
v-else-if="field.fieldtype === 'Percent'"
class="[&_input]:text-right"
type="text"
variant="outline"
:value="getFormattedPercent(field.fieldname, row)"
:disabled="Boolean(field.read_only)"
@change="row[field.fieldname] = flt($event.target.value)"
/>
<FormControl
v-else-if="field.fieldtype === 'Currency'"
class="[&_input]:text-right"
type="text"
variant="outline"
:value="
getFormattedCurrency(field.fieldname, row, parentDoc)
"
:disabled="Boolean(field.read_only)"
@change="row[field.fieldname] = flt($event.target.value)"
/>
<FormControl
v-else-if="field.fieldtype === 'Select'"
class="text-sm text-ink-gray-8"
@ -350,6 +379,7 @@ getMeta(props.parentDoctype)
const { getUser } = usersStore()
const rows = defineModel()
const parentDoc = defineModel('parent')
const showRowList = ref(new Array(rows.value?.length || []).fill(false))
const selectedRows = reactive(new Set())

View File

@ -25,6 +25,7 @@
<Grid
v-else-if="field.fieldtype === 'Table'"
v-model="data[field.fieldname]"
v-model:parent="data"
:doctype="field.options"
:parentDoctype="doctype"
:parentFieldname="field.fieldname"

View File

@ -39,7 +39,7 @@ export function getMeta(doctype) {
return formatNumber(doc[fieldname], '', precision)
}
function getFormattedCurrency(fieldname, doc) {
function getFormattedCurrency(fieldname, doc, parentDoc = null) {
let currency = window.sysdefaults.currency || 'USD'
let df = doctypeMeta[doctype]?.fields.find((f) => f.fieldname == fieldname)
let precision = df?.precision || null
@ -47,8 +47,11 @@ export function getMeta(doctype) {
if (df && df.options) {
if (df.options.indexOf(':') != -1) {
currency = currency
// TODO: Handle this case
} else if (doc && doc[df.options]) {
currency = doc[df.options]
} else if (parentDoc && parentDoc[df.options]) {
currency = parentDoc[df.options]
}
}