Added dafult bank account in the customer/supplier

This commit is contained in:
Rohit Waghchaure 2019-01-17 15:30:44 +05:30
parent f725816809
commit fa7ee0b3b6
7 changed files with 110 additions and 12 deletions

View File

@ -33,6 +33,11 @@ def make_bank_account(doctype, docname):
return doc
@frappe.whitelist()
def get_account_from_bank_acc(name):
return frappe.db.get_value('Bank Account',
name, 'account')
def get_party_bank_account(party_type, party):
return frappe.db.get_value(party_type,
party, 'default_bank_account')
@frappe.whitelist()
def get_bank_account_details(bank_account):
return frappe.db.get_value("Bank Account",
bank_account, ['account', 'bank', 'bank_account_no'], as_dict=1)

View File

@ -291,7 +291,12 @@ frappe.ui.form.on('Payment Entry', {
() => frm.events.get_outstanding_documents(frm),
() => frm.events.hide_unhide_fields(frm),
() => frm.events.set_dynamic_labels(frm),
() => { frm.set_party_account_based_on_party = false; }
() => {
frm.set_party_account_based_on_party = false;
if (r.message.bank_account) {
frm.set_value("bank_account", r.message.bank_account);
}
}
]);
}
}
@ -846,13 +851,15 @@ frappe.ui.form.on('Payment Entry', {
const field = frm.doc.payment_type == "Pay" ? "paid_from":"paid_to";
if (frm.doc.bank_account && in_list(['Pay', 'Receive'], frm.doc.payment_type)) {
frappe.call({
method: "erpnext.accounts.doctype.bank_account.bank_account.get_account_from_bank_acc",
method: "erpnext.accounts.doctype.bank_account.bank_account.get_bank_account_details",
args: {
bank_account: frm.doc.bank_account
},
callback: function(r) {
if (r.message) {
frm.set_value(field, r.message);
frm.set_value(field, r.message.account);
frm.set_value('bank', r.message.bank);
frm.set_value('bank_account_no', r.message.bank_account_no);
}
}
});

View File

@ -12,6 +12,7 @@ from erpnext.accounts.doctype.journal_entry.journal_entry import get_default_ban
from erpnext.setup.utils import get_exchange_rate
from erpnext.accounts.general_ledger import make_gl_entries
from erpnext.hr.doctype.expense_claim.expense_claim import update_reimbursed_amount
from erpnext.accounts.doctype.bank_account.bank_account import get_party_bank_account, get_bank_account_details
from erpnext.controllers.accounts_controller import AccountsController, get_supplier_block_status
from six import string_types, iteritems
@ -88,6 +89,16 @@ class PaymentEntry(AccountsController):
.format(d.idx, d.reference_doctype, d.reference_name))
reference_names.append((d.reference_doctype, d.reference_name))
def set_bank_account_data(self):
if self.bank_account:
bank_data = get_bank_account_details(self.bank_account)
field = "paid_from" if self.payment_type == "Pay" else "paid_to"
self.bank = bank_data.bank
self.bank_account_no = bank_data.bank_account_no
self.set(field, bank_data.account)
def validate_allocated_amount(self):
for d in self.get("references"):
if (flt(d.allocated_amount))> 0:
@ -670,6 +681,7 @@ def get_negative_outstanding_invoices(party_type, party, party_account, party_ac
@frappe.whitelist()
def get_party_details(company, party_type, party, date, cost_center=None):
bank_account = ''
if not frappe.db.exists(party_type, party):
frappe.throw(_("Invalid {0}: {1}").format(party_type, party))
@ -680,13 +692,16 @@ def get_party_details(company, party_type, party, date, cost_center=None):
_party_name = "title" if party_type == "Student" else party_type.lower() + "_name"
party_name = frappe.db.get_value(party_type, party, _party_name)
party_balance = get_balance_on(party_type=party_type, party=party, cost_center=cost_center)
if party_type in ["Customer", "Supplier"]:
bank_account = get_party_bank_account(party_type, party)
return {
"party_account": party_account,
"party_name": party_name,
"party_account_currency": account_currency,
"party_balance": party_balance,
"account_balance": account_balance
"account_balance": account_balance,
"bank_account": bank_account
}
@ -890,6 +905,11 @@ def get_payment_entry(dt, dn, party_amount=None, bank_account=None, bank_amount=
pe.allocate_payment_amount = 1
pe.letter_head = doc.get("letter_head")
if pe.party_type in ["Customer", "Supplier"]:
bank_account = get_party_bank_account(pe.party_type, pe.party)
pe.set("bank_account", bank_account)
pe.set_bank_account_data()
# only Purchase Invoice can be blocked individually
if doc.doctype == "Purchase Invoice" and doc.invoice_is_blocked():
frappe.msgprint(_('{0} is on hold till {1}'.format(doc.name, doc.release_date)))

View File

@ -567,7 +567,7 @@ def get_partywise_advanced_payment_amount(party_type="Customer"):
data = frappe.db.sql(""" SELECT party, sum({0}) as amount
FROM `tabGL Entry`
WHERE party_type = %s and against_voucher is null GROUP BY party"""
.format("credit" if party_type == "Customer" else "debit") , party_type, debug=1)
.format(("credit - debit") if party_type == "Customer" else "debit") , party_type, debug=1)
if data:
return frappe._dict(data)

View File

@ -25,8 +25,8 @@ class AccountsReceivableSummary(ReceivablePayableReport):
credit_debit_label = "Credit Note Amt" if args.get('party_type') == 'Customer' else "Debit Note Amt"
columns += [{
"label": _("On Account Amount"),
"fieldname": "on_account_amt",
"label": _("Advance Amount"),
"fieldname": "advance_amount",
"fieldtype": "Currency",
"options": "currency",
"width": 100

View File

@ -149,6 +149,39 @@
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "default_bank_account",
"fieldtype": "Link",
"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": "Default Bank Account",
"length": 0,
"no_copy": 0,
"options": "Bank Account",
"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,
@ -1463,7 +1496,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2019-01-07 16:52:04.660271",
"modified": "2019-01-17 13:58:08.597792",
"modified_by": "Administrator",
"module": "Buying",
"name": "Supplier",

View File

@ -217,6 +217,39 @@
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_in_quick_entry": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "default_bank_account",
"fieldtype": "Link",
"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": "Default Bank Account",
"length": 0,
"no_copy": 0,
"options": "Bank Account",
"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,
@ -1873,7 +1906,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2018-10-01 10:07:34.510264",
"modified": "2019-01-17 13:10:24.360875",
"modified_by": "Administrator",
"module": "Selling",
"name": "Customer",