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

View File

@ -28,6 +28,7 @@ class CRMDeal(Document):
self.closed_on = frappe.utils.now_datetime() self.closed_on = frappe.utils.now_datetime()
self.validate_forcasting_fields() self.validate_forcasting_fields()
self.validate_lost_reason() self.validate_lost_reason()
self.update_currency_exchange()
def after_insert(self): def after_insert(self):
if self.deal_owner: if self.deal_owner:
@ -170,6 +171,28 @@ class CRMDeal(Document):
elif self.lost_reason == "Other" and not self.lost_notes: elif self.lost_reason == "Other" and not self.lost_notes:
frappe.throw(_("Please specify the reason for losing the deal."), frappe.ValidationError) 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 @staticmethod
def default_list_data(): def default_list_data():
columns = [ columns = [

View File

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

View File

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