Merge pull request #227 from shariquerik/currency-fix

fix: added/render currency for deal & organization amount field
This commit is contained in:
Shariq Ansari 2024-06-20 15:18:00 +05:30 committed by GitHub
commit e9010abe20
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 69 additions and 26 deletions

View File

@ -73,6 +73,7 @@ def get_linked_deals(contact):
fields=[ fields=[
"name", "name",
"organization", "organization",
"currency",
"annual_revenue", "annual_revenue",
"status", "status",
"email", "email",

View File

@ -257,17 +257,18 @@ def get_list_data(
"user": frappe.session.user, "user": frappe.session.user,
} }
_list = get_controller(doctype)
if not custom_view and frappe.db.exists("CRM View Settings", default_view_filters): if not custom_view and frappe.db.exists("CRM View Settings", default_view_filters):
list_view_settings = frappe.get_doc("CRM View Settings", default_view_filters) list_view_settings = frappe.get_doc("CRM View Settings", default_view_filters)
columns = frappe.parse_json(list_view_settings.columns) columns = frappe.parse_json(list_view_settings.columns)
rows = frappe.parse_json(list_view_settings.rows) rows = frappe.parse_json(list_view_settings.rows)
is_default = False is_default = False
elif not custom_view or is_default: elif not custom_view or is_default and hasattr(_list, "default_list_data"):
_list = get_controller(doctype) columns = _list.default_list_data().get("columns")
if hasattr(_list, "default_list_data"): if hasattr(_list, "default_list_data"):
columns = _list.default_list_data().get("columns") rows = _list.default_list_data().get("rows")
rows = _list.default_list_data().get("rows")
# check if rows has all keys from columns if not add them # check if rows has all keys from columns if not add them
for column in columns: for column in columns:

View File

@ -31,6 +31,7 @@
"job_title", "job_title",
"column_break_xbyf", "column_break_xbyf",
"territory", "territory",
"currency",
"annual_revenue", "annual_revenue",
"industry", "industry",
"person_section", "person_section",
@ -72,7 +73,8 @@
"fetch_from": ".annual_revenue", "fetch_from": ".annual_revenue",
"fieldname": "annual_revenue", "fieldname": "annual_revenue",
"fieldtype": "Currency", "fieldtype": "Currency",
"label": "Amount" "label": "Amount",
"options": "currency"
}, },
{ {
"fetch_from": ".website", "fetch_from": ".website",
@ -327,11 +329,17 @@
"fieldtype": "Link", "fieldtype": "Link",
"label": "Contact", "label": "Contact",
"options": "Contact" "options": "Contact"
},
{
"fieldname": "currency",
"fieldtype": "Link",
"label": "Currency",
"options": "Currency"
} }
], ],
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"links": [], "links": [],
"modified": "2024-06-19 18:01:59.213811", "modified": "2024-06-20 12:55:41.602364",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "FCRM", "module": "FCRM",
"name": "CRM Deal", "name": "CRM Deal",

View File

@ -178,6 +178,7 @@ class CRMDeal(Document):
"annual_revenue", "annual_revenue",
"status", "status",
"email", "email",
"currency",
"mobile_no", "mobile_no",
"deal_owner", "deal_owner",
"sla_status", "sla_status",

View File

@ -9,6 +9,7 @@
"field_order": [ "field_order": [
"organization_name", "organization_name",
"no_of_employees", "no_of_employees",
"currency",
"annual_revenue", "annual_revenue",
"organization_logo", "organization_logo",
"column_break_pnpp", "column_break_pnpp",
@ -47,7 +48,8 @@
{ {
"fieldname": "annual_revenue", "fieldname": "annual_revenue",
"fieldtype": "Currency", "fieldtype": "Currency",
"label": "Annual Revenue" "label": "Annual Revenue",
"options": "currency"
}, },
{ {
"fieldname": "industry", "fieldname": "industry",
@ -60,12 +62,18 @@
"fieldtype": "Link", "fieldtype": "Link",
"label": "Territory", "label": "Territory",
"options": "CRM Territory" "options": "CRM Territory"
},
{
"fieldname": "currency",
"fieldtype": "Link",
"label": "Currency",
"options": "Currency"
} }
], ],
"image_field": "organization_logo", "image_field": "organization_logo",
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"links": [], "links": [],
"modified": "2024-01-19 21:53:14.945857", "modified": "2024-06-20 12:59:55.297752",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "FCRM", "module": "FCRM",
"name": "CRM Organization", "name": "CRM Organization",

View File

@ -47,6 +47,7 @@ class CRMOrganization(Document):
"organization_logo", "organization_logo",
"website", "website",
"industry", "industry",
"currency",
"annual_revenue", "annual_revenue",
"modified", "modified",
] ]

View File

@ -61,9 +61,11 @@
<script setup> <script setup>
import Fields from '@/components/Fields.vue' import Fields from '@/components/Fields.vue'
import EditIcon from '@/components/Icons/EditIcon.vue' import EditIcon from '@/components/Icons/EditIcon.vue'
import MoneyIcon from '@/components/Icons/MoneyIcon.vue'
import WebsiteIcon from '@/components/Icons/WebsiteIcon.vue' import WebsiteIcon from '@/components/Icons/WebsiteIcon.vue'
import OrganizationsIcon from '@/components/Icons/OrganizationsIcon.vue' import OrganizationsIcon from '@/components/Icons/OrganizationsIcon.vue'
import TerritoryIcon from '@/components/Icons/TerritoryIcon.vue' import TerritoryIcon from '@/components/Icons/TerritoryIcon.vue'
import { formatNumberIntoCurrency } from '@/utils'
import { call, FeatherIcon, createResource } from 'frappe-ui' import { call, FeatherIcon, createResource } from 'frappe-ui'
import { ref, nextTick, watch, computed, h } from 'vue' import { ref, nextTick, watch, computed, h } from 'vue'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
@ -205,9 +207,12 @@ const fields = computed(() => {
value: _organization.value.territory, value: _organization.value.territory,
}, },
{ {
icon: h(FeatherIcon, { name: 'dollar-sign', class: 'h-4 w-4' }), icon: MoneyIcon,
name: 'annual_revenue', name: 'annual_revenue',
value: _organization.value.annual_revenue, value: formatNumberIntoCurrency(
_organization.value.annual_revenue,
_organization.value.currency,
),
}, },
{ {
icon: h(FeatherIcon, { name: 'hash', class: 'h-4 w-4' }), icon: h(FeatherIcon, { name: 'hash', class: 'h-4 w-4' }),
@ -227,7 +232,7 @@ const fields = computed(() => {
const sections = createResource({ const sections = createResource({
url: 'crm.fcrm.doctype.crm_fields_layout.crm_fields_layout.get_fields_layout', url: 'crm.fcrm.doctype.crm_fields_layout.crm_fields_layout.get_fields_layout',
cache: ['quickEntryFields', 'CRM Organization'], cache: ['quickEntryFields', 'CRM Organization'],
params: { doctype: 'CRM Organization', type: 'Quick Entry'}, params: { doctype: 'CRM Organization', type: 'Quick Entry' },
auto: true, auto: true,
}) })
@ -246,6 +251,6 @@ watch(
editMode.value = true editMode.value = true
} }
}) })
} },
) )
</script> </script>

View File

@ -357,7 +357,10 @@ function getDealRowObject(deal) {
label: deal.organization, label: deal.organization,
logo: getOrganization(deal.organization)?.organization_logo, logo: getOrganization(deal.organization)?.organization_logo,
}, },
annual_revenue: formatNumberIntoCurrency(deal.annual_revenue), annual_revenue: formatNumberIntoCurrency(
deal.annual_revenue,
deal.currency,
),
status: { status: {
label: deal.status, label: deal.status,
color: getDealStatus(deal.status)?.iconColorClass, color: getDealStatus(deal.status)?.iconColorClass,

View File

@ -109,7 +109,7 @@ const rows = computed(() => {
if (!deals.value?.data.group_by_field?.name) return [] if (!deals.value?.data.group_by_field?.name) return []
return getGroupedByRows( return getGroupedByRows(
deals.value?.data.data, deals.value?.data.data,
deals.value?.data.group_by_field deals.value?.data.group_by_field,
) )
} else { } else {
return parseRows(deals.value?.data.data) return parseRows(deals.value?.data.data)
@ -158,7 +158,10 @@ function parseRows(rows) {
logo: getOrganization(deal.organization)?.organization_logo, logo: getOrganization(deal.organization)?.organization_logo,
} }
} else if (row == 'annual_revenue') { } else if (row == 'annual_revenue') {
_rows[row] = formatNumberIntoCurrency(deal.annual_revenue) _rows[row] = formatNumberIntoCurrency(
deal.annual_revenue,
deal.currency,
)
} else if (row == 'status') { } else if (row == 'status') {
_rows[row] = { _rows[row] = {
label: deal.status, label: deal.status,
@ -171,8 +174,8 @@ function parseRows(rows) {
deal.sla_status == 'Failed' deal.sla_status == 'Failed'
? 'red' ? 'red'
: deal.sla_status == 'Fulfilled' : deal.sla_status == 'Fulfilled'
? 'green' ? 'green'
: 'orange' : 'orange'
if (value == 'First Response Due') { if (value == 'First Response Due') {
value = __(timeAgo(deal.response_by)) value = __(timeAgo(deal.response_by))
tooltipText = dateFormat(deal.response_by, dateTooltipFormat) tooltipText = dateFormat(deal.response_by, dateTooltipFormat)
@ -207,7 +210,7 @@ function parseRows(rows) {
} }
} else if ( } else if (
['first_response_time', 'first_responded_on', 'response_by'].includes( ['first_response_time', 'first_responded_on', 'response_by'].includes(
row row,
) )
) { ) {
let field = row == 'response_by' ? 'response_by' : 'first_responded_on' let field = row == 'response_by' ? 'response_by' : 'first_responded_on'

View File

@ -104,7 +104,12 @@
class="flex items-center gap-1.5" class="flex items-center gap-1.5"
> >
<MoneyIcon class="size-4" /> <MoneyIcon class="size-4" />
<span class="">{{ formatNumberIntoCurrency(organization.doc.annual_revenue) }}</span> <span class="">{{
formatNumberIntoCurrency(
organization.doc.annual_revenue,
organization.doc.currency,
)
}}</span>
</div> </div>
<span <span
v-if="organization.doc.annual_revenue" v-if="organization.doc.annual_revenue"
@ -348,6 +353,7 @@ const deals = createListResource({
fields: [ fields: [
'name', 'name',
'organization', 'organization',
'currency',
'annual_revenue', 'annual_revenue',
'status', 'status',
'email', 'email',
@ -406,7 +412,10 @@ function getDealRowObject(deal) {
label: deal.organization, label: deal.organization,
logo: props.organization?.organization_logo, logo: props.organization?.organization_logo,
}, },
annual_revenue: formatNumberIntoCurrency(deal.annual_revenue), annual_revenue: formatNumberIntoCurrency(
deal.annual_revenue,
deal.currency,
),
status: { status: {
label: deal.status, label: deal.status,
color: getDealStatus(deal.status)?.iconColorClass, color: getDealStatus(deal.status)?.iconColorClass,

View File

@ -85,7 +85,7 @@ const showOrganizationModal = ref(false)
const currentOrganization = computed(() => { const currentOrganization = computed(() => {
return organizations.value?.data?.data?.find( return organizations.value?.data?.data?.find(
(organization) => organization.name === route.params.organizationId (organization) => organization.name === route.params.organizationId,
) )
}) })
@ -124,7 +124,10 @@ const rows = computed(() => {
} else if (row === 'website') { } else if (row === 'website') {
_rows[row] = website(organization.website) _rows[row] = website(organization.website)
} else if (row === 'annual_revenue') { } else if (row === 'annual_revenue') {
_rows[row] = formatNumberIntoCurrency(organization.annual_revenue) _rows[row] = formatNumberIntoCurrency(
organization.annual_revenue,
organization.currency,
)
} else if (['modified', 'creation'].includes(row)) { } else if (['modified', 'creation'].includes(row)) {
_rows[row] = { _rows[row] = {
label: dateFormat(organization[row], dateTooltipFormat), label: dateFormat(organization[row], dateTooltipFormat),

View File

@ -94,12 +94,12 @@ export function secondsToDuration(seconds) {
return `${hours}h ${minutes}m ${_seconds}s` return `${hours}h ${minutes}m ${_seconds}s`
} }
export function formatNumberIntoCurrency(value) { export function formatNumberIntoCurrency(value, currency = 'INR') {
if (value) { if (value) {
return value.toLocaleString('en-IN', { return value.toLocaleString('en-IN', {
maximumFractionDigits: 2, maximumFractionDigits: 0,
style: 'currency', style: 'currency',
currency: 'INR', currency: currency ? currency : 'INR',
}) })
} }
return '' return ''