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

fix: added/render currency for deal & organization amount field #227

Merged
merged 4 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crm/api/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def get_linked_deals(contact):
fields=[
"name",
"organization",
"currency",
"annual_revenue",
"status",
"email",
Expand Down
11 changes: 6 additions & 5 deletions crm/api/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,17 +257,18 @@ def get_list_data(
"user": frappe.session.user,
}

_list = get_controller(doctype)

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)
columns = frappe.parse_json(list_view_settings.columns)
rows = frappe.parse_json(list_view_settings.rows)
is_default = False
elif not custom_view or is_default:
_list = get_controller(doctype)
elif not custom_view or is_default and hasattr(_list, "default_list_data"):
columns = _list.default_list_data().get("columns")

if hasattr(_list, "default_list_data"):
columns = _list.default_list_data().get("columns")
rows = _list.default_list_data().get("rows")
if hasattr(_list, "default_list_data"):
rows = _list.default_list_data().get("rows")

# check if rows has all keys from columns if not add them
for column in columns:
Expand Down
12 changes: 10 additions & 2 deletions crm/fcrm/doctype/crm_deal/crm_deal.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"job_title",
"column_break_xbyf",
"territory",
"currency",
"annual_revenue",
"industry",
"person_section",
Expand Down Expand Up @@ -72,7 +73,8 @@
"fetch_from": ".annual_revenue",
"fieldname": "annual_revenue",
"fieldtype": "Currency",
"label": "Amount"
"label": "Amount",
"options": "currency"
},
{
"fetch_from": ".website",
Expand Down Expand Up @@ -327,11 +329,17 @@
"fieldtype": "Link",
"label": "Contact",
"options": "Contact"
},
{
"fieldname": "currency",
"fieldtype": "Link",
"label": "Currency",
"options": "Currency"
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2024-06-19 18:01:59.213811",
"modified": "2024-06-20 12:55:41.602364",
"modified_by": "Administrator",
"module": "FCRM",
"name": "CRM Deal",
Expand Down
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 @@ -178,6 +178,7 @@ def default_list_data():
"annual_revenue",
"status",
"email",
"currency",
"mobile_no",
"deal_owner",
"sla_status",
Expand Down
12 changes: 10 additions & 2 deletions crm/fcrm/doctype/crm_organization/crm_organization.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"field_order": [
"organization_name",
"no_of_employees",
"currency",
"annual_revenue",
"organization_logo",
"column_break_pnpp",
Expand Down Expand Up @@ -47,7 +48,8 @@
{
"fieldname": "annual_revenue",
"fieldtype": "Currency",
"label": "Annual Revenue"
"label": "Annual Revenue",
"options": "currency"
},
{
"fieldname": "industry",
Expand All @@ -60,12 +62,18 @@
"fieldtype": "Link",
"label": "Territory",
"options": "CRM Territory"
},
{
"fieldname": "currency",
"fieldtype": "Link",
"label": "Currency",
"options": "Currency"
}
],
"image_field": "organization_logo",
"index_web_pages_for_search": 1,
"links": [],
"modified": "2024-01-19 21:53:14.945857",
"modified": "2024-06-20 12:59:55.297752",
"modified_by": "Administrator",
"module": "FCRM",
"name": "CRM Organization",
Expand Down
1 change: 1 addition & 0 deletions crm/fcrm/doctype/crm_organization/crm_organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def default_list_data():
"organization_logo",
"website",
"industry",
"currency",
"annual_revenue",
"modified",
]
Expand Down
13 changes: 9 additions & 4 deletions frontend/src/components/Modals/OrganizationModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@
<script setup>
import Fields from '@/components/Fields.vue'
import EditIcon from '@/components/Icons/EditIcon.vue'
import MoneyIcon from '@/components/Icons/MoneyIcon.vue'
import WebsiteIcon from '@/components/Icons/WebsiteIcon.vue'
import OrganizationsIcon from '@/components/Icons/OrganizationsIcon.vue'
import TerritoryIcon from '@/components/Icons/TerritoryIcon.vue'
import { formatNumberIntoCurrency } from '@/utils'
import { call, FeatherIcon, createResource } from 'frappe-ui'
import { ref, nextTick, watch, computed, h } from 'vue'
import { useRouter } from 'vue-router'
Expand Down Expand Up @@ -205,9 +207,12 @@ const fields = computed(() => {
value: _organization.value.territory,
},
{
icon: h(FeatherIcon, { name: 'dollar-sign', class: 'h-4 w-4' }),
icon: MoneyIcon,
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' }),
Expand All @@ -227,7 +232,7 @@ const fields = computed(() => {
const sections = createResource({
url: 'crm.fcrm.doctype.crm_fields_layout.crm_fields_layout.get_fields_layout',
cache: ['quickEntryFields', 'CRM Organization'],
params: { doctype: 'CRM Organization', type: 'Quick Entry'},
params: { doctype: 'CRM Organization', type: 'Quick Entry' },
auto: true,
})

Expand All @@ -246,6 +251,6 @@ watch(
editMode.value = true
}
})
}
},
)
</script>
5 changes: 4 additions & 1 deletion frontend/src/pages/Contact.vue
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,10 @@ function getDealRowObject(deal) {
label: deal.organization,
logo: getOrganization(deal.organization)?.organization_logo,
},
annual_revenue: formatNumberIntoCurrency(deal.annual_revenue),
annual_revenue: formatNumberIntoCurrency(
deal.annual_revenue,
deal.currency,
),
status: {
label: deal.status,
color: getDealStatus(deal.status)?.iconColorClass,
Expand Down
13 changes: 8 additions & 5 deletions frontend/src/pages/Deals.vue
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const rows = computed(() => {
if (!deals.value?.data.group_by_field?.name) return []
return getGroupedByRows(
deals.value?.data.data,
deals.value?.data.group_by_field
deals.value?.data.group_by_field,
)
} else {
return parseRows(deals.value?.data.data)
Expand Down Expand Up @@ -158,7 +158,10 @@ function parseRows(rows) {
logo: getOrganization(deal.organization)?.organization_logo,
}
} else if (row == 'annual_revenue') {
_rows[row] = formatNumberIntoCurrency(deal.annual_revenue)
_rows[row] = formatNumberIntoCurrency(
deal.annual_revenue,
deal.currency,
)
} else if (row == 'status') {
_rows[row] = {
label: deal.status,
Expand All @@ -171,8 +174,8 @@ function parseRows(rows) {
deal.sla_status == 'Failed'
? 'red'
: deal.sla_status == 'Fulfilled'
? 'green'
: 'orange'
? 'green'
: 'orange'
if (value == 'First Response Due') {
value = __(timeAgo(deal.response_by))
tooltipText = dateFormat(deal.response_by, dateTooltipFormat)
Expand Down Expand Up @@ -207,7 +210,7 @@ function parseRows(rows) {
}
} else if (
['first_response_time', 'first_responded_on', 'response_by'].includes(
row
row,
)
) {
let field = row == 'response_by' ? 'response_by' : 'first_responded_on'
Expand Down
13 changes: 11 additions & 2 deletions frontend/src/pages/Organization.vue
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@
class="flex items-center gap-1.5"
>
<MoneyIcon class="size-4" />
<span class="">{{ formatNumberIntoCurrency(organization.doc.annual_revenue) }}</span>
<span class="">{{
formatNumberIntoCurrency(
organization.doc.annual_revenue,
organization.doc.currency,
)
}}</span>
</div>
<span
v-if="organization.doc.annual_revenue"
Expand Down Expand Up @@ -348,6 +353,7 @@ const deals = createListResource({
fields: [
'name',
'organization',
'currency',
'annual_revenue',
'status',
'email',
Expand Down Expand Up @@ -406,7 +412,10 @@ function getDealRowObject(deal) {
label: deal.organization,
logo: props.organization?.organization_logo,
},
annual_revenue: formatNumberIntoCurrency(deal.annual_revenue),
annual_revenue: formatNumberIntoCurrency(
deal.annual_revenue,
deal.currency,
),
status: {
label: deal.status,
color: getDealStatus(deal.status)?.iconColorClass,
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/pages/Organizations.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const showOrganizationModal = ref(false)

const currentOrganization = computed(() => {
return organizations.value?.data?.data?.find(
(organization) => organization.name === route.params.organizationId
(organization) => organization.name === route.params.organizationId,
)
})

Expand Down Expand Up @@ -124,7 +124,10 @@ const rows = computed(() => {
} else if (row === 'website') {
_rows[row] = website(organization.website)
} 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)) {
_rows[row] = {
label: dateFormat(organization[row], dateTooltipFormat),
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ export function secondsToDuration(seconds) {
return `${hours}h ${minutes}m ${_seconds}s`
}

export function formatNumberIntoCurrency(value) {
export function formatNumberIntoCurrency(value, currency = 'INR') {
if (value) {
return value.toLocaleString('en-IN', {
maximumFractionDigits: 2,
maximumFractionDigits: 0,
style: 'currency',
currency: 'INR',
currency: currency ? currency : 'INR',
})
}
return ''
Expand Down
Loading