Skip to content

Commit 71afea9

Browse files
fix: disallow save until table renders (#380) (#381)
correct mode of payment summary (cherry picked from commit 56ba10a) Co-authored-by: Tyler Matteson <support@agritheory.dev>
1 parent 17afb21 commit 71afea9

File tree

3 files changed

+72
-42
lines changed

3 files changed

+72
-42
lines changed

check_run/check_run/doctype/check_run/check_run.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ frappe.provide('check_run')
55

66
frappe.ui.form.on('Check Run', {
77
setup: frm => {
8+
frm.disable_save()
89
frappe.realtime.on('process_check_run_progress', data => {
910
show_progress_bar(frm, data, 'Processing')
1011
})
@@ -29,9 +30,9 @@ frappe.ui.form.on('Check Run', {
2930
}
3031
frm.doc.transactions = JSON.stringify(check_run.transactions)
3132
},
32-
refresh: frm => {
33+
refresh: async frm => {
34+
frm.disable_save()
3335
frm.layout.show_message('')
34-
frm.trigger('update_primary_action')
3536
if (frm.doc.__onload && frm.doc.__onload.errors) {
3637
frm.set_intro(
3738
__('<a href="" style="color: var(--red)" id="check-run-error">This Check Run has errors, click to view.</a>'),
@@ -68,7 +69,6 @@ frappe.ui.form.on('Check Run', {
6869
onload_post_render: frm => {
6970
frm.page.wrapper.find('.layout-side-section').hide()
7071
permit_first_user(frm)
71-
frm.trigger('update_primary_action')
7272
$(frm.wrapper).on('dirty', () => {
7373
frm.trigger('update_primary_action')
7474
})
@@ -239,11 +239,24 @@ function set_queries(frm) {
239239
}
240240

241241
function get_entries(frm) {
242-
return new Promise(function (resolve, reject) {
243-
if (!frm.doc.transactions && check_run.transactions) {
244-
frm.dirty()
242+
return new Promise(async (resolve, reject) => {
243+
try {
244+
if (!frm.doc.transactions && check_run.transactions) {
245+
frm.dirty()
246+
}
247+
248+
// Wait for mount to complete
249+
await window.check_run.mount(frm)
250+
251+
// Wait an additional tick to ensure Vue rendering is complete
252+
await new Promise(resolve => setTimeout(resolve, 0))
253+
254+
// Trigger update and resolve
255+
frm.trigger('update_primary_action')
256+
resolve()
257+
} catch (error) {
258+
reject(error)
245259
}
246-
resolve(window.check_run.mount(frm))
247260
})
248261
}
249262

check_run/public/js/check_run/ModeOfPaymentSummary.vue

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ function format_currency(v2, currency, decimals) {
3030
3131
function calculate_totals() {
3232
let modes_of_payments = aggregate(props.transactions, 'mode_of_payment', 'amount', 'pay')
33+
console.log(modes_of_payments)
3334
let results = []
3435
if (!(frm.value.doc && frm.value.settings)) {
3536
return
@@ -60,27 +61,25 @@ function calculate_totals() {
6061
})
6162
}
6263
63-
function aggregate(arr, on, who, filter) {
64-
const agg = arr.reduce((a, b) => {
65-
let whoValue = null
66-
const onValue = b[on]
67-
if (b[filter]) {
68-
whoValue = b[who]
69-
}
70-
if (a[onValue]) {
71-
a[onValue] = {
72-
[on]: onValue,
73-
[who]: [...a[onValue][who], whoValue],
64+
function aggregate(transactions, groupByField, valueField, filterField) {
65+
const groups = transactions
66+
.filter(transaction => transaction[filterField])
67+
.reduce((accumulator, transaction) => {
68+
let groupKey = transaction[groupByField]
69+
const value = transaction[valueField]
70+
if (!groupKey) {
71+
groupKey = 'None'
7472
}
75-
} else {
76-
a[onValue] = {
77-
[on]: onValue,
78-
[who]: [whoValue],
73+
if (!accumulator[groupKey]) {
74+
accumulator[groupKey] = {
75+
[groupByField]: groupKey,
76+
[valueField]: [],
77+
}
7978
}
80-
}
81-
return a
82-
}, {})
83-
return Object.values(agg)
79+
accumulator[groupKey][valueField].push(value)
80+
return accumulator
81+
}, {})
82+
return Object.values(groups)
8483
}
8584
</script>
8685
<style scoped>

check_run/public/js/check_run/check_run.js

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright (c) 2025, AgriTheory and contributors
2+
// For license information, please see license.txt
3+
14
import CheckRun from './CheckRun.vue'
25
import { createApp, reactive, ref, unref } from 'vue'
36

@@ -32,23 +35,38 @@ check_run.get_entries = frm => {
3235
}
3336

3437
check_run.mount = frm => {
35-
check_run.transactions = reactive({})
36-
check_run.modes_of_payment = ref([])
37-
check_run.filters = reactive({
38-
key: 'posting_date',
39-
posting_date: 1,
40-
mode_of_payment: 1,
41-
amount: 1,
42-
due_date: 1,
43-
party: '',
38+
return new Promise(async (resolve, reject) => {
39+
try {
40+
check_run.transactions = reactive({})
41+
check_run.modes_of_payment = ref([])
42+
check_run.filters = reactive({
43+
key: 'posting_date',
44+
posting_date: 1,
45+
mode_of_payment: 1,
46+
amount: 1,
47+
due_date: 1,
48+
party: '',
49+
})
50+
51+
if (frm.$check_run != undefined && frm.$check_run._isVue) {
52+
frm.$check_run.unmount()
53+
}
54+
55+
await check_run.get_entries(frm)
56+
$(frm.fields_dict['check_run_table'].wrapper).html($("<div id='check-run-vue'></div>").get(0))
57+
frm.$check_run = createApp(CheckRun)
58+
frm.$check_run.provide('$check_run', check_run)
59+
frm.$check_run.mount('#check-run-vue')
60+
61+
const { nextTick } = await import('vue')
62+
await nextTick()
63+
await new Promise(resolve => requestAnimationFrame(resolve))
64+
65+
resolve()
66+
} catch (error) {
67+
reject(error)
68+
}
4469
})
45-
if (frm.$check_run != undefined && frm.$check_run._isVue) {
46-
return
47-
}
48-
$(frm.fields_dict['check_run_table'].wrapper).html($("<div id='check-run-vue'></div>").get(0))
49-
frm.$check_run = createApp(CheckRun)
50-
frm.$check_run.mount('#check-run-vue')
51-
frm.$check_run.provide('$check_run', check_run)
5270
}
5371

5472
check_run.total = frm => {

0 commit comments

Comments
 (0)