feat: Journal Entry Template

This commit is contained in:
Abhishek Balam 2020-04-25 03:13:50 +05:30
parent 291837e63d
commit d64438ff47

View File

@ -13,8 +13,6 @@ frappe.ui.form.on("Journal Entry", {
refresh: function(frm) { refresh: function(frm) {
erpnext.toggle_naming_series(); erpnext.toggle_naming_series();
// frm.cscript.voucher_type(frm.doc); // frm.cscript.voucher_type(frm.doc);
cur_frm.set_df_property("cheque_no", "reqd", frm.doc.voucher_type=="Bank Entry");
cur_frm.set_df_property("cheque_date", "reqd", frm.doc.voucher_type=="Bank Entry");
if(frm.doc.docstatus==1) { if(frm.doc.docstatus==1) {
frm.add_custom_button(__('Ledger'), function() { frm.add_custom_button(__('Ledger'), function() {
@ -123,7 +121,10 @@ frappe.ui.form.on("Journal Entry", {
} }
}); });
}, },
voucher_type: function(frm){
frm.toggle_reqd("cheque_no", frm.doc.voucher_type=="Bank Entry");
frm.toggle_reqd("cheque_date", frm.doc.voucher_type=="Bank Entry");
},
from_template: function(frm){ from_template: function(frm){
var update_jv_details = function(doc, r) { var update_jv_details = function(doc, r) {
frappe.model.clear_table(frm.doc, "accounts"); frappe.model.clear_table(frm.doc, "accounts");
@ -403,55 +404,55 @@ cur_frm.cscript.select_print_heading = function(doc,cdt,cdn){
cur_frm.pformat.print_heading = __("Journal Entry"); cur_frm.pformat.print_heading = __("Journal Entry");
} }
cur_frm.cscript.voucher_type = function(doc, cdt, cdn) { // cur_frm.cscript.voucher_type = function(doc, cdt, cdn) {
cur_frm.set_df_property("cheque_no", "reqd", doc.voucher_type=="Bank Entry"); // cur_frm.set_df_property("cheque_no", "reqd", doc.voucher_type=="Bank Entry");
cur_frm.set_df_property("cheque_date", "reqd", doc.voucher_type=="Bank Entry"); // cur_frm.set_df_property("cheque_date", "reqd", doc.voucher_type=="Bank Entry");
if(!doc.company) return; // if(!doc.company) return;
var update_jv_details = function(doc, r) { // var update_jv_details = function(doc, r) {
$.each(r, function(i, d) { // $.each(r, function(i, d) {
var row = frappe.model.add_child(doc, "Journal Entry Account", "accounts"); // var row = frappe.model.add_child(doc, "Journal Entry Account", "accounts");
row.account = d.account; // row.account = d.account;
row.balance = d.balance; // row.balance = d.balance;
}); // });
refresh_field("accounts"); // refresh_field("accounts");
} // }
if((!(doc.accounts || []).length) || ((doc.accounts || []).length==1 && !doc.accounts[0].account)) { // if((!(doc.accounts || []).length) || ((doc.accounts || []).length==1 && !doc.accounts[0].account)) {
if(in_list(["Bank Entry", "Cash Entry"], doc.voucher_type)) { // if(in_list(["Bank Entry", "Cash Entry"], doc.voucher_type)) {
return frappe.call({ // return frappe.call({
type: "GET", // type: "GET",
method: "erpnext.accounts.doctype.journal_entry.journal_entry.get_default_bank_cash_account", // method: "erpnext.accounts.doctype.journal_entry.journal_entry.get_default_bank_cash_account",
args: { // args: {
"account_type": (doc.voucher_type=="Bank Entry" ? // "account_type": (doc.voucher_type=="Bank Entry" ?
"Bank" : (doc.voucher_type=="Cash Entry" ? "Cash" : null)), // "Bank" : (doc.voucher_type=="Cash Entry" ? "Cash" : null)),
"company": doc.company // "company": doc.company
}, // },
callback: function(r) { // callback: function(r) {
if(r.message) { // if(r.message) {
update_jv_details(doc, [r.message]); // update_jv_details(doc, [r.message]);
} // }
} // }
}) // })
} else if(doc.voucher_type=="Opening Entry") { // } else if(doc.voucher_type=="Opening Entry") {
return frappe.call({ // return frappe.call({
type:"GET", // type:"GET",
method: "erpnext.accounts.doctype.journal_entry.journal_entry.get_opening_accounts", // method: "erpnext.accounts.doctype.journal_entry.journal_entry.get_opening_accounts",
args: { // args: {
"company": doc.company // "company": doc.company
}, // },
callback: function(r) { // callback: function(r) {
frappe.model.clear_table(doc, "accounts"); // frappe.model.clear_table(doc, "accounts");
if(r.message) { // if(r.message) {
update_jv_details(doc, r.message); // update_jv_details(doc, r.message);
} // }
cur_frm.set_value("is_opening", "Yes") // cur_frm.set_value("is_opening", "Yes")
} // }
}) // })
} // }
} // }
} // }
frappe.ui.form.on("Journal Entry Account", { frappe.ui.form.on("Journal Entry Account", {
party: function(frm, cdt, cdn) { party: function(frm, cdt, cdn) {