From ed40542658ecafb270eb581d931cd772bc46fa42 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 13 Aug 2015 10:34:49 +0530 Subject: [PATCH] [fix] minor auto-select party type and add has_permission in whitelisted methods --- .../doctype/journal_entry/journal_entry.js | 5 +++-- .../doctype/journal_entry/journal_entry.py | 18 ++++++++++++++++++ .../payment_reconciliation.py | 2 +- .../page/accounts_browser/accounts_browser.js | 2 +- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.js b/erpnext/accounts/doctype/journal_entry/journal_entry.js index eac8f44e92..b05adbd279 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.js +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.js @@ -225,11 +225,12 @@ cur_frm.cscript.account = function(doc,dt,dn) { var d = locals[dt][dn]; if(d.account) { return frappe.call({ - method: "erpnext.accounts.utils.get_balance_on", + method: "erpnext.accounts.doctype.journal_entry.journal_entry.get_account_balance_and_party_type", args: {account: d.account, date: doc.posting_date}, callback: function(r) { - d.balance = r.message; + $.extend(d, r.message); refresh_field('balance', d.name, 'accounts'); + refresh_field('party_type', d.name, 'accounts'); } }); } diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index 00e2e91318..d891dd5b31 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -611,6 +611,8 @@ def get_against_jv(doctype, txt, searchfield, start, page_len, filters): @frappe.whitelist() def get_outstanding(args): + if not frappe.has_permission("Account"): + frappe.msgprint(_("No Permission"), raise_exception=1) args = eval(args) if args.get("doctype") == "Journal Entry": condition = " and party=%(party)s" if args.get("party") else "" @@ -637,6 +639,9 @@ def get_outstanding(args): @frappe.whitelist() def get_party_account_and_balance(company, party_type, party): + if not frappe.has_permission("Account"): + frappe.msgprint(_("No Permission"), raise_exception=1) + from erpnext.accounts.party import get_party_account account = get_party_account(company, party, party_type) @@ -648,3 +653,16 @@ def get_party_account_and_balance(company, party_type, party): "balance": account_balance, "party_balance": party_balance } + +@frappe.whitelist() +def get_account_balance_and_party_type(account, date): + """Returns dict of account balance and party type to be set in Journal Entry on selection of account.""" + if not frappe.has_permission("Account"): + frappe.msgprint(_("No Permission"), raise_exception=1) + + account_type = frappe.db.get_value("Account", account, "account_type") + return { + "balance": get_balance_on(account, date), + "party_type": {"Receivable":"Customer", "Payable":"Supplier"}.get(account_type, "") + } + diff --git a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py index 933570f9eb..b283c8fcb6 100644 --- a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py +++ b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py @@ -34,7 +34,7 @@ class PaymentReconciliation(Document): t1.name = t2.parent and t1.docstatus = 1 and t2.docstatus = 1 and t2.party_type = %(party_type)s and t2.party = %(party)s and t2.account = %(account)s and {dr_or_cr} > 0 - and ifnull(t2.reference_type, '')='' + and ifnull(t2.reference_type, '') in ('', 'Sales Order', 'Purchase Order') {cond} and (CASE WHEN t1.voucher_type in ('Debit Note', 'Credit Note') diff --git a/erpnext/accounts/page/accounts_browser/accounts_browser.js b/erpnext/accounts/page/accounts_browser/accounts_browser.js index cb36d059fd..77a87fff7c 100644 --- a/erpnext/accounts/page/accounts_browser/accounts_browser.js +++ b/erpnext/accounts/page/accounts_browser/accounts_browser.js @@ -202,7 +202,7 @@ erpnext.AccountsChart = Class.extend({ title:__('New Account'), fields: [ {fieldtype:'Data', fieldname:'account_name', label:__('New Account Name'), reqd:true, - description: __("Name of new Account. Note: Please don't create accounts for Customers and Suppliers, they are created automatically from the Customer and Supplier master")}, + description: __("Name of new Account. Note: Please don't create accounts for Customers and Suppliers")}, {fieldtype:'Check', fieldname:'is_group', label:__('Is Group'), description: __('Further accounts can be made under Groups, but entries can be made against non-Groups')}, {fieldtype:'Select', fieldname:'account_type', label:__('Account Type'),