Merge pull request #1061 from frappe/mergify/bp/main-hotfix/pr-1059
fixes (backport #1059)
This commit is contained in:
commit
b8dde8c41c
@ -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):
|
||||
"""
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user