fix: store currency exchange in deal & organization

This commit is contained in:
Shariq Ansari 2025-07-09 14:38:56 +05:30
parent 1b0d966db0
commit 0be737914a
5 changed files with 113 additions and 50 deletions

View File

@ -38,6 +38,7 @@
"column_break_xbyf",
"territory",
"currency",
"currency_exchange",
"annual_revenue",
"industry",
"person_section",
@ -415,12 +416,18 @@
"fieldname": "closed_on",
"fieldtype": "Datetime",
"label": "Closed On"
},
{
"fieldname": "currency_exchange",
"fieldtype": "Link",
"label": "Currency Exchange",
"options": "CRM Currency Exchange"
}
],
"grid_page_length": 50,
"index_web_pages_for_search": 1,
"links": [],
"modified": "2025-07-06 15:16:37.673699",
"modified": "2025-07-09 14:26:53.986118",
"modified_by": "Administrator",
"module": "FCRM",
"name": "CRM Deal",

View File

@ -28,6 +28,7 @@ class CRMDeal(Document):
self.closed_on = frappe.utils.now_datetime()
self.validate_forcasting_fields()
self.validate_lost_reason()
self.update_currency_exchange()
def after_insert(self):
if self.deal_owner:
@ -170,6 +171,28 @@ class CRMDeal(Document):
elif self.lost_reason == "Other" and not self.lost_notes:
frappe.throw(_("Please specify the reason for losing the deal."), frappe.ValidationError)
def update_currency_exchange(self):
if self.has_value_changed("currency") or not self.currency_exchange:
system_currency = frappe.db.get_single_value("System Settings", "currency")
currency_exchange = None
if self.currency and self.currency != system_currency:
if not frappe.db.exists(
"CRM Currency Exchange", {"from_currency": self.currency, "to_currency": system_currency}
):
new_er = frappe.new_doc("CRM Currency Exchange")
new_er.from_currency = self.currency
new_er.to_currency = system_currency
new_er.insert(ignore_permissions=True)
currency_exchange = new_er.name
else:
currency_exchange = frappe.db.get_value(
"CRM Currency Exchange",
{"from_currency": self.currency, "to_currency": system_currency},
"name",
)
currency_exchange and self.db_set("currency_exchange", currency_exchange)
@staticmethod
def default_list_data():
columns = [

View File

@ -10,6 +10,7 @@
"organization_name",
"no_of_employees",
"currency",
"currency_exchange",
"annual_revenue",
"organization_logo",
"column_break_pnpp",
@ -74,12 +75,18 @@
"fieldtype": "Link",
"label": "Address",
"options": "Address"
},
{
"fieldname": "currency_exchange",
"fieldtype": "Link",
"label": "Currency Exchange",
"options": "CRM Currency Exchange"
}
],
"image_field": "organization_logo",
"index_web_pages_for_search": 1,
"links": [],
"modified": "2024-09-17 18:37:10.341062",
"modified": "2025-07-09 14:32:23.893267",
"modified_by": "Administrator",
"module": "FCRM",
"name": "CRM Organization",
@ -111,7 +118,8 @@
"write": 1
}
],
"row_format": "Dynamic",
"sort_field": "modified",
"sort_order": "DESC",
"states": []
}
}

View File

@ -6,49 +6,74 @@ from frappe.model.document import Document
class CRMOrganization(Document):
@staticmethod
def default_list_data():
columns = [
{
'label': 'Organization',
'type': 'Data',
'key': 'organization_name',
'width': '16rem',
},
{
'label': 'Website',
'type': 'Data',
'key': 'website',
'width': '14rem',
},
{
'label': 'Industry',
'type': 'Link',
'key': 'industry',
'options': 'CRM Industry',
'width': '14rem',
},
{
'label': 'Annual Revenue',
'type': 'Currency',
'key': 'annual_revenue',
'width': '14rem',
},
{
'label': 'Last Modified',
'type': 'Datetime',
'key': 'modified',
'width': '8rem',
},
]
rows = [
"name",
"organization_name",
"organization_logo",
"website",
"industry",
"currency",
"annual_revenue",
"modified",
]
return {'columns': columns, 'rows': rows}
def validate(self):
self.update_currency_exchange()
def update_currency_exchange(self):
if self.has_value_changed("currency") or not self.currency_exchange:
system_currency = frappe.db.get_single_value("System Settings", "currency")
currency_exchange = None
if self.currency and self.currency != system_currency:
if not frappe.db.exists(
"CRM Currency Exchange", {"from_currency": self.currency, "to_currency": system_currency}
):
new_er = frappe.new_doc("CRM Currency Exchange")
new_er.from_currency = self.currency
new_er.to_currency = system_currency
new_er.insert(ignore_permissions=True)
currency_exchange = new_er.name
else:
currency_exchange = frappe.db.get_value(
"CRM Currency Exchange",
{"from_currency": self.currency, "to_currency": system_currency},
"name",
)
currency_exchange and self.db_set("currency_exchange", currency_exchange)
@staticmethod
def default_list_data():
columns = [
{
"label": "Organization",
"type": "Data",
"key": "organization_name",
"width": "16rem",
},
{
"label": "Website",
"type": "Data",
"key": "website",
"width": "14rem",
},
{
"label": "Industry",
"type": "Link",
"key": "industry",
"options": "CRM Industry",
"width": "14rem",
},
{
"label": "Annual Revenue",
"type": "Currency",
"key": "annual_revenue",
"width": "14rem",
},
{
"label": "Last Modified",
"type": "Datetime",
"key": "modified",
"width": "8rem",
},
]
rows = [
"name",
"organization_name",
"organization_logo",
"website",
"industry",
"currency",
"annual_revenue",
"modified",
]
return {"columns": columns, "rows": rows}

View File

@ -54,7 +54,7 @@ export const usersStore = defineStore('crm-users', () => {
}
function isManager(email) {
return getUser(email).role === 'Sales Manager'
return getUser(email).role === 'Sales Manager' || isAdmin(email)
}
function isSalesUser(email) {