Skip to content

Commit 62270a4

Browse files
authored
Merge pull request #897 from frappe/mergify/bp/main-hotfix/pr-896
2 parents 31c649d + 0023ea0 commit 62270a4

File tree

6 files changed

+135
-5
lines changed

6 files changed

+135
-5
lines changed

frontend/src/data/document.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ export function useDocument(doctype, docname) {
7575
organizedControllers[controllerKey].push(controller)
7676
}
7777
controllersCache[doctype][docname || ''] = organizedControllers
78+
79+
triggerOnload()
7880
}
7981

8082
function getControllers(row = null) {
@@ -93,9 +95,16 @@ export function useDocument(doctype, docname) {
9395
return []
9496
}
9597

98+
async function triggerOnload() {
99+
const handler = async function () {
100+
await this.onload?.()
101+
}
102+
await trigger(handler)
103+
}
104+
96105
async function triggerOnRefresh() {
97106
const handler = async function () {
98-
await this.refresh()
107+
await this.refresh?.()
99108
}
100109
await trigger(handler)
101110
}
@@ -189,6 +198,8 @@ export function useDocument(doctype, docname) {
189198
return {
190199
document: documentsCache[doctype][docname || ''],
191200
assignees,
201+
getControllers,
202+
triggerOnload,
192203
triggerOnChange,
193204
triggerOnRowAdd,
194205
triggerOnRowRemove,

frontend/src/data/script.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,13 @@ export function getScript(doctype, view = 'Form') {
116116
parentInstance = null,
117117
isChildDoctype = false,
118118
) {
119+
document.actions = document.actions || []
120+
document.statuses = document.statuses || []
121+
119122
let instance = new FormClass()
120123

124+
// Store the original document context to be used by properties like 'actions'
125+
instance._originalDocumentContext = document
121126
instance._isChildDoctype = isChildDoctype
122127

123128
for (const key in document) {
@@ -199,6 +204,76 @@ export function getScript(doctype, view = 'Form') {
199204
return createDocProxy(row, this)
200205
}
201206
}
207+
208+
if (!Object.prototype.hasOwnProperty.call(FormClass.prototype, 'actions')) {
209+
Object.defineProperty(FormClass.prototype, 'actions', {
210+
configurable: true,
211+
enumerable: true,
212+
get() {
213+
if (!this._originalDocumentContext) {
214+
console.warn(
215+
'CRM Script: _originalDocumentContext not found on instance for actions getter.',
216+
)
217+
return []
218+
}
219+
220+
return this._originalDocumentContext.actions
221+
},
222+
set(newValue) {
223+
if (!this._originalDocumentContext) {
224+
console.warn(
225+
'CRM Script: _originalDocumentContext not found on instance for actions setter.',
226+
)
227+
return
228+
}
229+
if (!Array.isArray(newValue)) {
230+
console.warn(
231+
'CRM Script: "actions" property must be an array. Value was not set.',
232+
newValue,
233+
)
234+
this._originalDocumentContext.actions = []
235+
return
236+
}
237+
this._originalDocumentContext.actions = newValue
238+
},
239+
})
240+
}
241+
242+
if (
243+
!Object.prototype.hasOwnProperty.call(FormClass.prototype, 'statuses')
244+
) {
245+
Object.defineProperty(FormClass.prototype, 'statuses', {
246+
configurable: true,
247+
enumerable: true,
248+
get() {
249+
if (!this._originalDocumentContext) {
250+
console.warn(
251+
'CRM Script: _originalDocumentContext not found on instance for statuses getter.',
252+
)
253+
return []
254+
}
255+
256+
return this._originalDocumentContext.statuses
257+
},
258+
set(newValue) {
259+
if (!this._originalDocumentContext) {
260+
console.warn(
261+
'CRM Script: _originalDocumentContext not found on instance for statuses setter.',
262+
)
263+
return
264+
}
265+
if (!Array.isArray(newValue)) {
266+
console.warn(
267+
'CRM Script: "statuses" property must be an array. Value was not set.',
268+
newValue,
269+
)
270+
this._originalDocumentContext.statuses = []
271+
return
272+
}
273+
this._originalDocumentContext.statuses = newValue
274+
},
275+
})
276+
}
202277
}
203278

204279
// utility function to setup a form controller

frontend/src/pages/Deal.vue

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,25 @@
1212
v-if="deal.data._customActions?.length"
1313
:actions="deal.data._customActions"
1414
/>
15+
<CustomActions
16+
v-if="document.actions?.length"
17+
:actions="document.actions"
18+
/>
1519
<AssignTo
1620
v-model="assignees.data"
1721
:data="document.doc"
1822
doctype="CRM Deal"
1923
/>
2024
<Dropdown
21-
:options="statusOptions('deal', updateField, deal.data._customStatuses)"
25+
:options="
26+
statusOptions(
27+
'deal',
28+
updateField,
29+
document.statuses?.length
30+
? document.statuses
31+
: deal.data._customStatuses,
32+
)
33+
"
2234
>
2335
<template #default="{ open }">
2436
<Button :label="deal.data.status">

frontend/src/pages/Lead.vue

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,25 @@
1212
v-if="lead.data._customActions?.length"
1313
:actions="lead.data._customActions"
1414
/>
15+
<CustomActions
16+
v-if="document.actions?.length"
17+
:actions="document.actions"
18+
/>
1519
<AssignTo
1620
v-model="assignees.data"
1721
:data="document.doc"
1822
doctype="CRM Lead"
1923
/>
2024
<Dropdown
21-
:options="statusOptions('lead', updateField, lead.data._customStatuses)"
25+
:options="
26+
statusOptions(
27+
'lead',
28+
updateField,
29+
document.statuses?.length
30+
? document.statuses
31+
: lead.data._customStatuses,
32+
)
33+
"
2234
>
2335
<template #default="{ open }">
2436
<Button :label="lead.data.status">

frontend/src/pages/MobileDeal.vue

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@
1111
<div class="absolute right-0">
1212
<Dropdown
1313
:options="
14-
statusOptions('deal', updateField, deal.data._customStatuses)
14+
statusOptions(
15+
'deal',
16+
updateField,
17+
document.statuses?.length
18+
? document.statuses
19+
: deal.data._customStatuses,
20+
)
1521
"
1622
>
1723
<template #default="{ open }">
@@ -45,6 +51,10 @@
4551
v-if="deal.data._customActions?.length"
4652
:actions="deal.data._customActions"
4753
/>
54+
<CustomActions
55+
v-if="document.actions?.length"
56+
:actions="document.actions"
57+
/>
4858
</div>
4959
</div>
5060
<div v-if="deal.data" class="flex h-full overflow-hidden">

frontend/src/pages/MobileLead.vue

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@
1111
<div class="absolute right-0">
1212
<Dropdown
1313
:options="
14-
statusOptions('lead', updateField, lead.data._customStatuses)
14+
statusOptions(
15+
'lead',
16+
updateField,
17+
document.statuses?.length
18+
? document.statuses
19+
: lead.data._customStatuses,
20+
)
1521
"
1622
>
1723
<template #default="{ open }">
@@ -45,6 +51,10 @@
4551
v-if="lead.data._customActions?.length"
4652
:actions="lead.data._customActions"
4753
/>
54+
<CustomActions
55+
v-if="document.actions?.length"
56+
:actions="document.actions"
57+
/>
4858
<Button
4959
:label="__('Convert')"
5060
variant="solid"

0 commit comments

Comments
 (0)