Code cleanup and improvements requested in PR:21404

This commit is contained in:
Abhishek Balam
2020-04-26 05:00:36 +05:30
parent 331bc0c366
commit 84187fb8e9
6 changed files with 156 additions and 213 deletions

View File

@@ -12,7 +12,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);
if(frm.doc.docstatus==1) { if(frm.doc.docstatus==1) {
frm.add_custom_button(__('Ledger'), function() { frm.add_custom_button(__('Ledger'), function() {
@@ -121,37 +120,82 @@ frappe.ui.form.on("Journal Entry", {
} }
}); });
}, },
voucher_type: function(frm){ voucher_type: function(frm){
frm.toggle_reqd("cheque_no", frm.doc.voucher_type=="Bank Entry"); frm.toggle_reqd("cheque_no", frm.doc.voucher_type=="Bank Entry");
frm.toggle_reqd("cheque_date", frm.doc.voucher_type=="Bank Entry"); frm.toggle_reqd("cheque_date", frm.doc.voucher_type=="Bank Entry");
},
from_template: function(frm){
var update_jv_details = function(doc, r) {
frappe.model.clear_table(frm.doc, "accounts");
$.each(r, function(i, d) {
var row = frappe.model.add_child(doc, "Journal Entry Account", "accounts");
row.account = d.account;
row.balance = d.balance;
});
refresh_field("accounts");
}
if(!frm.doc.company) return;
if(frm.)
if((!(frm.doc.accounts || []).length) || ((frm.doc.accounts || []).length==1 && !frm.doc.accounts[0].account)) {
if(in_list(["Bank Entry", "Cash Entry"], frm.doc.voucher_type)) {
return frappe.call({
type: "GET",
method: "erpnext.accounts.doctype.journal_entry.journal_entry.get_default_bank_cash_account",
args: {
"account_type": (frm.doc.voucher_type=="Bank Entry" ?
"Bank" : (frm.doc.voucher_type=="Cash Entry" ? "Cash" : null)),
"company": frm.doc.company
},
callback: function(r) {
if(r.message) {
// If default company bank account not set
if(!$.isEmptyObject(r.message)){
update_jv_details(frm.doc, [r.message]);
}
}
}
})
}
else if(frm.doc.voucher_type=="Opening Entry") {
return frappe.call({
type:"GET",
method: "erpnext.accounts.doctype.journal_entry.journal_entry.get_opening_accounts",
args: {
"company": frm.doc.company
},
callback: function(r) {
frappe.model.clear_table(frm.doc, "accounts");
if(r.message) {
update_jv_details(frm.doc, r.message);
}
cur_frm.set_value("is_opening", "Yes")
}
})
}
}
},
from_template: function(frm){
if (frm.doc.from_template){ if (frm.doc.from_template){
frappe.db.get_doc("Journal Entry Template", frm.doc.from_template) frappe.db.get_doc("Journal Entry Template", frm.doc.from_template)
.then((doc) => { .then((doc) => {
frm.set_value("company",doc.company); frappe.model.clear_table(frm.doc, "accounts");
frm.set_value("voucher_type", doc.voucher_type); frm.set_value({
frm.set_value("naming_series", doc.je_naming_series); "company": doc.company,
frm.set_value("is_opening", doc.is_opening); "voucher_type": doc.voucher_type,
update_jv_details(frm.doc, doc.accounts); "naming_series": doc.naming_series,
}) "is_opening": doc.is_opening
.catch((err)=>{ })
console.log(err); update_jv_details(frm.doc, doc.accounts);
}) })
.catch((err)=>{
console.log(err);
})
} }
} }
}); });
var update_jv_details = function(doc, r) {
$.each(r, function(i, d) {
var row = frappe.model.add_child(doc, "Journal Entry Account", "accounts");
row.account = d.account;
row.balance = d.balance;
});
refresh_field("accounts");
}
erpnext.accounts.JournalEntry = frappe.ui.form.Controller.extend({ erpnext.accounts.JournalEntry = frappe.ui.form.Controller.extend({
onload: function() { onload: function() {
this.load_defaults(); this.load_defaults();
@@ -404,56 +448,6 @@ 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.set_df_property("cheque_no", "reqd", doc.voucher_type=="Bank Entry");
// cur_frm.set_df_property("cheque_date", "reqd", doc.voucher_type=="Bank Entry");
// if(!doc.company) return;
// var update_jv_details = function(doc, r) {
// $.each(r, function(i, d) {
// var row = frappe.model.add_child(doc, "Journal Entry Account", "accounts");
// row.account = d.account;
// row.balance = d.balance;
// });
// refresh_field("accounts");
// }
// if((!(doc.accounts || []).length) || ((doc.accounts || []).length==1 && !doc.accounts[0].account)) {
// if(in_list(["Bank Entry", "Cash Entry"], doc.voucher_type)) {
// return frappe.call({
// type: "GET",
// method: "erpnext.accounts.doctype.journal_entry.journal_entry.get_default_bank_cash_account",
// args: {
// "account_type": (doc.voucher_type=="Bank Entry" ?
// "Bank" : (doc.voucher_type=="Cash Entry" ? "Cash" : null)),
// "company": doc.company
// },
// callback: function(r) {
// if(r.message) {
// update_jv_details(doc, [r.message]);
// }
// }
// })
// } else if(doc.voucher_type=="Opening Entry") {
// return frappe.call({
// type:"GET",
// method: "erpnext.accounts.doctype.journal_entry.journal_entry.get_opening_accounts",
// args: {
// "company": doc.company
// },
// callback: function(r) {
// frappe.model.clear_table(doc, "accounts");
// if(r.message) {
// update_jv_details(doc, r.message);
// }
// 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) {
var d = frappe.get_doc(cdt, cdn); var d = frappe.get_doc(cdt, cdn);

View File

@@ -491,14 +491,17 @@
"fieldname": "from_template", "fieldname": "from_template",
"fieldtype": "Link", "fieldtype": "Link",
"label": "From Template", "label": "From Template",
"options": "Journal Entry Template" "no_copy": 1,
"options": "Journal Entry Template",
"print_hide": 1,
"report_hide": 1
} }
], ],
"icon": "fa fa-file-text", "icon": "fa fa-file-text",
"idx": 176, "idx": 176,
"is_submittable": 1, "is_submittable": 1,
"links": [], "links": [],
"modified": "2020-04-25 02:02:04.017198", "modified": "2020-04-26 04:48:31.753820",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Accounts", "module": "Accounts",
"name": "Journal Entry", "name": "Journal Entry",

View File

@@ -2,23 +2,26 @@
// For license information, please see license.txt // For license information, please see license.txt
frappe.ui.form.on("Journal Entry Template", { frappe.ui.form.on("Journal Entry Template", {
// refresh: function(frm) {
// }
setup: function(frm) { setup: function(frm) {
frm.set_query("account" ,"accounts", () => { frappe.model.set_default_values(frm.doc);
return { frm.set_query("account" ,"accounts", function(){
filters: { return {
"company": frm.doc.company==undefined ? null: frm.doc.company, filters: {
} "company": frm.doc.company,
} }
}
});
frappe.call({
type: "GET",
method: "erpnext.accounts.doctype.journal_entry_template.journal_entry_template.get_naming_series",
callback: function(r){
if(r.message){
frm.set_df_property("naming_series", "options", r.message.split("\n"));
frm.set_value("naming_series", r.message.split("\n")[0]);
frm.refresh_field("naming_series");
}
}
}); });
},
onload_post_render: function(frm){
// frm.get_field("accounts").grid.set_multiple_add("account");
},
all_accounts: function(frm) {
frm.trigger("clear_child");
}, },
voucher_type: function(frm) { voucher_type: function(frm) {
var add_accounts = function(doc, r) { var add_accounts = function(doc, r) {
@@ -28,14 +31,13 @@ frappe.ui.form.on("Journal Entry Template", {
}); });
refresh_field("accounts"); refresh_field("accounts");
} }
if(!frm.doc.company) return;
frm.trigger("clear_child"); frm.trigger("clear_child");
switch(frm.doc.voucher_type){ switch(frm.doc.voucher_type){
case "Opening Entry": case "Opening Entry":
if(frm.doc.company == undefined){
frappe.throw("Please select Company!");
}
frm.set_value("is_opening", "Yes"); frm.set_value("is_opening", "Yes");
frappe.call({ 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",
@@ -61,10 +63,13 @@ frappe.ui.form.on("Journal Entry Template", {
}, },
callback: function(r) { callback: function(r) {
if(r.message) { if(r.message) {
add_accounts(frm.doc, [r.message]); // If default company bank account not set
if(!$.isEmptyObject(r.message)){
add_accounts(frm.doc, [r.message]);
}
} }
} }
}) });
break; break;
default: default:
frm.trigger("clear_child"); frm.trigger("clear_child");
@@ -72,6 +77,6 @@ frappe.ui.form.on("Journal Entry Template", {
}, },
clear_child: function(frm){ clear_child: function(frm){
frappe.model.clear_table(frm.doc, "accounts"); frappe.model.clear_table(frm.doc, "accounts");
refresh_field("accounts"); frm.refresh_field("accounts");
} }
}); });

View File

@@ -1,18 +1,21 @@
{ {
"actions": [], "actions": [],
"autoname": "naming_series:", "autoname": "field:template_title",
"creation": "2020-04-09 01:32:51.332301", "creation": "2020-04-09 01:32:51.332301",
"doctype": "DocType", "doctype": "DocType",
"document_type": "Document",
"editable_grid": 1, "editable_grid": 1,
"engine": "InnoDB", "engine": "InnoDB",
"field_order": [ "field_order": [
"section_break_1", "section_break_1",
"voucher_type", "template_title",
"company",
"column_break_3",
"je_naming_series",
"is_opening",
"section_break_2", "section_break_2",
"company",
"voucher_type",
"column_break_3",
"naming_series",
"is_opening",
"section_break_3",
"accounts" "accounts"
], ],
"fields": [ "fields": [
@@ -32,20 +35,16 @@
"fieldname": "company", "fieldname": "company",
"fieldtype": "Link", "fieldtype": "Link",
"in_list_view": 1, "in_list_view": 1,
"in_standard_filter": 1,
"label": "Company", "label": "Company",
"options": "Company", "options": "Company",
"remember_last_selected_value": 1,
"reqd": 1 "reqd": 1
}, },
{ {
"fieldname": "column_break_3", "fieldname": "column_break_3",
"fieldtype": "Column Break" "fieldtype": "Column Break"
}, },
{
"default": "ACC-JV-.YYYY.-",
"fieldname": "je_naming_series",
"fieldtype": "Data",
"label": "Naming Series"
},
{ {
"default": "No", "default": "No",
"fieldname": "is_opening", "fieldname": "is_opening",
@@ -61,28 +60,36 @@
"fieldname": "accounts", "fieldname": "accounts",
"fieldtype": "Table", "fieldtype": "Table",
"label": "Accounting Entries", "label": "Accounting Entries",
"options": "JE Template Account" "options": "Journal Entry Template Account"
},
{
"fieldname": "naming_series",
"fieldtype": "Select",
"label": "Series",
"no_copy": 1,
"print_hide": 1,
"reqd": 1,
"set_only_once": 1
},
{
"fieldname": "template_title",
"fieldtype": "Data",
"label": "Template Title",
"reqd": 1,
"unique": 1
},
{
"fieldname": "section_break_3",
"fieldtype": "Section Break"
} }
], ],
"links": [], "links": [],
"modified": "2020-04-25 02:14:35.185062", "modified": "2020-04-26 04:29:03.347852",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Accounts", "module": "Accounts",
"name": "Journal Entry Template", "name": "Journal Entry Template",
"owner": "Administrator", "owner": "Administrator",
"permissions": [ "permissions": [
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "System Manager",
"share": 1,
"write": 1
},
{ {
"create": 1, "create": 1,
"delete": 1, "delete": 1,
@@ -106,9 +113,20 @@
"role": "Accounts Manager", "role": "Accounts Manager",
"share": 1, "share": 1,
"write": 1 "write": 1
},
{
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "Auditor",
"share": 1
} }
], ],
"search_fields": "voucher_type, company",
"sort_field": "modified", "sort_field": "modified",
"sort_order": "DESC", "sort_order": "DESC",
"title_field": "template_title",
"track_changes": 1 "track_changes": 1
} }

View File

@@ -5,9 +5,10 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe import frappe
from frappe.model.document import Document from frappe.model.document import Document
from erpnext.accounts.utils import get_balance_on
class JournalEntryTemplate(Document): class JournalEntryTemplate(Document):
def autoname(self): pass
self.name = self.voucher_type + ' - ' + frappe.get_value('Company', self.company, 'abbr')
@frappe.whitelist()
def get_naming_series():
return frappe.get_meta("Journal Entry").get_field("naming_series").options

View File

@@ -1,130 +1,52 @@
{ {
"allow_copy": 0, "actions": [],
"allow_events_in_timeline": 0,
"allow_guest_to_view": 0,
"allow_import": 0,
"allow_rename": 0,
"autoname": "Prompt", "autoname": "Prompt",
"beta": 0,
"creation": "2019-02-18 17:23:11.708371", "creation": "2019-02-18 17:23:11.708371",
"custom": 0,
"docstatus": 0,
"doctype": "DocType", "doctype": "DocType",
"document_type": "",
"editable_grid": 1, "editable_grid": 1,
"engine": "InnoDB", "engine": "InnoDB",
"field_order": [
"project_type",
"tasks"
],
"fields": [ "fields": [
{ {
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "project_type", "fieldname": "project_type",
"fieldtype": "Link", "fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1, "in_list_view": 1,
"in_standard_filter": 0,
"label": "Project Type", "label": "Project Type",
"length": 0, "options": "Project Type"
"no_copy": 0,
"options": "Project Type",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
}, },
{ {
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "tasks", "fieldname": "tasks",
"fieldtype": "Table", "fieldtype": "Table",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_standard_filter": 0,
"label": "Tasks", "label": "Tasks",
"length": 0,
"no_copy": 0,
"options": "Project Template Task", "options": "Project Template Task",
"permlevel": 0, "reqd": 1
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
} }
], ],
"has_web_view": 0, "links": [],
"hide_heading": 0, "modified": "2020-04-26 02:23:53.990322",
"hide_toolbar": 0,
"idx": 0,
"image_view": 0,
"in_create": 0,
"is_submittable": 0,
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2019-02-18 18:01:26.519832",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Projects", "module": "Projects",
"name": "Project Template", "name": "Project Template",
"name_case": "",
"owner": "Administrator", "owner": "Administrator",
"permissions": [ "permissions": [
{ {
"amend": 0,
"cancel": 0,
"create": 1, "create": 1,
"delete": 1, "delete": 1,
"email": 1, "email": 1,
"export": 1, "export": 1,
"if_owner": 0,
"import": 0,
"permlevel": 0,
"print": 1, "print": 1,
"read": 1, "read": 1,
"report": 1, "report": 1,
"role": "System Manager", "role": "System Manager",
"set_user_permissions": 0,
"share": 1, "share": 1,
"submit": 0,
"write": 1 "write": 1
} }
], ],
"quick_entry": 1, "quick_entry": 1,
"read_only": 0,
"read_only_onload": 0,
"show_name_in_global_search": 0,
"sort_field": "modified", "sort_field": "modified",
"sort_order": "DESC", "sort_order": "DESC",
"track_changes": 1, "track_changes": 1
"track_seen": 0,
"track_views": 0
} }