Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Currency, Float & Percent format #487

Merged
merged 10 commits into from
Dec 25, 2024
1 change: 1 addition & 0 deletions crm/fcrm/doctype/crm_deal/crm_deal.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def default_list_data():
'label': 'Amount',
'type': 'Currency',
'key': 'annual_revenue',
'align': 'right',
'width': '9rem',
},
{
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/components/Activities/DataFields.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@
<span>{{ __('Loading...') }}</span>
</div>
<div v-else>
<FieldLayout v-if="tabs.data" :tabs="tabs.data" :data="data.doc" />
<FieldLayout
v-if="tabs.data"
:tabs="tabs.data"
:data="data.doc"
:doctype="doctype"
/>
</div>
<DataFieldsModal
v-if="showDataFieldsModal"
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/components/ColumnSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
</div>
</template>
</Draggable>
<div class="mt-1.5 flex flex-col gap-1 border-t border-outline-gray-modals pt-1.5">
<div
class="mt-1.5 flex flex-col gap-1 border-t border-outline-gray-modals pt-1.5"
>
<Autocomplete
value=""
:options="fields"
Expand Down Expand Up @@ -213,11 +215,13 @@ const fields = computed(() => {
})

function addColumn(c) {
let align = ['Float', 'Int', 'Percent', 'Currency'].includes(c.type) ? 'right' : 'left'
let _column = {
label: c.label,
type: c.type,
key: c.value,
width: '10rem',
align,
}
columns.value.push(_column)
rows.value.push(c.value)
Expand Down
36 changes: 34 additions & 2 deletions frontend/src/components/FieldLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,30 @@
:placeholder="getPlaceholder(field)"
v-model="data[field.name]"
/>
<FormControl
v-else-if="field.type === 'Percent'"
type="text"
:value="getFormattedPercent(field.name, data)"
:placeholder="getPlaceholder(field)"
:disabled="Boolean(field.read_only)"
@change="data[field.name] = flt($event.target.value)"
/>
<FormControl
v-else-if="field.type === 'Float'"
type="text"
:value="getFormattedFloat(field.name, data)"
:placeholder="getPlaceholder(field)"
:disabled="Boolean(field.read_only)"
@change="data[field.name] = flt($event.target.value)"
/>
<FormControl
v-else-if="field.type === 'Currency'"
type="text"
:value="getFormattedCurrency(field.name, data)"
:placeholder="getPlaceholder(field)"
:disabled="Boolean(field.read_only)"
@change="data[field.name] = flt($event.target.value)"
/>
<FormControl
v-else
type="text"
Expand All @@ -213,22 +237,30 @@ import EditIcon from '@/components/Icons/EditIcon.vue'
import IndicatorIcon from '@/components/Icons/IndicatorIcon.vue'
import UserAvatar from '@/components/UserAvatar.vue'
import Link from '@/components/Controls/Link.vue'
import { getMeta } from '../stores/meta'
import { usersStore } from '@/stores/users'
import { getFormat } from '@/utils'
import { flt } from '@/utils/numberFormat.js'
import { Tabs, Tooltip, DatePicker, DateTimePicker } from 'frappe-ui'
import { ref, computed } from 'vue'

const { getUser } = usersStore()

const props = defineProps({
tabs: Array,
data: Object,
doctype: {
type: String,
default: 'CRM Lead',
},
modal: {
type: Boolean,
default: false,
},
})

const { getFormattedPercent, getFormattedFloat, getFormattedCurrency } =
getMeta(props.doctype)
const { getUser } = usersStore()

const hasTabs = computed(() => !props.tabs[0].no_tabs)

const tabIndex = ref(0)
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/ListViews/CallLogsListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
v-slot="{ idx, column, item }"
doctype="CRM Call Log"
>
<ListRowItem :item="item">
<ListRowItem :item="item" :align="column.align">
<template #prefix>
<div v-if="['caller', 'receiver'].includes(column.key)">
<Avatar
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/ListViews/ContactsListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
v-slot="{ idx, column, item }"
doctype="Contact"
>
<ListRowItem :item="item">
<ListRowItem :item="item" :align="column.align">
<template #prefix>
<div v-if="column.key === 'full_name'">
<Avatar
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/ListViews/DealsListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"
/>
</div>
<ListRowItem v-else :item="item">
<ListRowItem v-else :item="item" :align="column.align">
<template #prefix>
<div v-if="column.key === 'status'">
<IndicatorIcon :class="item.color" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
v-slot="{ idx, column, item }"
doctype="Email Template"
>
<ListRowItem :item="item">
<ListRowItem :item="item" :align="column.align">
<!-- <template #prefix>

</template> -->
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/ListViews/LeadsListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"
/>
</div>
<ListRowItem v-else :item="item">
<ListRowItem v-else :item="item" :align="column.align">
<template #prefix>
<div v-if="column.key === 'status'">
<IndicatorIcon :class="item.color" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
v-slot="{ idx, column, item }"
doctype="CRM Organization"
>
<ListRowItem :item="item">
<ListRowItem :item="item" :align="column.align">
<template #prefix>
<div v-if="column.key === 'organization_name'">
<Avatar
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/ListViews/TasksListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
</div>
</Tooltip>
</div>
<ListRowItem v-else :item="item">
<ListRowItem v-else :item="item" :align="column.align">
<template #prefix>
<div v-if="column.key === 'status'">
<TaskStatusIcon :status="item" />
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/Modals/AddressModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</div>
</div>
<div v-if="tabs.data">
<FieldLayout :tabs="tabs.data" :data="_address" />
<FieldLayout :tabs="tabs.data" :data="_address" doctype="Address" />
<ErrorMessage class="mt-2" :message="error" />
</div>
</div>
Expand Down Expand Up @@ -54,7 +54,7 @@ import FieldLayout from '@/components/FieldLayout.vue'
import EditIcon from '@/components/Icons/EditIcon.vue'
import { usersStore } from '@/stores/users'
import { capture } from '@/telemetry'
import { call, FeatherIcon, createResource, ErrorMessage } from 'frappe-ui'
import { FeatherIcon, createResource, ErrorMessage } from 'frappe-ui'
import { ref, nextTick, watch, computed } from 'vue'

const props = defineProps({
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/components/Modals/ContactModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
</div>
</div>
<div v-if="filteredSections.length">
<FieldLayout :tabs="filteredSections" :data="_contact" />
<FieldLayout
:tabs="filteredSections"
:data="_contact"
doctype="Contact"
/>
</div>
</div>
<div class="px-4 pb-7 pt-4 sm:px-6">
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/Modals/DealModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
v-if="filteredSections.length"
:tabs="filteredSections"
:data="deal"
doctype="CRM Deal"
/>
<ErrorMessage class="mt-4" v-if="error" :message="__(error)" />
</div>
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/components/Modals/OrganizationModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
</div>
</div>
<div v-if="filteredSections.length">
<FieldLayout :tabs="filteredSections" :data="_organization" />
<FieldLayout
:tabs="filteredSections"
:data="_organization"
doctype="CRM Organization"
/>
</div>
</div>
<div class="px-4 pb-7 pt-4 sm:px-6">
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Modals/SidePanelModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function saveChanges() {
{
doctype: _doctype.value,
type: 'Side Panel',
layout: JSON.stringify(_tabs),
layout: JSON.stringify(_tabs[0].sections),
},
).then(() => {
loading.value = false
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/components/Settings/SettingsPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
/>
</h2>
<div v-if="!data.get.loading" class="flex-1 overflow-y-auto">
<FieldLayout v-if="data?.doc && tabs" :tabs="tabs" :data="data.doc" />
<FieldLayout
v-if="data?.doc && tabs"
:tabs="tabs"
:data="data.doc"
:doctype="doctype"
/>
<ErrorMessage class="mt-2" :message="error" />
</div>
<div v-else class="flex flex-1 items-center justify-center">
Expand Down
35 changes: 35 additions & 0 deletions frontend/src/components/SidePanelLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,33 @@
@change="(data) => emit('update', field.name, data)"
/>
</div>
<FormControl
v-else-if="field.type === 'percent'"
class="form-control"
type="text"
:value="getFormattedPercent(field.name, data)"
:placeholder="field.placeholder"
:debounce="500"
@change.stop="emit('update', field.name, flt($event.target.value))"
/>
<FormControl
v-else-if="field.type === 'float'"
class="form-control"
type="text"
:value="getFormattedFloat(field.name, data)"
:placeholder="field.placeholder"
:debounce="500"
@change.stop="emit('update', field.name, flt($event.target.value))"
/>
<FormControl
v-else-if="field.type === 'currency'"
class="form-control"
type="text"
:value="getFormattedCurrency(field.name, data)"
:placeholder="field.placeholder"
:debounce="500"
@change.stop="emit('update', field.name, flt($event.target.value))"
/>
<FormControl
v-else
class="form-control"
Expand Down Expand Up @@ -203,21 +230,29 @@ import ArrowUpRightIcon from '@/components/Icons/ArrowUpRightIcon.vue'
import EditIcon from '@/components/Icons/EditIcon.vue'
import Link from '@/components/Controls/Link.vue'
import UserAvatar from '@/components/UserAvatar.vue'
import { getMeta } from '@/stores/meta'
import { usersStore } from '@/stores/users'
import { getFormat } from '@/utils'
import { flt } from '@/utils/numberFormat.js'
import { Tooltip, DateTimePicker, DatePicker } from 'frappe-ui'
import { computed } from 'vue'

const props = defineProps({
fields: {
type: Object,
},
doctype: {
type: String,
default: 'CRM Lead',
},
isLastSection: {
type: Boolean,
default: false,
},
})

const { getFormattedPercent, getFormattedFloat, getFormattedCurrency } =
getMeta(props.doctype)
const { getUser } = usersStore()

const emit = defineEmits(['update'])
Expand Down
17 changes: 7 additions & 10 deletions frontend/src/pages/Contact.vue
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
v-if="section.fields"
:fields="section.fields"
:isLastSection="i == fieldsLayout.data.length - 1"
doctype="Contact"
v-model="contact.data"
@update="updateField"
/>
Expand Down Expand Up @@ -211,13 +212,9 @@ import DealsIcon from '@/components/Icons/DealsIcon.vue'
import DealsListView from '@/components/ListViews/DealsListView.vue'
import SidePanelModal from '@/components/Modals/SidePanelModal.vue'
import AddressModal from '@/components/Modals/AddressModal.vue'
import {
formatDate,
timeAgo,
formatNumberIntoCurrency,
createToast,
} from '@/utils'
import { formatDate, timeAgo, createToast } from '@/utils'
import { getView } from '@/utils/view'
import { getMeta } from '@/stores/meta'
import { globalStore } from '@/stores/global.js'
import { usersStore } from '@/stores/users.js'
import { organizationsStore } from '@/stores/organizations.js'
Expand Down Expand Up @@ -601,6 +598,8 @@ async function updateField(fieldname, value) {
contact.reload()
}

const { getFormattedCurrency } = getMeta('CRM Deal')

const columns = computed(() => dealColumns)

function getDealRowObject(deal) {
Expand All @@ -610,10 +609,7 @@ function getDealRowObject(deal) {
label: deal.organization,
logo: getOrganization(deal.organization)?.organization_logo,
},
annual_revenue: formatNumberIntoCurrency(
deal.annual_revenue,
deal.currency,
),
annual_revenue: getFormattedCurrency('annual_revenue', deal),
status: {
label: deal.status,
color: getDealStatus(deal.status)?.iconColorClass,
Expand All @@ -640,6 +636,7 @@ const dealColumns = [
{
label: __('Amount'),
key: 'annual_revenue',
align: 'right',
width: '9rem',
},
{
Expand Down
14 changes: 14 additions & 0 deletions frontend/src/pages/Contacts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,12 @@ import LayoutHeader from '@/components/LayoutHeader.vue'
import ContactModal from '@/components/Modals/ContactModal.vue'
import ContactsListView from '@/components/ListViews/ContactsListView.vue'
import ViewControls from '@/components/ViewControls.vue'
import { getMeta } from '@/stores/meta'
import { organizationsStore } from '@/stores/organizations.js'
import { formatDate, timeAgo } from '@/utils'
import { ref, computed } from 'vue'

const { getFormattedPercent, getFormattedFloat, getFormattedCurrency } = getMeta('Contact')
const { getOrganization } = organizationsStore()

const showContactModal = ref(false)
Expand Down Expand Up @@ -110,6 +112,18 @@ const rows = computed(() => {
_rows[row] = formatDate(contact[row], '', true, fieldType == 'Datetime')
}

if (fieldType && fieldType == 'Currency') {
_rows[row] = getFormattedCurrency(row, contact)
}

if (fieldType && fieldType == 'Float') {
_rows[row] = getFormattedFloat(row, contact)
}

if (fieldType && fieldType == 'Percent') {
_rows[row] = getFormattedPercent(row, contact)
}

if (row == 'full_name') {
_rows[row] = {
label: contact.full_name,
Expand Down
Loading
Loading