From 0e1c27a362c6107d877a270bbe9f0a4e56ca82a8 Mon Sep 17 00:00:00 2001 From: John Kelley Date: Thu, 7 Jul 2022 11:11:13 -0600 Subject: [PATCH 1/3] fixes: check run table save and render on save --- check_run/check_run/doctype/check_run/check_run.js | 3 +-- check_run/check_run/doctype/check_run/check_run.json | 9 ++++++++- check_run/check_run/doctype/check_run/check_run.py | 6 +++--- check_run/public/js/check_run/check_run.js | 10 ++++------ 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/check_run/check_run/doctype/check_run/check_run.js b/check_run/check_run/doctype/check_run/check_run.js index cc41d85a..8ffb157f 100644 --- a/check_run/check_run/doctype/check_run/check_run.js +++ b/check_run/check_run/doctype/check_run/check_run.js @@ -92,7 +92,6 @@ function set_queries(frm){ function get_entries(frm){ frappe.xcall('check_run.check_run.doctype.check_run.check_run.get_entries', { doc: frm.doc} ).then((r) => { - console.log("TRANSACTIONS", frm.transactions.length, r.transactions.length) frm.transactions = r.transactions frm.modes_of_payment = r.modes_of_payment check_run.mount_table(frm) @@ -211,4 +210,4 @@ function reprint_checks(frm){ d.hide() }) d.show() -} \ No newline at end of file +} diff --git a/check_run/check_run/doctype/check_run/check_run.json b/check_run/check_run/doctype/check_run/check_run.json index 8a7d918f..274e17ff 100644 --- a/check_run/check_run/doctype/check_run/check_run.json +++ b/check_run/check_run/doctype/check_run/check_run.json @@ -22,6 +22,7 @@ "pay_to_account", "section_break_9", "check_run_table", + "html_15", "transactions", "amended_from", "print_count", @@ -143,13 +144,19 @@ "options": "Draft\nSubmitted\nConfirm Print\nPrinted" }, { + "default": "", "fieldname": "check_run_table", "fieldtype": "HTML" + }, + { + "default": "", + "fieldname": "html_15", + "fieldtype": "HTML" } ], "is_submittable": 1, "links": [], - "modified": "2022-07-04 05:50:56.817736", + "modified": "2022-07-07 11:07:40.783065", "modified_by": "Administrator", "module": "Check Run", "name": "Check Run", diff --git a/check_run/check_run/doctype/check_run/check_run.py b/check_run/check_run/doctype/check_run/check_run.py index bf9dc9ce..8e15737a 100644 --- a/check_run/check_run/doctype/check_run/check_run.py +++ b/check_run/check_run/doctype/check_run/check_run.py @@ -277,8 +277,8 @@ def get_entries(doc): if frappe.db.exists('Check Run', doc.name): db_doc = frappe.get_doc('Check Run', doc.name) print("dirty", db_doc.is_dirty(doc)) - if db_doc.docstatus > 0 or not db_doc.is_dirty(doc): - return {'transactions': json.loads(frappe.get_value('Check Run', doc.name, 'transactions')), 'modes_of_payment': modes_of_payment} + if db_doc.transactions and json.loads(db_doc.transactions): + return {'transactions': json.loads(db_doc.transactions), 'modes_of_payment': modes_of_payment} transactions = frappe.db.sql(""" ( SELECT @@ -319,7 +319,7 @@ def get_entries(doc): AND `tabExpense Claim`.payable_account = %(pay_to_account)s ) UNION ( - SELECT + SELECT 'Journal Entry' AS doctype, `tabJournal Entry`.name, `tabJournal Entry`.name AS ref_number, diff --git a/check_run/public/js/check_run/check_run.js b/check_run/public/js/check_run/check_run.js index 4b3e9d49..792bd711 100644 --- a/check_run/public/js/check_run/check_run.js +++ b/check_run/public/js/check_run/check_run.js @@ -7,9 +7,7 @@ check_run.mount_table = frm => { console.log('existing vue app') frm.check_run_state.docstatus = frm.doc.docstatus frm.check_run_state.transactions = frm.transactions - frm.check_run_state.modes_of_payment = state.modes_of_payment - frm.check_run_state.state = state - frm.$check_run.$forceUpdate() + frm.check_run_state.modes_of_payment = frm.check_run_state.modes_of_payment return } const state = Vue.observable({ @@ -21,7 +19,7 @@ check_run.mount_table = frm => { }) frm.check_run_state = state - // if (frm.$check_run instanceof Vue) { return } + frm.$check_run = new window.Vue({ el: $(frm.fields_dict['check_run_table'].wrapper).get(0), render: h => h( @@ -31,7 +29,7 @@ check_run.mount_table = frm => { modes_of_payment: state.modes_of_payment, // populate modes_of_payment select. doesn't get updated docstatus: state.docstatus, // used to conditionally render column inputs based on submission status. doesn't get updated state: state - } + } }) }) -} \ No newline at end of file +} From eabf8a55e9d2bd01fffdfbc6a24e41f8391a3981 Mon Sep 17 00:00:00 2001 From: John Kelley Date: Thu, 7 Jul 2022 13:46:58 -0600 Subject: [PATCH 2/3] fix: checkrun rerender on document change --- check_run/public/js/check_run/check_run.js | 29 ++++++++++------------ 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/check_run/public/js/check_run/check_run.js b/check_run/public/js/check_run/check_run.js index 792bd711..29cd540c 100644 --- a/check_run/public/js/check_run/check_run.js +++ b/check_run/public/js/check_run/check_run.js @@ -3,33 +3,30 @@ import CheckRun from './CheckRun.vue' frappe.provide('check_run') check_run.mount_table = frm => { - if (frm.$check_run instanceof Vue) { - console.log('existing vue app') - frm.check_run_state.docstatus = frm.doc.docstatus - frm.check_run_state.transactions = frm.transactions - frm.check_run_state.modes_of_payment = frm.check_run_state.modes_of_payment - return - } - const state = Vue.observable({ + frm.check_run_state = Vue.observable({ transactions: frm.transactions, party_filter: "", docstatus: frm.doc.docstatus, modes_of_payment: frm.modes_of_payment, show_party_filter: false }) - - frm.check_run_state = state - + if (frm.$check_run instanceof Vue) { + frm.$check_run.$destroy(); + } + $('#check-run-vue').remove() + $(frm.fields_dict['check_run_table'].wrapper).html($("
").get(0)); frm.$check_run = new window.Vue({ - el: $(frm.fields_dict['check_run_table'].wrapper).get(0), + el: $("#check-run-vue").get(0), render: h => h( CheckRun, { props: { - transactions: state.transactions, //list of transtactions - modes_of_payment: state.modes_of_payment, // populate modes_of_payment select. doesn't get updated - docstatus: state.docstatus, // used to conditionally render column inputs based on submission status. doesn't get updated - state: state + transactions: frm.check_run_state.transactions, //list of transtactions + modes_of_payment: frm.check_run_state.modes_of_payment, // populate modes_of_payment select. doesn't get updated + docstatus: frm.check_run_state.docstatus, // used to conditionally render column inputs based on submission status. doesn't get updated + state: frm.check_run_state } }) }) + + } From bc05bde2fdbe8feb852a8f851bf64ed2897d9d7d Mon Sep 17 00:00:00 2001 From: John Kelley Date: Fri, 8 Jul 2022 10:14:53 -0600 Subject: [PATCH 3/3] cleanup: removed default span in check_run_table, removed is_dirty function --- .../check_run/doctype/check_run/check_run.json | 3 +-- check_run/check_run/doctype/check_run/check_run.py | 14 -------------- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/check_run/check_run/doctype/check_run/check_run.json b/check_run/check_run/doctype/check_run/check_run.json index 274e17ff..b953152e 100644 --- a/check_run/check_run/doctype/check_run/check_run.json +++ b/check_run/check_run/doctype/check_run/check_run.json @@ -144,7 +144,6 @@ "options": "Draft\nSubmitted\nConfirm Print\nPrinted" }, { - "default": "", "fieldname": "check_run_table", "fieldtype": "HTML" }, @@ -156,7 +155,7 @@ ], "is_submittable": 1, "links": [], - "modified": "2022-07-07 11:07:40.783065", + "modified": "2022-07-08 10:10:39.971682", "modified_by": "Administrator", "module": "Check Run", "name": "Check Run", diff --git a/check_run/check_run/doctype/check_run/check_run.py b/check_run/check_run/doctype/check_run/check_run.py index 8e15737a..11789053 100644 --- a/check_run/check_run/doctype/check_run/check_run.py +++ b/check_run/check_run/doctype/check_run/check_run.py @@ -32,19 +32,6 @@ def validate(self): else: self.validate_last_check_number() - def is_dirty(self, doc): - dirty = False - for key in ('start_date', 'end_date', 'check_run_date', 'initial_check_number', 'company', 'bank_account', 'pay_to_account'): - if self.get(key) != doc.get(key): - return True - for db_row in json.loads(self.transactions): - for frm_row in doc.transactions: - if db_row.get('name') == frm_row.get('name'): - if db_row.get('mode_of_payment') != frm_row.get('mode_of_payment'): - return True - if db_row.get('pay') != frm_row.get('pay'): - return True - def set_status(self, status=None): if status: self.status = status @@ -276,7 +263,6 @@ def get_entries(doc): modes_of_payment = frappe.get_all('Mode of Payment', order_by='name') if frappe.db.exists('Check Run', doc.name): db_doc = frappe.get_doc('Check Run', doc.name) - print("dirty", db_doc.is_dirty(doc)) if db_doc.transactions and json.loads(db_doc.transactions): return {'transactions': json.loads(db_doc.transactions), 'modes_of_payment': modes_of_payment} transactions = frappe.db.sql("""