Party balance
This commit is contained in:
parent
997a7a1d3e
commit
6f17cf93c5
@ -77,7 +77,9 @@ erpnext.accounts.JournalVoucher = frappe.ui.form.Controller.extend({
|
||||
},
|
||||
|
||||
setup_balance_formatter: function() {
|
||||
var df = frappe.meta.get_docfield("Journal Voucher Detail", "balance", this.frm.doc.name);
|
||||
var me = this;
|
||||
$.each(["balance", "party_balance"], function(i, field) {
|
||||
var df = frappe.meta.get_docfield("Journal Voucher Detail", field, me.frm.doc.name);
|
||||
df.formatter = function(value, df, options, doc) {
|
||||
var currency = frappe.meta.get_field_currency(df, doc);
|
||||
var dr_or_cr = value ? ('<label>' + (value > 0.0 ? __("Dr") : __("Cr")) + '</label>') : "";
|
||||
@ -86,6 +88,7 @@ erpnext.accounts.JournalVoucher = frappe.ui.form.Controller.extend({
|
||||
+ " " + dr_or_cr
|
||||
+ "</div>";
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
against_voucher: function(doc, cdt, cdn) {
|
||||
@ -259,19 +262,15 @@ cur_frm.cscript.voucher_type = function(doc, cdt, cdn) {
|
||||
}
|
||||
|
||||
frappe.ui.form.on("Journal Voucher Detail", "party", function(frm, cdt, cdn) {
|
||||
var d = locals[cdt][cdn];
|
||||
var d = frappe.get_doc(cdt, cdn);
|
||||
if(!d.account && d.party_type && d.party) {
|
||||
return frappe.call({
|
||||
method: "erpnext.accounts.party.get_party_account",
|
||||
return frm.call({
|
||||
method: "erpnext.accounts.doctype.journal_voucher.journal_voucher.get_party_account_and_balance",
|
||||
child: d,
|
||||
args: {
|
||||
company: frm.doc.company,
|
||||
party_type: d.party_type,
|
||||
party: d.party
|
||||
},
|
||||
callback: function(r) {
|
||||
if(!r.exc && r.message) {
|
||||
frappe.model.set_value(cdt, cdn, "account", r.message);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ from frappe.utils import cstr, flt, fmt_money, formatdate, getdate, money_in_wor
|
||||
from frappe import msgprint, _, scrub
|
||||
from erpnext.setup.utils import get_company_currency
|
||||
from erpnext.controllers.accounts_controller import AccountsController
|
||||
from erpnext.accounts.utils import get_balance_on
|
||||
|
||||
|
||||
class JournalVoucher(AccountsController):
|
||||
def __init__(self, arg1, arg2=None):
|
||||
@ -400,7 +402,6 @@ class JournalVoucher(AccountsController):
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_default_bank_cash_account(company, voucher_type):
|
||||
from erpnext.accounts.utils import get_balance_on
|
||||
account = frappe.db.get_value("Company", company,
|
||||
voucher_type=="Bank Voucher" and "default_bank_account" or "default_cash_account")
|
||||
if account:
|
||||
@ -421,6 +422,7 @@ def get_payment_entry_from_sales_invoice(sales_invoice):
|
||||
jv.get("entries")[0].party_type = "Customer"
|
||||
jv.get("entries")[0].party = si.customer
|
||||
jv.get("entries")[0].balance = get_balance_on(si.debit_to)
|
||||
jv.get("entries")[0].party_balance = get_balance_on(si.customer, "Customer")
|
||||
jv.get("entries")[0].credit = si.outstanding_amount
|
||||
jv.get("entries")[0].against_invoice = si.name
|
||||
|
||||
@ -431,7 +433,6 @@ def get_payment_entry_from_sales_invoice(sales_invoice):
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_payment_entry_from_purchase_invoice(purchase_invoice):
|
||||
from erpnext.accounts.utils import get_balance_on
|
||||
pi = frappe.get_doc("Purchase Invoice", purchase_invoice)
|
||||
jv = get_payment_entry(pi)
|
||||
jv.remark = 'Payment against Purchase Invoice {0}. {1}'.format(pi.name, pi.remarks)
|
||||
@ -441,6 +442,7 @@ def get_payment_entry_from_purchase_invoice(purchase_invoice):
|
||||
jv.get("entries")[0].party_type = "Supplier"
|
||||
jv.get("entries")[0].party = pi.supplier
|
||||
jv.get("entries")[0].balance = get_balance_on(pi.credit_to)
|
||||
jv.get("entries")[0].party_balance = get_balance_on(pi.supplier, "Supplier")
|
||||
jv.get("entries")[0].debit = pi.outstanding_amount
|
||||
jv.get("entries")[0].against_voucher = pi.name
|
||||
|
||||
@ -469,7 +471,6 @@ def get_payment_entry(doc):
|
||||
@frappe.whitelist()
|
||||
def get_opening_accounts(company):
|
||||
"""get all balance sheet accounts for opening entry"""
|
||||
from erpnext.accounts.utils import get_balance_on
|
||||
accounts = frappe.db.sql_list("""select name from tabAccount
|
||||
where group_or_ledger='Ledger' and report_type='Balance Sheet' and company=%s""", company)
|
||||
|
||||
@ -508,3 +509,17 @@ def get_outstanding(args):
|
||||
return {
|
||||
"debit": flt(frappe.db.get_value("Purchase Invoice", args["docname"], "outstanding_amount"))
|
||||
}
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_party_account_and_balance(company, party_type, party):
|
||||
from erpnext.accounts.party import get_party_account
|
||||
account = get_party_account(company, party, party_type)
|
||||
|
||||
account_balance = get_balance_on(account=account)
|
||||
party_balance = get_balance_on(party_type=party_type, party=party)
|
||||
|
||||
return {
|
||||
"account": account,
|
||||
"balance": account_balance,
|
||||
"party_balance": party_balance
|
||||
}
|
||||
|
@ -19,6 +19,19 @@
|
||||
"search_index": 1,
|
||||
"width": "250px"
|
||||
},
|
||||
{
|
||||
"fieldname": "balance",
|
||||
"fieldtype": "Currency",
|
||||
"in_list_view": 1,
|
||||
"label": "Account Balance",
|
||||
"no_copy": 1,
|
||||
"oldfieldname": "balance",
|
||||
"oldfieldtype": "Data",
|
||||
"options": "Company:company:default_currency",
|
||||
"permlevel": 0,
|
||||
"print_hide": 1,
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"default": ":Company",
|
||||
"description": "If Income or Expense",
|
||||
@ -56,21 +69,18 @@
|
||||
"permlevel": 0
|
||||
},
|
||||
{
|
||||
"fieldname": "balance",
|
||||
"fieldname": "party_balance",
|
||||
"fieldtype": "Currency",
|
||||
"in_list_view": 1,
|
||||
"label": "Account Balance",
|
||||
"no_copy": 1,
|
||||
"oldfieldname": "balance",
|
||||
"oldfieldtype": "Data",
|
||||
"label": "Party Balance",
|
||||
"options": "Company:company:default_currency",
|
||||
"permlevel": 0,
|
||||
"print_hide": 1,
|
||||
"precision": "",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "sec_break1",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "Amount",
|
||||
"permlevel": 0
|
||||
},
|
||||
{
|
||||
@ -188,7 +198,7 @@
|
||||
],
|
||||
"idx": 1,
|
||||
"istable": 1,
|
||||
"modified": "2014-09-11 18:33:53.705093",
|
||||
"modified": "2014-09-17 13:02:42.012069",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Journal Voucher Detail",
|
||||
|
@ -40,13 +40,15 @@ def validate_fiscal_year(date, fiscal_year, label="Date"):
|
||||
throw(_("{0} '{1}' not in Fiscal Year {2}").format(label, formatdate(date), fiscal_year))
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_balance_on(account=None, date=None):
|
||||
def get_balance_on(account=None, date=None, party_type=None, party=None):
|
||||
if not account and frappe.form_dict.get("account"):
|
||||
account = frappe.form_dict.get("account")
|
||||
if not date and frappe.form_dict.get("date"):
|
||||
date = frappe.form_dict.get("date")
|
||||
|
||||
acc = frappe.get_doc("Account", account)
|
||||
acc.check_permission("read")
|
||||
if not party_type and frappe.form_dict.get("party_type"):
|
||||
party_type = frappe.form_dict.get("party_type")
|
||||
if not party and frappe.form_dict.get("party"):
|
||||
party = frappe.form_dict.get("party")
|
||||
|
||||
cond = []
|
||||
if date:
|
||||
@ -67,6 +69,10 @@ def get_balance_on(account=None, date=None):
|
||||
# hence, assuming balance as 0.0
|
||||
return 0.0
|
||||
|
||||
if account:
|
||||
acc = frappe.get_doc("Account", account)
|
||||
acc.check_permission("read")
|
||||
|
||||
# for pl accounts, get balance within a fiscal year
|
||||
if acc.report_type == 'Profit and Loss':
|
||||
cond.append("posting_date >= '%s' and voucher_type != 'Period Closing Voucher'" \
|
||||
@ -81,6 +87,10 @@ def get_balance_on(account=None, date=None):
|
||||
else:
|
||||
cond.append("""gle.account = "%s" """ % (account.replace('"', '\\"'), ))
|
||||
|
||||
if party_type and party:
|
||||
cond.append("""gle.party_type = "%s" and gle.party = "%s" """ %
|
||||
(party_type.replace('"', '\\"'), party.replace('"', '\\"')))
|
||||
|
||||
bal = frappe.db.sql("""
|
||||
SELECT sum(ifnull(debit, 0)) - sum(ifnull(credit, 0))
|
||||
FROM `tabGL Entry` gle
|
||||
|
Loading…
x
Reference in New Issue
Block a user