Merge pull request #1059 from shariquerik/refactor-1

This commit is contained in:
Shariq Ansari 2025-07-23 13:35:55 +05:30 committed by GitHub
commit 076762e2f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 37 additions and 28 deletions

View File

@ -139,12 +139,12 @@ class CRMDeal(Document):
if sla:
sla.apply(self)
def update_close_date(self):
def update_closed_date(self):
"""
Update the close date based on the "Won" status.
Update the closed date based on the "Won" status.
"""
if self.status == "Won" and not self.close_date:
self.close_date = frappe.utils.nowdate()
if self.status == "Won" and not self.closed_date:
self.closed_date = frappe.utils.nowdate()
def update_default_probability(self):
"""
@ -154,13 +154,13 @@ class CRMDeal(Document):
self.probability = frappe.db.get_value("CRM Deal Status", self.status, "probability") or 0
def validate_forcasting_fields(self):
self.update_close_date()
self.update_closed_date()
self.update_default_probability()
if frappe.db.get_single_value("FCRM Settings", "enable_forecasting"):
if not self.deal_value or self.deal_value == 0:
frappe.throw(_("Deal Value is required."), frappe.MandatoryError)
if not self.close_date:
frappe.throw(_("Close Date is required."), frappe.MandatoryError)
if not self.expected_deal_value or self.expected_deal_value == 0:
frappe.throw(_("Expected Deal Value is required."), frappe.MandatoryError)
if not self.expected_closure_date:
frappe.throw(_("Expected Closure Date is required."), frappe.MandatoryError)
def validate_lost_reason(self):
"""

View File

@ -275,12 +275,16 @@ def get_exchange_rate(from_currency, to_currency, date=None):
url = f"https://api.frankfurter.app/{date}?from={from_currency}&to={to_currency}"
response = requests.get(url)
for _i in range(3):
response = requests.get(url)
if response.status_code == 200:
data = response.json()
rate = data["rates"].get(to_currency)
if rate:
return rate
if response.status_code == 200:
data = response.json()
rate = data["rates"].get(to_currency)
return rate
else:
frappe.throw(_("Failed to fetch historical exchange rate from external API. Please try again later."))
return None
frappe.log_error(
f"Failed to fetch exchange rate from {from_currency} to {to_currency} on {date}",
title="Exchange Rate Fetch Error",
)
return 1.0 # Default exchange rate if API call fails or no rate found

View File

@ -5,6 +5,7 @@ import { reactive } from 'vue'
const documentsCache = {}
const controllersCache = {}
const assigneesCache = {}
export function useDocument(doctype, docname) {
const { setupScript } = getScript(doctype)
@ -46,16 +47,20 @@ export function useDocument(doctype, docname) {
}
}
const assignees = createResource({
url: 'crm.api.doc.get_assigned_users',
cache: `assignees:${doctype}:${docname}`,
auto: docname ? true : false,
params: {
doctype: doctype,
name: docname,
},
transform: (data) => parseAssignees(data),
})
assigneesCache[doctype] = assigneesCache[doctype] || {}
if (!assigneesCache[doctype][docname || '']) {
assigneesCache[doctype][docname || ''] = createResource({
url: 'crm.api.doc.get_assigned_users',
cache: `assignees:${doctype}:${docname}`,
auto: docname ? true : false,
params: {
doctype: doctype,
name: docname,
},
transform: (data) => parseAssignees(data),
})
}
async function setupFormScript() {
if (
@ -224,7 +229,7 @@ export function useDocument(doctype, docname) {
return {
document: documentsCache[doctype][docname || ''],
assignees,
assignees: assigneesCache[doctype][docname || ''],
getControllers,
triggerOnLoad,
triggerOnBeforeCreate,