mode of payment - company wise default account added

This commit is contained in:
Neil Trini Lasrado 2015-01-05 16:01:57 +05:30
parent 0bcf3e307c
commit bd2ac2f51f
14 changed files with 169 additions and 35 deletions

View File

@ -230,7 +230,7 @@ cur_frm.cscript.voucher_type = function(doc, cdt, cdn) {
var jvdetail = frappe.model.add_child(doc, "Journal Entry Account", "accounts");
$.each(r, function(i, d) {
var row = frappe.model.add_child(doc, "Journal Entry Account", "accounts");
row.account = d.account;
row.account = d.cash_bank_account;
row.balance = d.balance;
});
refresh_field("accounts");

View File

@ -442,12 +442,20 @@ class JournalEntry(AccountsController):
Pending Amount is {2}".format(d.idx, d.against_expense_claim, pending_amount)))
@frappe.whitelist()
def get_default_bank_cash_account(company, voucher_type):
account = frappe.db.get_value("Company", company,
voucher_type=="Bank Entry" and "default_bank_account" or "default_cash_account")
def get_default_bank_cash_account(company, voucher_type, mode_of_payment=None):
from erpnext.accounts.doctype.sales_invoice.sales_invoice import get_bank_cash_account
if mode_of_payment:
account = get_bank_cash_account(mode_of_payment, company)
if account.get("bank_cash_account"):
account.update({"balance": get_balance_on(account.get("cash_bank_account"))})
return account
account = frappe.db.get_value("Company", company, \
voucher_type=="Bank Voucher" and "default_bank_account" or "default_cash_account")
if account:
return {
"account": account,
"cash_bank_account": account,
"balance": get_balance_on(account)
}
@ -504,7 +512,7 @@ def get_payment_entry(doc):
d2 = jv.append("accounts")
if bank_account:
d2.account = bank_account["account"]
d2.account = bank_account["cash_bank_account"]
d2.balance = bank_account["balance"]
return jv

View File

@ -1,7 +1,7 @@
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt
cur_frm.set_query("default_account", function(doc) {
cur_frm.set_query("default_account", "mode_of_payment_details", function(doc, cdt, cdn) {
return{
filters: [
['Account', 'account_type', 'in', 'Bank, Cash'],

View File

@ -19,29 +19,17 @@
"reqd": 1
},
{
"fieldname": "company",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Company",
"options": "Company",
"fieldname": "accounts",
"fieldtype": "Table",
"label": "Accounts",
"options": "Mode of Payment Account",
"permlevel": 0,
"read_only": 0
},
{
"description": "Default Bank / Cash account will be automatically updated in POS Invoice when this mode is selected.",
"fieldname": "default_account",
"fieldtype": "Link",
"ignore_user_permissions": 1,
"in_list_view": 1,
"label": "Default Account",
"options": "Account",
"permlevel": 0,
"read_only": 0
"precision": ""
}
],
"icon": "icon-credit-card",
"idx": 1,
"modified": "2015-01-05 11:13:54.446006",
"modified": "2015-01-06 17:21:12.485997",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Mode of Payment",

View File

@ -0,0 +1,10 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors and Contributors
# See license.txt
import frappe
import unittest
test_records = frappe.get_test_records('Mode of Payment')
class TestModeofPayment(unittest.TestCase):
pass

View File

@ -0,0 +1,6 @@
[
{
"doctype": "Mode of Payment",
"name": "_Test Mode of Payment 1"
}
]

View File

@ -0,0 +1,71 @@
{
"allow_copy": 0,
"allow_import": 0,
"allow_rename": 0,
"creation": "2015-01-05 14:17:53.101432",
"custom": 0,
"docstatus": 0,
"doctype": "DocType",
"document_type": "",
"fields": [
{
"allow_on_submit": 0,
"fieldname": "company",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 1,
"label": "Company",
"no_copy": 0,
"options": "Company",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0
},
{
"allow_on_submit": 0,
"description": "Default Bank / Cash account will be automatically updated in POS Invoice when this mode is selected.",
"fieldname": "default_account",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 1,
"label": "Default Account",
"no_copy": 0,
"options": "Account",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0
}
],
"hide_heading": 0,
"hide_toolbar": 0,
"in_create": 0,
"in_dialog": 0,
"is_submittable": 0,
"issingle": 0,
"istable": 1,
"modified": "2015-01-06 17:26:57.053474",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Mode of Payment Account",
"name_case": "",
"owner": "Administrator",
"permissions": [],
"read_only": 0,
"read_only_onload": 0,
"sort_field": "modified",
"sort_order": "DESC"
}

View File

@ -0,0 +1,9 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors and contributors
# For license information, please see license.txt
from __future__ import unicode_literals
import frappe
from frappe.model.document import Document
class ModeofPaymentAccount(Document):
pass

View File

@ -63,7 +63,22 @@ frappe.ui.form.on("Payment Tool", "received_or_paid", function(frm) {
});
// Fetch bank/cash account based on payment mode
cur_frm.add_fetch("payment_mode", "default_account", "payment_account");
frappe.ui.form.on("Payment Tool", "payment_mode", function(frm) {
return frappe.call({
method: "erpnext.accounts.doctype.sales_invoice.sales_invoice.get_bank_cash_account",
args: {
"mode_of_payment": frm.doc.mode_of_payment,
"company": frm.doc.company
},
callback: function(r, rt) {
if(r.message) {
frm.doc.set_value("payment_account", r.message['bank_cash_account']
);
}
}
});
});
erpnext.payment_tool.check_mandatory_to_set_button = function(frm) {
if (frm.doc.company && frm.doc.party_type && frm.doc.party && frm.doc.received_or_paid) {

View File

@ -246,11 +246,15 @@ cur_frm.cscript.hide_fields = function(doc) {
cur_frm.cscript.mode_of_payment = function(doc) {
console.log("mode of payment!");
return cur_frm.call({
method: "erpnext.accounts.doctype.sales_invoice.sales_invoice.get_bank_cash_account",
args: { mode_of_payment: doc.mode_of_payment },
});
if(doc.is_pos) {
return cur_frm.call({
method: "erpnext.accounts.doctype.sales_invoice.sales_invoice.get_bank_cash_account",
args: {
"mode_of_payment": doc.mode_of_payment,
"company": doc.company
},
});
}
}
cur_frm.cscript.update_stock = function(doc, dt, dn) {

View File

@ -577,14 +577,16 @@ class SalesInvoice(SellingController):
)
@frappe.whitelist()
def get_bank_cash_account(mode_of_payment):
val = frappe.db.get_value("Mode of Payment", mode_of_payment, "default_account")
if not val:
def get_bank_cash_account(mode_of_payment, company):
account = frappe.db.get_value("Mode of Payment Account", {"parent": mode_of_payment, "company": company}, \
"default_account")
if not account:
frappe.msgprint(_("Please set default Cash or Bank account in Mode of Payment {0}").format(mode_of_payment))
return {
"cash_bank_account": val
"cash_bank_account": account
}
@frappe.whitelist()
def get_income_account(doctype, txt, searchfield, start, page_len, filters):
from erpnext.controllers.queries import get_match_cond

View File

@ -102,3 +102,4 @@ erpnext.patches.v4_2.party_model
erpnext.patches.v4_1.fix_jv_remarks
erpnext.patches.v5_0.recalculate_total_amount_in_jv
erpnext.patches.v5_0.remove_shopping_cart_app
erpnext.patches.v5_0.update_companywise_payment_account

View File

@ -0,0 +1,20 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
import frappe
def execute():
frappe.reload_doc('accounts', 'doctype', 'mode_of_payment')
mode_of_payment_list = frappe.db.sql("""select name, default_account
from `tabMode of Payment`""", as_dict=1)
for d in mode_of_payment_list:
if d.get("default_account"):
parent_doc = frappe.get_doc("Mode of Payment", d.get("name"))
parent_doc.set("mode_of_payment_details",
[{"company": frappe.db.get_user_default("company"),
"default_account": d.get("default_account")}])
parent_doc.save()