Skip to content

Commit 49fadcb

Browse files
Mangesh-Khairnarnabinhait
authored andcommitted
fix(exchange-rate-revaluation): change create to view button on creation of journal entry (frappe#18202)
1 parent e6ab86e commit 49fadcb

1 file changed

Lines changed: 23 additions & 3 deletions

File tree

erpnext/accounts/doctype/exchange_rate_revaluation/exchange_rate_revaluation.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,29 @@ frappe.ui.form.on('Exchange Rate Revaluation', {
2121

2222
refresh: function(frm) {
2323
if(frm.doc.docstatus==1) {
24-
frm.add_custom_button(__('Make Journal Entry'), function() {
25-
return frm.events.make_jv(frm);
26-
});
24+
frappe.db.get_value("Journal Entry Account", {
25+
'reference_type': 'Exchange Rate Revaluation',
26+
'reference_name': frm.doc.name,
27+
'docstatus': 1
28+
}, "sum(debit) as sum", (r) =>{
29+
let total_amt = 0;
30+
frm.doc.accounts.forEach(d=> {
31+
total_amt = total_amt + d['new_balance_in_base_currency'];
32+
});
33+
if(total_amt === r.sum) {
34+
frm.add_custom_button(__("Journal Entry"), function(){
35+
frappe.route_options = {
36+
'reference_type': 'Exchange Rate Revaluation',
37+
'reference_name': frm.doc.name
38+
};
39+
frappe.set_route("List", "Journal Entry");
40+
}, __("View"));
41+
} else {
42+
frm.add_custom_button(__('Create Journal Entry'), function() {
43+
return frm.events.make_jv(frm);
44+
});
45+
}
46+
}, 'Journal Entry');
2747
}
2848
},
2949

0 commit comments

Comments
 (0)