From 7bbb77e66faa1e8e149167b65857620a58e9f276 Mon Sep 17 00:00:00 2001 From: Abhishek Balam Date: Sat, 25 Apr 2020 02:45:45 +0530 Subject: [PATCH 01/10] feat: Journal Entry Template --- .../doctype/je_template_account/__init__.py | 0 .../je_template_account.json | 31 +++++ .../je_template_account.py | 10 ++ .../doctype/journal_entry/journal_entry.js | 32 ++++- .../doctype/journal_entry/journal_entry.json | 11 +- .../journal_entry_account.json | 6 +- .../journal_entry_template/__init__.py | 0 .../journal_entry_template.js | 77 ++++++++++++ .../journal_entry_template.json | 114 ++++++++++++++++++ .../journal_entry_template.py | 13 ++ .../test_journal_entry_template.py | 10 ++ 11 files changed, 299 insertions(+), 5 deletions(-) create mode 100644 erpnext/accounts/doctype/je_template_account/__init__.py create mode 100644 erpnext/accounts/doctype/je_template_account/je_template_account.json create mode 100644 erpnext/accounts/doctype/je_template_account/je_template_account.py create mode 100644 erpnext/accounts/doctype/journal_entry_template/__init__.py create mode 100644 erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js create mode 100644 erpnext/accounts/doctype/journal_entry_template/journal_entry_template.json create mode 100644 erpnext/accounts/doctype/journal_entry_template/journal_entry_template.py create mode 100644 erpnext/accounts/doctype/journal_entry_template/test_journal_entry_template.py diff --git a/erpnext/accounts/doctype/je_template_account/__init__.py b/erpnext/accounts/doctype/je_template_account/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/erpnext/accounts/doctype/je_template_account/je_template_account.json b/erpnext/accounts/doctype/je_template_account/je_template_account.json new file mode 100644 index 00000000000..748261d2fb7 --- /dev/null +++ b/erpnext/accounts/doctype/je_template_account/je_template_account.json @@ -0,0 +1,31 @@ +{ + "actions": [], + "creation": "2020-04-09 01:48:42.783620", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "account" + ], + "fields": [ + { + "fieldname": "account", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Account", + "options": "Account", + "reqd": 1 + } + ], + "istable": 1, + "links": [], + "modified": "2020-04-25 01:15:44.879839", + "modified_by": "Administrator", + "module": "Accounts", + "name": "JE Template Account", + "owner": "Administrator", + "permissions": [], + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 +} \ No newline at end of file diff --git a/erpnext/accounts/doctype/je_template_account/je_template_account.py b/erpnext/accounts/doctype/je_template_account/je_template_account.py new file mode 100644 index 00000000000..fa73f223219 --- /dev/null +++ b/erpnext/accounts/doctype/je_template_account/je_template_account.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +# import frappe +from frappe.model.document import Document + +class JETemplateAccount(Document): + pass diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.js b/erpnext/accounts/doctype/journal_entry/journal_entry.js index 3604b60b751..d6d77e87bb0 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.js +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.js @@ -12,8 +12,10 @@ frappe.ui.form.on("Journal Entry", { refresh: function(frm) { 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) { frm.add_custom_button(__('Ledger'), function() { frappe.route_options = { @@ -120,6 +122,32 @@ frappe.ui.form.on("Journal 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.from_template){ + frappe.db.get_doc("Journal Entry Template", frm.doc.from_template) + .then((doc) => { + frm.set_value("company",doc.company); + frm.set_value("voucher_type", doc.voucher_type); + frm.set_value("naming_series", doc.je_naming_series); + frm.set_value("is_opening", doc.is_opening); + update_jv_details(frm.doc, doc.accounts); + }) + .catch((err)=>{ + console.log(err); + }) + } } }); diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.json b/erpnext/accounts/doctype/journal_entry/journal_entry.json index f5991241a72..b943452a704 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.json +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.json @@ -1,4 +1,5 @@ { + "actions": [], "allow_import": 1, "autoname": "naming_series:", "creation": "2013-03-25 10:53:52", @@ -10,6 +11,7 @@ "title", "voucher_type", "naming_series", + "from_template", "column_break1", "posting_date", "company", @@ -484,12 +486,19 @@ "options": "Journal Entry", "print_hide": 1, "read_only": 1 + }, + { + "fieldname": "from_template", + "fieldtype": "Link", + "label": "From Template", + "options": "Journal Entry Template" } ], "icon": "fa fa-file-text", "idx": 176, "is_submittable": 1, - "modified": "2020-01-16 13:05:30.634226", + "links": [], + "modified": "2020-04-25 02:02:04.017198", "modified_by": "Administrator", "module": "Accounts", "name": "Journal Entry", diff --git a/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json b/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json index 9552e60a857..26c84a6398c 100644 --- a/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json +++ b/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json @@ -1,4 +1,5 @@ { + "actions": [], "autoname": "hash", "creation": "2013-02-22 01:27:39", "doctype": "DocType", @@ -271,7 +272,8 @@ ], "idx": 1, "istable": 1, - "modified": "2020-01-13 12:41:33.968025", + "links": [], + "modified": "2020-04-25 01:47:49.060128", "modified_by": "Administrator", "module": "Accounts", "name": "Journal Entry Account", @@ -280,4 +282,4 @@ "sort_field": "modified", "sort_order": "DESC", "track_changes": 1 -} +} \ No newline at end of file diff --git a/erpnext/accounts/doctype/journal_entry_template/__init__.py b/erpnext/accounts/doctype/journal_entry_template/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js b/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js new file mode 100644 index 00000000000..959267774d1 --- /dev/null +++ b/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js @@ -0,0 +1,77 @@ +// Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors +// For license information, please see license.txt + +frappe.ui.form.on("Journal Entry Template", { + // refresh: function(frm) { + + // } + setup: function(frm) { + frm.set_query("account" ,"accounts", () => { + return { + filters: { + "company": frm.doc.company==undefined ? null: frm.doc.company, + } + } + }); + }, + 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) { + var add_accounts = function(doc, r) { + $.each(r, function(i, d) { + var row = frappe.model.add_child(doc, "JE Template Account", "accounts"); + row.account = d.account; + }); + refresh_field("accounts"); + } + frm.trigger("clear_child"); + switch(frm.doc.voucher_type){ + case "Opening Entry": + if(frm.doc.company == undefined){ + frappe.throw("Please select Company!"); + } + frm.set_value("is_opening", "Yes"); + + frappe.call({ + type:"GET", + method: "erpnext.accounts.doctype.journal_entry.journal_entry.get_opening_accounts", + args: { + "company": frm.doc.company + }, + callback: function(r) { + if(r.message) { + add_accounts(frm.doc, r.message); + } + } + }) + break; + case "Bank Entry": + case "Cash Entry": + 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) { + add_accounts(frm.doc, [r.message]); + } + } + }) + break; + default: + frm.trigger("clear_child"); + } + }, + clear_child: function(frm){ + frappe.model.clear_table(frm.doc, "accounts"); + refresh_field("accounts"); + } +}); diff --git a/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.json b/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.json new file mode 100644 index 00000000000..a16503e893c --- /dev/null +++ b/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.json @@ -0,0 +1,114 @@ +{ + "actions": [], + "autoname": "naming_series:", + "creation": "2020-04-09 01:32:51.332301", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "section_break_1", + "voucher_type", + "company", + "column_break_3", + "je_naming_series", + "is_opening", + "section_break_2", + "accounts" + ], + "fields": [ + { + "fieldname": "section_break_1", + "fieldtype": "Section Break" + }, + { + "fieldname": "voucher_type", + "fieldtype": "Select", + "in_list_view": 1, + "label": "Journal Entry Type", + "options": "Journal Entry\nInter Company Journal Entry\nBank Entry\nCash Entry\nCredit Card Entry\nDebit Note\nCredit Note\nContra Entry\nExcise Entry\nWrite Off Entry\nOpening Entry\nDepreciation Entry\nExchange Rate Revaluation", + "reqd": 1 + }, + { + "fieldname": "company", + "fieldtype": "Link", + "in_list_view": 1, + "label": "Company", + "options": "Company", + "reqd": 1 + }, + { + "fieldname": "column_break_3", + "fieldtype": "Column Break" + }, + { + "default": "ACC-JV-.YYYY.-", + "fieldname": "je_naming_series", + "fieldtype": "Data", + "label": "Naming Series" + }, + { + "default": "No", + "fieldname": "is_opening", + "fieldtype": "Select", + "label": "Is Opening", + "options": "No\nYes" + }, + { + "fieldname": "section_break_2", + "fieldtype": "Section Break" + }, + { + "fieldname": "accounts", + "fieldtype": "Table", + "label": "Accounting Entries", + "options": "JE Template Account" + } + ], + "links": [], + "modified": "2020-04-25 02:14:35.185062", + "modified_by": "Administrator", + "module": "Accounts", + "name": "Journal Entry Template", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "share": 1, + "write": 1 + }, + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Accounts User", + "share": 1, + "write": 1 + }, + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Accounts Manager", + "share": 1, + "write": 1 + } + ], + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1 +} \ No newline at end of file diff --git a/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.py b/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.py new file mode 100644 index 00000000000..d576832c3bd --- /dev/null +++ b/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +import frappe +from frappe.model.document import Document +from erpnext.accounts.utils import get_balance_on + +class JournalEntryTemplate(Document): + def autoname(self): + self.name = self.voucher_type + ' - ' + frappe.get_value('Company', self.company, 'abbr') + diff --git a/erpnext/accounts/doctype/journal_entry_template/test_journal_entry_template.py b/erpnext/accounts/doctype/journal_entry_template/test_journal_entry_template.py new file mode 100644 index 00000000000..5f74a2042fd --- /dev/null +++ b/erpnext/accounts/doctype/journal_entry_template/test_journal_entry_template.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors +# See license.txt +from __future__ import unicode_literals + +# import frappe +import unittest + +class TestJournalEntryTemplate(unittest.TestCase): + pass From d64438ff473deb2c50fc44ab9105aef8ccad38f7 Mon Sep 17 00:00:00 2001 From: Abhishek Balam Date: Sat, 25 Apr 2020 03:13:50 +0530 Subject: [PATCH 02/10] feat: Journal Entry Template --- .../doctype/journal_entry/journal_entry.js | 99 ++++++++++--------- 1 file changed, 50 insertions(+), 49 deletions(-) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.js b/erpnext/accounts/doctype/journal_entry/journal_entry.js index d6d77e87bb0..a99ec70fd73 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.js +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.js @@ -13,8 +13,6 @@ frappe.ui.form.on("Journal Entry", { refresh: function(frm) { erpnext.toggle_naming_series(); // 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) { 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){ var update_jv_details = function(doc, r) { 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.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"); +// 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; +// 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"); - } +// 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") - } - }) - } - } -} +// 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", { party: function(frm, cdt, cdn) { From 539c67966f3d9cce41eded7c87a1f29f3ad24294 Mon Sep 17 00:00:00 2001 From: Abhishek Balam Date: Sat, 25 Apr 2020 18:13:01 +0530 Subject: [PATCH 03/10] rename je template account dt --- .../doctype/journal_entry_template/journal_entry_template.js | 2 +- .../__init__.py | 0 .../journal_entry_template_account.json} | 2 +- .../journal_entry_template_account.py} | 2 +- 4 files changed, 3 insertions(+), 3 deletions(-) rename erpnext/accounts/doctype/{je_template_account => journal_entry_template_account}/__init__.py (100%) rename erpnext/accounts/doctype/{je_template_account/je_template_account.json => journal_entry_template_account/journal_entry_template_account.json} (92%) rename erpnext/accounts/doctype/{je_template_account/je_template_account.py => journal_entry_template_account/journal_entry_template_account.py} (84%) diff --git a/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js b/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js index 959267774d1..153392dedce 100644 --- a/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js +++ b/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js @@ -23,7 +23,7 @@ frappe.ui.form.on("Journal Entry Template", { voucher_type: function(frm) { var add_accounts = function(doc, r) { $.each(r, function(i, d) { - var row = frappe.model.add_child(doc, "JE Template Account", "accounts"); + var row = frappe.model.add_child(doc, "Journal Entry Template Account", "accounts"); row.account = d.account; }); refresh_field("accounts"); diff --git a/erpnext/accounts/doctype/je_template_account/__init__.py b/erpnext/accounts/doctype/journal_entry_template_account/__init__.py similarity index 100% rename from erpnext/accounts/doctype/je_template_account/__init__.py rename to erpnext/accounts/doctype/journal_entry_template_account/__init__.py diff --git a/erpnext/accounts/doctype/je_template_account/je_template_account.json b/erpnext/accounts/doctype/journal_entry_template_account/journal_entry_template_account.json similarity index 92% rename from erpnext/accounts/doctype/je_template_account/je_template_account.json rename to erpnext/accounts/doctype/journal_entry_template_account/journal_entry_template_account.json index 748261d2fb7..eecd87727d4 100644 --- a/erpnext/accounts/doctype/je_template_account/je_template_account.json +++ b/erpnext/accounts/doctype/journal_entry_template_account/journal_entry_template_account.json @@ -22,7 +22,7 @@ "modified": "2020-04-25 01:15:44.879839", "modified_by": "Administrator", "module": "Accounts", - "name": "JE Template Account", + "name": "Journal Entry Template Account", "owner": "Administrator", "permissions": [], "sort_field": "modified", diff --git a/erpnext/accounts/doctype/je_template_account/je_template_account.py b/erpnext/accounts/doctype/journal_entry_template_account/journal_entry_template_account.py similarity index 84% rename from erpnext/accounts/doctype/je_template_account/je_template_account.py rename to erpnext/accounts/doctype/journal_entry_template_account/journal_entry_template_account.py index fa73f223219..48e6abbc284 100644 --- a/erpnext/accounts/doctype/je_template_account/je_template_account.py +++ b/erpnext/accounts/doctype/journal_entry_template_account/journal_entry_template_account.py @@ -6,5 +6,5 @@ from __future__ import unicode_literals # import frappe from frappe.model.document import Document -class JETemplateAccount(Document): +class JournalEntryTemplateAccount(Document): pass From 84187fb8e978b2dcbb700ab6774fa4cf70928340 Mon Sep 17 00:00:00 2001 From: Abhishek Balam Date: Sun, 26 Apr 2020 05:00:36 +0530 Subject: [PATCH 04/10] Code cleanup and improvements requested in PR:21404 --- .../doctype/journal_entry/journal_entry.js | 138 +++++++++--------- .../doctype/journal_entry/journal_entry.json | 7 +- .../journal_entry_template.js | 49 ++++--- .../journal_entry_template.json | 70 +++++---- .../journal_entry_template.py | 7 +- .../project_template/project_template.json | 98 ++----------- 6 files changed, 156 insertions(+), 213 deletions(-) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.js b/erpnext/accounts/doctype/journal_entry/journal_entry.js index a99ec70fd73..a6ef4942fbd 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.js +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.js @@ -12,7 +12,6 @@ frappe.ui.form.on("Journal Entry", { refresh: function(frm) { erpnext.toggle_naming_series(); - // frm.cscript.voucher_type(frm.doc); if(frm.doc.docstatus==1) { frm.add_custom_button(__('Ledger'), function() { @@ -121,37 +120,82 @@ 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){ - 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){ frappe.db.get_doc("Journal Entry Template", frm.doc.from_template) - .then((doc) => { - frm.set_value("company",doc.company); - frm.set_value("voucher_type", doc.voucher_type); - frm.set_value("naming_series", doc.je_naming_series); - frm.set_value("is_opening", doc.is_opening); - update_jv_details(frm.doc, doc.accounts); - }) - .catch((err)=>{ - console.log(err); - }) + .then((doc) => { + frappe.model.clear_table(frm.doc, "accounts"); + frm.set_value({ + "company": doc.company, + "voucher_type": doc.voucher_type, + "naming_series": doc.naming_series, + "is_opening": doc.is_opening + }) + 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({ onload: function() { 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.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", { party: function(frm, cdt, cdn) { var d = frappe.get_doc(cdt, cdn); diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.json b/erpnext/accounts/doctype/journal_entry/journal_entry.json index b943452a704..2335109847c 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.json +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.json @@ -491,14 +491,17 @@ "fieldname": "from_template", "fieldtype": "Link", "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", "idx": 176, "is_submittable": 1, "links": [], - "modified": "2020-04-25 02:02:04.017198", + "modified": "2020-04-26 04:48:31.753820", "modified_by": "Administrator", "module": "Accounts", "name": "Journal Entry", diff --git a/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js b/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js index 153392dedce..3dc66aaa584 100644 --- a/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js +++ b/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js @@ -2,23 +2,26 @@ // For license information, please see license.txt frappe.ui.form.on("Journal Entry Template", { - // refresh: function(frm) { - - // } setup: function(frm) { - frm.set_query("account" ,"accounts", () => { - return { - filters: { - "company": frm.doc.company==undefined ? null: frm.doc.company, - } + frappe.model.set_default_values(frm.doc); + frm.set_query("account" ,"accounts", function(){ + return { + 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) { var add_accounts = function(doc, r) { @@ -28,14 +31,13 @@ frappe.ui.form.on("Journal Entry Template", { }); refresh_field("accounts"); } + + if(!frm.doc.company) return; + frm.trigger("clear_child"); switch(frm.doc.voucher_type){ case "Opening Entry": - if(frm.doc.company == undefined){ - frappe.throw("Please select Company!"); - } frm.set_value("is_opening", "Yes"); - frappe.call({ type:"GET", 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) { 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; default: frm.trigger("clear_child"); @@ -72,6 +77,6 @@ frappe.ui.form.on("Journal Entry Template", { }, clear_child: function(frm){ frappe.model.clear_table(frm.doc, "accounts"); - refresh_field("accounts"); + frm.refresh_field("accounts"); } -}); +}); \ No newline at end of file diff --git a/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.json b/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.json index a16503e893c..3f6cb026aa6 100644 --- a/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.json +++ b/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.json @@ -1,18 +1,21 @@ { "actions": [], - "autoname": "naming_series:", + "autoname": "field:template_title", "creation": "2020-04-09 01:32:51.332301", "doctype": "DocType", + "document_type": "Document", "editable_grid": 1, "engine": "InnoDB", "field_order": [ "section_break_1", - "voucher_type", - "company", - "column_break_3", - "je_naming_series", - "is_opening", + "template_title", "section_break_2", + "company", + "voucher_type", + "column_break_3", + "naming_series", + "is_opening", + "section_break_3", "accounts" ], "fields": [ @@ -32,20 +35,16 @@ "fieldname": "company", "fieldtype": "Link", "in_list_view": 1, + "in_standard_filter": 1, "label": "Company", "options": "Company", + "remember_last_selected_value": 1, "reqd": 1 }, { "fieldname": "column_break_3", "fieldtype": "Column Break" }, - { - "default": "ACC-JV-.YYYY.-", - "fieldname": "je_naming_series", - "fieldtype": "Data", - "label": "Naming Series" - }, { "default": "No", "fieldname": "is_opening", @@ -61,28 +60,36 @@ "fieldname": "accounts", "fieldtype": "Table", "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": [], - "modified": "2020-04-25 02:14:35.185062", + "modified": "2020-04-26 04:29:03.347852", "modified_by": "Administrator", "module": "Accounts", "name": "Journal Entry Template", "owner": "Administrator", "permissions": [ - { - "create": 1, - "delete": 1, - "email": 1, - "export": 1, - "print": 1, - "read": 1, - "report": 1, - "role": "System Manager", - "share": 1, - "write": 1 - }, { "create": 1, "delete": 1, @@ -106,9 +113,20 @@ "role": "Accounts Manager", "share": 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_order": "DESC", + "title_field": "template_title", "track_changes": 1 } \ No newline at end of file diff --git a/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.py b/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.py index d576832c3bd..e0b9cbc9193 100644 --- a/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.py +++ b/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.py @@ -5,9 +5,10 @@ from __future__ import unicode_literals import frappe from frappe.model.document import Document -from erpnext.accounts.utils import get_balance_on class JournalEntryTemplate(Document): - def autoname(self): - self.name = self.voucher_type + ' - ' + frappe.get_value('Company', self.company, 'abbr') + pass +@frappe.whitelist() +def get_naming_series(): + return frappe.get_meta("Journal Entry").get_field("naming_series").options diff --git a/erpnext/projects/doctype/project_template/project_template.json b/erpnext/projects/doctype/project_template/project_template.json index 8352995face..445ad9f2386 100644 --- a/erpnext/projects/doctype/project_template/project_template.json +++ b/erpnext/projects/doctype/project_template/project_template.json @@ -1,130 +1,52 @@ { - "allow_copy": 0, - "allow_events_in_timeline": 0, - "allow_guest_to_view": 0, - "allow_import": 0, - "allow_rename": 0, + "actions": [], "autoname": "Prompt", - "beta": 0, "creation": "2019-02-18 17:23:11.708371", - "custom": 0, - "docstatus": 0, "doctype": "DocType", - "document_type": "", "editable_grid": 1, "engine": "InnoDB", + "field_order": [ + "project_type", + "tasks" + ], "fields": [ { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fieldname": "project_type", "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, "in_list_view": 1, - "in_standard_filter": 0, "label": "Project Type", - "length": 0, - "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 + "options": "Project Type" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fieldname": "tasks", "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", - "length": 0, - "no_copy": 0, "options": "Project Template Task", - "permlevel": 0, - "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 + "reqd": 1 } ], - "has_web_view": 0, - "hide_heading": 0, - "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", + "links": [], + "modified": "2020-04-26 02:23:53.990322", "modified_by": "Administrator", "module": "Projects", "name": "Project Template", - "name_case": "", "owner": "Administrator", "permissions": [ { - "amend": 0, - "cancel": 0, "create": 1, "delete": 1, "email": 1, "export": 1, - "if_owner": 0, - "import": 0, - "permlevel": 0, "print": 1, "read": 1, "report": 1, "role": "System Manager", - "set_user_permissions": 0, "share": 1, - "submit": 0, "write": 1 } ], "quick_entry": 1, - "read_only": 0, - "read_only_onload": 0, - "show_name_in_global_search": 0, "sort_field": "modified", "sort_order": "DESC", - "track_changes": 1, - "track_seen": 0, - "track_views": 0 + "track_changes": 1 } \ No newline at end of file From e4e23836e78425eb2db27b993878989f12219168 Mon Sep 17 00:00:00 2001 From: Abhishek Balam Date: Sun, 26 Apr 2020 13:06:55 +0530 Subject: [PATCH 05/10] mandatory depends on for cheque no and date, fix typo --- erpnext/accounts/doctype/journal_entry/journal_entry.js | 5 +---- erpnext/accounts/doctype/journal_entry/journal_entry.json | 4 +++- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.js b/erpnext/accounts/doctype/journal_entry/journal_entry.js index a6ef4942fbd..0e5eee4186a 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.js +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.js @@ -122,12 +122,9 @@ 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"); 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({ diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.json b/erpnext/accounts/doctype/journal_entry/journal_entry.json index 2335109847c..7892042bb9f 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.json +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.json @@ -159,6 +159,7 @@ "in_global_search": 1, "in_list_view": 1, "label": "Reference Number", + "mandatory_depends_on": "eval:doc.voucher_type == \"Bank Entry\"", "no_copy": 1, "oldfieldname": "cheque_no", "oldfieldtype": "Data", @@ -168,6 +169,7 @@ "fieldname": "cheque_date", "fieldtype": "Date", "label": "Reference Date", + "mandatory_depends_on": "eval:doc.voucher_type == \"Bank Entry\"", "no_copy": 1, "oldfieldname": "cheque_date", "oldfieldtype": "Date", @@ -501,7 +503,7 @@ "idx": 176, "is_submittable": 1, "links": [], - "modified": "2020-04-26 04:48:31.753820", + "modified": "2020-04-26 13:04:05.230155", "modified_by": "Administrator", "module": "Accounts", "name": "Journal Entry", From 8dbc4e648b5a52a06bc87d66e11ef7e98a4a2492 Mon Sep 17 00:00:00 2001 From: Abhishek Balam Date: Wed, 29 Apr 2020 11:13:55 +0530 Subject: [PATCH 06/10] rearranged fields in journal entry and journal entry type --- .../doctype/journal_entry/journal_entry.js | 17 +++++++---------- .../doctype/journal_entry/journal_entry.json | 10 +++++----- .../journal_entry_template.js | 4 ++-- .../journal_entry_template.json | 11 +++-------- 4 files changed, 17 insertions(+), 25 deletions(-) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.js b/erpnext/accounts/doctype/journal_entry/journal_entry.js index 0e5eee4186a..2e5d6b3847b 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.js +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.js @@ -123,9 +123,9 @@ frappe.ui.form.on("Journal Entry", { voucher_type: function(frm){ - if(!frm.doc.company) return; - - if((!(frm.doc.accounts || []).length) || ((frm.doc.accounts || []).length==1 && !frm.doc.accounts[0].account)) { + if(!frm.doc.company) return null; + + 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", @@ -143,7 +143,7 @@ frappe.ui.form.on("Journal Entry", { } } } - }) + }); } else if(frm.doc.voucher_type=="Opening Entry") { return frappe.call({ @@ -157,9 +157,9 @@ frappe.ui.form.on("Journal Entry", { if(r.message) { update_jv_details(frm.doc, r.message); } - cur_frm.set_value("is_opening", "Yes") + cur_frm.set_value("is_opening", "Yes"); } - }) + }); } } }, @@ -176,10 +176,7 @@ frappe.ui.form.on("Journal Entry", { "is_opening": doc.is_opening }) update_jv_details(frm.doc, doc.accounts); - }) - .catch((err)=>{ - console.log(err); - }) + }); } } }); diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.json b/erpnext/accounts/doctype/journal_entry/journal_entry.json index 7892042bb9f..9d5063929fd 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.json +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.json @@ -11,11 +11,11 @@ "title", "voucher_type", "naming_series", - "from_template", - "column_break1", - "posting_date", - "company", "finance_book", + "column_break1", + "from_template", + "company", + "posting_date", "2_add_edit_gl_entries", "accounts", "section_break99", @@ -503,7 +503,7 @@ "idx": 176, "is_submittable": 1, "links": [], - "modified": "2020-04-26 13:04:05.230155", + "modified": "2020-04-29 10:55:28.240916", "modified_by": "Administrator", "module": "Accounts", "name": "Journal Entry", diff --git a/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js b/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js index 3dc66aaa584..2a549778d7e 100644 --- a/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js +++ b/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js @@ -33,7 +33,7 @@ frappe.ui.form.on("Journal Entry Template", { } if(!frm.doc.company) return; - + frm.trigger("clear_child"); switch(frm.doc.voucher_type){ case "Opening Entry": @@ -49,7 +49,7 @@ frappe.ui.form.on("Journal Entry Template", { add_accounts(frm.doc, r.message); } } - }) + }); break; case "Bank Entry": case "Cash Entry": diff --git a/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.json b/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.json index 3f6cb026aa6..c411401a3f7 100644 --- a/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.json +++ b/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.json @@ -9,11 +9,10 @@ "field_order": [ "section_break_1", "template_title", - "section_break_2", - "company", "voucher_type", - "column_break_3", "naming_series", + "column_break_3", + "company", "is_opening", "section_break_3", "accounts" @@ -52,10 +51,6 @@ "label": "Is Opening", "options": "No\nYes" }, - { - "fieldname": "section_break_2", - "fieldtype": "Section Break" - }, { "fieldname": "accounts", "fieldtype": "Table", @@ -84,7 +79,7 @@ } ], "links": [], - "modified": "2020-04-26 04:29:03.347852", + "modified": "2020-04-29 10:52:33.526433", "modified_by": "Administrator", "module": "Accounts", "name": "Journal Entry Template", From 3b26b24af611f7b314d1696dab6c03b8d7a29e26 Mon Sep 17 00:00:00 2001 From: Abhishek Balam Date: Wed, 29 Apr 2020 11:28:40 +0530 Subject: [PATCH 07/10] fix semicolons as per codacy review --- erpnext/accounts/doctype/journal_entry/journal_entry.js | 4 ++-- .../doctype/journal_entry_template/journal_entry_template.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.js b/erpnext/accounts/doctype/journal_entry/journal_entry.js index 2e5d6b3847b..ccfdfceadb3 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.js +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.js @@ -12,7 +12,7 @@ frappe.ui.form.on("Journal Entry", { refresh: function(frm) { erpnext.toggle_naming_series(); - + if(frm.doc.docstatus==1) { frm.add_custom_button(__('Ledger'), function() { frappe.route_options = { @@ -144,7 +144,7 @@ frappe.ui.form.on("Journal Entry", { } } }); - } + } else if(frm.doc.voucher_type=="Opening Entry") { return frappe.call({ type:"GET", diff --git a/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js b/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js index 2a549778d7e..13e9a3d80c2 100644 --- a/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js +++ b/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js @@ -30,8 +30,8 @@ frappe.ui.form.on("Journal Entry Template", { row.account = d.account; }); refresh_field("accounts"); - } - + }; + if(!frm.doc.company) return; frm.trigger("clear_child"); From e35bb16436fdddf2c254fc44f5771d5926750194 Mon Sep 17 00:00:00 2001 From: Abhishek Balam Date: Wed, 29 Apr 2020 12:18:33 +0530 Subject: [PATCH 08/10] added journal entry template to accounting desk page --- erpnext/accounts/desk_page/accounting/accounting.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/desk_page/accounting/accounting.json b/erpnext/accounts/desk_page/accounting/accounting.json index 8566eadad4e..f3c4d25ab08 100644 --- a/erpnext/accounts/desk_page/accounting/accounting.json +++ b/erpnext/accounts/desk_page/accounting/accounting.json @@ -8,7 +8,7 @@ { "hidden": 0, "label": "General Ledger", - "links": "[\n {\n \"description\": \"Accounting journal entries.\",\n \"label\": \"Journal Entry\",\n \"name\": \"Journal Entry\",\n \"type\": \"doctype\"\n },\n {\n \"dependencies\": [\n \"GL Entry\"\n ],\n \"doctype\": \"GL Entry\",\n \"is_query_report\": true,\n \"label\": \"General Ledger\",\n \"name\": \"General Ledger\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Sales Invoice\"\n ],\n \"doctype\": \"Sales Invoice\",\n \"is_query_report\": true,\n \"label\": \"Customer Ledger Summary\",\n \"name\": \"Customer Ledger Summary\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Sales Invoice\"\n ],\n \"doctype\": \"Sales Invoice\",\n \"is_query_report\": true,\n \"label\": \"Supplier Ledger Summary\",\n \"name\": \"Supplier Ledger Summary\",\n \"type\": \"report\"\n }\n]" + "links": "[\n {\n \"description\": \"Accounting journal entries.\",\n \"label\": \"Journal Entry\",\n \"name\": \"Journal Entry\",\n \"type\": \"doctype\"\n },\n {\n \"description\": \"Make journal entries from a template.\",\n \"label\": \"Journal Entry Template\",\n \"name\": \"Journal Entry Template\",\n \"type\": \"doctype\"\n },\n \n {\n \"dependencies\": [\n \"GL Entry\"\n ],\n \"doctype\": \"GL Entry\",\n \"is_query_report\": true,\n \"label\": \"General Ledger\",\n \"name\": \"General Ledger\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Sales Invoice\"\n ],\n \"doctype\": \"Sales Invoice\",\n \"is_query_report\": true,\n \"label\": \"Customer Ledger Summary\",\n \"name\": \"Customer Ledger Summary\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Sales Invoice\"\n ],\n \"doctype\": \"Sales Invoice\",\n \"is_query_report\": true,\n \"label\": \"Supplier Ledger Summary\",\n \"name\": \"Supplier Ledger Summary\",\n \"type\": \"report\"\n }\n]" }, { "hidden": 0, @@ -103,7 +103,7 @@ "idx": 0, "is_standard": 1, "label": "Accounting", - "modified": "2020-04-01 11:28:50.925719", + "modified": "2020-04-29 12:17:34.844397", "modified_by": "Administrator", "module": "Accounts", "name": "Accounting", From b59e46d773bbea6c70233a871a903684b78e3b25 Mon Sep 17 00:00:00 2001 From: Abhishek Balam Date: Wed, 29 Apr 2020 15:01:56 +0530 Subject: [PATCH 09/10] fix semicolons as per codacy review --- .../doctype/journal_entry_template/journal_entry_template.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js b/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js index 13e9a3d80c2..bcb3f3a0be7 100644 --- a/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js +++ b/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js @@ -9,7 +9,7 @@ frappe.ui.form.on("Journal Entry Template", { filters: { "company": frm.doc.company, } - } + }; }); frappe.call({ type: "GET", From 978de8779ce0dd03a5b60f6ed0fbe2d851f741cc Mon Sep 17 00:00:00 2001 From: Deepesh Garg Date: Fri, 1 May 2020 18:38:13 +0530 Subject: [PATCH 10/10] fix: Add multi currency check and proper account filters --- .../doctype/journal_entry/journal_entry.js | 3 ++- .../journal_entry_template.js | 17 +++++++++++++---- .../journal_entry_template.json | 9 ++++++++- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.js b/erpnext/accounts/doctype/journal_entry/journal_entry.js index ccfdfceadb3..9a832e3c1fe 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.js +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.js @@ -173,7 +173,8 @@ frappe.ui.form.on("Journal Entry", { "company": doc.company, "voucher_type": doc.voucher_type, "naming_series": doc.naming_series, - "is_opening": doc.is_opening + "is_opening": doc.is_opening, + "multi_currency": doc.multi_currency }) update_jv_details(frm.doc, doc.accounts); }); diff --git a/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js b/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js index bcb3f3a0be7..cbb9fc4b0f9 100644 --- a/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js +++ b/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.js @@ -4,13 +4,22 @@ frappe.ui.form.on("Journal Entry Template", { setup: function(frm) { frappe.model.set_default_values(frm.doc); + frm.set_query("account" ,"accounts", function(){ - return { - filters: { - "company": frm.doc.company, - } + var filters = { + company: frm.doc.company, + is_group: 0 }; + + if(!frm.doc.multi_currency) { + $.extend(filters, { + account_currency: frappe.get_doc(":Company", frm.doc.company).default_currency + }); + } + + return { filters: filters }; }); + frappe.call({ type: "GET", method: "erpnext.accounts.doctype.journal_entry_template.journal_entry_template.get_naming_series", diff --git a/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.json b/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.json index c411401a3f7..660ae85cef3 100644 --- a/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.json +++ b/erpnext/accounts/doctype/journal_entry_template/journal_entry_template.json @@ -14,6 +14,7 @@ "column_break_3", "company", "is_opening", + "multi_currency", "section_break_3", "accounts" ], @@ -76,10 +77,16 @@ { "fieldname": "section_break_3", "fieldtype": "Section Break" + }, + { + "default": "0", + "fieldname": "multi_currency", + "fieldtype": "Check", + "label": "Multi Currency" } ], "links": [], - "modified": "2020-04-29 10:52:33.526433", + "modified": "2020-05-01 18:32:01.420488", "modified_by": "Administrator", "module": "Accounts", "name": "Journal Entry Template",