fix: show lost reason modal if status of type Lost is set

This commit is contained in:
Shariq Ansari 2025-07-11 16:35:47 +05:30
parent 4e6d4a1d77
commit 51530b7608
4 changed files with 6 additions and 6 deletions

View File

@ -166,7 +166,7 @@ class CRMDeal(Document):
""" """
Validate the lost reason if the status is set to "Lost". Validate the lost reason if the status is set to "Lost".
""" """
if self.status == "Lost": if self.status and frappe.get_cached_value("CRM Deal Status", self.status, "type") == "Lost":
if not self.lost_reason: if not self.lost_reason:
frappe.throw(_("Please specify a reason for losing the deal."), frappe.ValidationError) frappe.throw(_("Please specify a reason for losing the deal."), frappe.ValidationError)
elif self.lost_reason == "Other" and not self.lost_notes: elif self.lost_reason == "Other" and not self.lost_notes:

View File

@ -783,7 +783,7 @@ const showLostReasonModal = ref(false)
function setLostReason() { function setLostReason() {
if ( if (
document.doc.status !== 'Lost' || getDealStatus(document.doc.status).type !== 'Lost' ||
(document.doc.lost_reason && document.doc.lost_reason !== 'Other') || (document.doc.lost_reason && document.doc.lost_reason !== 'Other') ||
(document.doc.lost_reason === 'Other' && document.doc.lost_notes) (document.doc.lost_reason === 'Other' && document.doc.lost_notes)
) { ) {
@ -795,7 +795,7 @@ function setLostReason() {
} }
function beforeStatusChange(data) { function beforeStatusChange(data) {
if (data?.hasOwnProperty('status') && data.status == 'Lost') { if (data?.hasOwnProperty('status') && getDealStatus(data.status).type == 'Lost') {
setLostReason() setLostReason()
} else { } else {
document.save.submit(null, { document.save.submit(null, {

View File

@ -643,7 +643,7 @@ const showLostReasonModal = ref(false)
function setLostReason() { function setLostReason() {
if ( if (
document.doc.status !== 'Lost' || getDealStatus(document.doc.status).type !== 'Lost' ||
(document.doc.lost_reason && document.doc.lost_reason !== 'Other') || (document.doc.lost_reason && document.doc.lost_reason !== 'Other') ||
(document.doc.lost_reason === 'Other' && document.doc.lost_notes) (document.doc.lost_reason === 'Other' && document.doc.lost_notes)
) { ) {
@ -655,7 +655,7 @@ function setLostReason() {
} }
function beforeStatusChange(data) { function beforeStatusChange(data) {
if (data?.hasOwnProperty('status') && data.status == 'Lost') { if (data?.hasOwnProperty('status') && getDealStatus(data.status).type == 'Lost') {
setLostReason() setLostReason()
} else { } else {
document.save.submit(null, { document.save.submit(null, {

View File

@ -28,7 +28,7 @@ export const statusesStore = defineStore('crm-statuses', () => {
const dealStatuses = createListResource({ const dealStatuses = createListResource({
doctype: 'CRM Deal Status', doctype: 'CRM Deal Status',
fields: ['name', 'color', 'position'], fields: ['name', 'color', 'position', 'type'],
orderBy: 'position asc', orderBy: 'position asc',
cache: 'deal-statuses', cache: 'deal-statuses',
initialData: [], initialData: [],