Merge pull request #4398 from nabinhait/bank_reco

[fix] Bank Reconciliation in account currency
This commit is contained in:
Rushabh Mehta 2015-11-30 16:06:06 +05:30
commit 0547a7668e
5 changed files with 262 additions and 181 deletions

View File

@ -4,7 +4,7 @@
frappe.ui.form.on("Bank Reconciliation", { frappe.ui.form.on("Bank Reconciliation", {
setup: function(frm) { setup: function(frm) {
frm.get_docfield("journal_entries").allow_bulk_edit = 1; frm.get_docfield("journal_entries").allow_bulk_edit = 1;
frm.add_fetch("bank_account", "company", "company"); frm.add_fetch("bank_account", "account_currency", "account_currency");
}, },
onload: function(frm) { onload: function(frm) {

View File

@ -19,10 +19,12 @@
"in_filter": 0, "in_filter": 0,
"in_list_view": 1, "in_list_view": 1,
"label": "Bank Account", "label": "Bank Account",
"length": 0,
"no_copy": 0, "no_copy": 0,
"options": "Account", "options": "Account",
"permlevel": 0, "permlevel": 0,
"print_hide": 0, "print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0, "read_only": 0,
"report_hide": 0, "report_hide": 0,
"reqd": 1, "reqd": 1,
@ -34,17 +36,19 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"fieldname": "company", "fieldname": "account_currency",
"fieldtype": "Link", "fieldtype": "Link",
"hidden": 1, "hidden": 1,
"ignore_user_permissions": 0, "ignore_user_permissions": 0,
"in_filter": 0, "in_filter": 0,
"in_list_view": 1, "in_list_view": 0,
"label": "Company", "label": "Account Currency",
"length": 0,
"no_copy": 0, "no_copy": 0,
"options": "Company", "options": "Currency",
"permlevel": 0, "permlevel": 0,
"print_hide": 1, "print_hide": 1,
"print_hide_if_no_value": 0,
"read_only": 0, "read_only": 0,
"report_hide": 0, "report_hide": 0,
"reqd": 0, "reqd": 0,
@ -63,9 +67,11 @@
"in_filter": 0, "in_filter": 0,
"in_list_view": 1, "in_list_view": 1,
"label": "From Date", "label": "From Date",
"length": 0,
"no_copy": 0, "no_copy": 0,
"permlevel": 0, "permlevel": 0,
"print_hide": 0, "print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0, "read_only": 0,
"report_hide": 0, "report_hide": 0,
"reqd": 1, "reqd": 1,
@ -84,9 +90,11 @@
"in_filter": 0, "in_filter": 0,
"in_list_view": 1, "in_list_view": 1,
"label": "To Date", "label": "To Date",
"length": 0,
"no_copy": 0, "no_copy": 0,
"permlevel": 0, "permlevel": 0,
"print_hide": 0, "print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0, "read_only": 0,
"report_hide": 0, "report_hide": 0,
"reqd": 1, "reqd": 1,
@ -105,9 +113,11 @@
"in_filter": 0, "in_filter": 0,
"in_list_view": 1, "in_list_view": 1,
"label": "Include Reconciled Entries", "label": "Include Reconciled Entries",
"length": 0,
"no_copy": 0, "no_copy": 0,
"permlevel": 0, "permlevel": 0,
"print_hide": 0, "print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0, "read_only": 0,
"report_hide": 0, "report_hide": 0,
"reqd": 0, "reqd": 0,
@ -126,10 +136,12 @@
"in_filter": 0, "in_filter": 0,
"in_list_view": 0, "in_list_view": 0,
"label": "Get Relevant Entries", "label": "Get Relevant Entries",
"length": 0,
"no_copy": 0, "no_copy": 0,
"options": "", "options": "",
"permlevel": 0, "permlevel": 0,
"print_hide": 0, "print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0, "read_only": 0,
"report_hide": 0, "report_hide": 0,
"reqd": 0, "reqd": 0,
@ -148,10 +160,12 @@
"in_filter": 0, "in_filter": 0,
"in_list_view": 0, "in_list_view": 0,
"label": "Journal Entries", "label": "Journal Entries",
"length": 0,
"no_copy": 0, "no_copy": 0,
"options": "Bank Reconciliation Detail", "options": "Bank Reconciliation Detail",
"permlevel": 0, "permlevel": 0,
"print_hide": 0, "print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0, "read_only": 0,
"report_hide": 0, "report_hide": 0,
"reqd": 0, "reqd": 0,
@ -170,10 +184,12 @@
"in_filter": 0, "in_filter": 0,
"in_list_view": 0, "in_list_view": 0,
"label": "Update Clearance Date", "label": "Update Clearance Date",
"length": 0,
"no_copy": 0, "no_copy": 0,
"options": "", "options": "",
"permlevel": 0, "permlevel": 0,
"print_hide": 0, "print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0, "read_only": 0,
"report_hide": 0, "report_hide": 0,
"reqd": 0, "reqd": 0,
@ -192,10 +208,12 @@
"in_filter": 0, "in_filter": 0,
"in_list_view": 0, "in_list_view": 0,
"label": "Total Amount", "label": "Total Amount",
"length": 0,
"no_copy": 0, "no_copy": 0,
"options": "Company:company:default_currency", "options": "account_currency",
"permlevel": 0, "permlevel": 0,
"print_hide": 0, "print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 1, "read_only": 1,
"report_hide": 0, "report_hide": 0,
"reqd": 0, "reqd": 0,
@ -213,7 +231,9 @@
"is_submittable": 0, "is_submittable": 0,
"issingle": 1, "issingle": 1,
"istable": 0, "istable": 0,
"modified": "2015-02-05 05:11:34.776660", "max_attachments": 0,
"menu_index": 0,
"modified": "2015-11-30 12:44:45.105451",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Accounts", "module": "Accounts",
"name": "Bank Reconciliation", "name": "Bank Reconciliation",
@ -241,5 +261,6 @@
} }
], ],
"read_only": 1, "read_only": 1,
"read_only_onload": 0 "read_only_onload": 0,
"version": 0
} }

View File

@ -18,9 +18,8 @@ class BankReconciliation(Document):
condition = "and (clearance_date is null or clearance_date='0000-00-00')" condition = "and (clearance_date is null or clearance_date='0000-00-00')"
dl = frappe.db.sql("""select t1.name, t1.cheque_no, t1.cheque_date, t2.debit, dl = frappe.db.sql("""select t1.name, t1.cheque_no, t1.cheque_date, t2.debit_in_account_currency,
t2.credit, t1.posting_date, t2.against_account, t1.clearance_date, t2.credit_in_account_currency, t1.posting_date, t2.against_account, t1.clearance_date
t2.reference_type, t2.reference_name
from from
`tabJournal Entry` t1, `tabJournal Entry Account` t2 `tabJournal Entry` t1, `tabJournal Entry Account` t2
where where
@ -39,11 +38,11 @@ class BankReconciliation(Document):
nl.voucher_id = d.name nl.voucher_id = d.name
nl.cheque_number = d.cheque_no nl.cheque_number = d.cheque_no
nl.cheque_date = d.cheque_date nl.cheque_date = d.cheque_date
nl.debit = d.debit nl.debit = d.debit_in_account_currency
nl.credit = d.credit nl.credit = d.credit_in_account_currency
nl.against_account = d.against_account nl.against_account = d.against_account
nl.clearance_date = d.clearance_date nl.clearance_date = d.clearance_date
self.total_amount += flt(d.debit) - flt(d.credit) self.total_amount += flt(d.debit_in_account_currency) - flt(d.credit_in_account_currency)
def update_details(self): def update_details(self):
vouchers = [] vouchers = []

View File

@ -25,30 +25,7 @@
"options": "Journal Entry", "options": "Journal Entry",
"permlevel": 0, "permlevel": 0,
"print_hide": 0, "print_hide": 0,
"read_only": 0, "print_hide_if_no_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "clearance_date",
"fieldtype": "Date",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 1,
"label": "Clearance Date",
"length": 0,
"no_copy": 0,
"oldfieldname": "clearance_date",
"oldfieldtype": "Date",
"permlevel": 0,
"print_hide": 0,
"read_only": 0, "read_only": 0,
"report_hide": 0, "report_hide": 0,
"reqd": 0, "reqd": 0,
@ -73,6 +50,108 @@
"oldfieldtype": "Data", "oldfieldtype": "Data",
"permlevel": 0, "permlevel": 0,
"print_hide": 0, "print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 1,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "debit",
"fieldtype": "Currency",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 1,
"label": "Debit",
"length": 0,
"no_copy": 0,
"oldfieldname": "debit",
"oldfieldtype": "Currency",
"options": "account_currency",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 1,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "credit",
"fieldtype": "Currency",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 1,
"label": "Credit",
"length": 0,
"no_copy": 0,
"oldfieldname": "credit",
"oldfieldtype": "Currency",
"options": "account_currency",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 1,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "column_break_5",
"fieldtype": "Column Break",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 0,
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0,
"width": "50%"
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "posting_date",
"fieldtype": "Date",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Posting Date",
"length": 0,
"no_copy": 0,
"oldfieldname": "posting_date",
"oldfieldtype": "Date",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 1, "read_only": 1,
"report_hide": 0, "report_hide": 0,
"reqd": 0, "reqd": 0,
@ -97,128 +176,7 @@
"oldfieldtype": "Data", "oldfieldtype": "Data",
"permlevel": 0, "permlevel": 0,
"print_hide": 0, "print_hide": 0,
"read_only": 1, "print_hide_if_no_value": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "debit",
"fieldtype": "Currency",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 1,
"label": "Debit",
"length": 0,
"no_copy": 0,
"oldfieldname": "debit",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"permlevel": 0,
"print_hide": 0,
"read_only": 1,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "credit",
"fieldtype": "Currency",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 1,
"label": "Credit",
"length": 0,
"no_copy": 0,
"oldfieldname": "credit",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"permlevel": 0,
"print_hide": 0,
"read_only": 1,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "reference_type",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Reference Type",
"length": 0,
"no_copy": 0,
"options": "DocType",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"read_only": 1,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "reference_name",
"fieldtype": "Dynamic Link",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Reference Name",
"length": 0,
"no_copy": 0,
"options": "reference_type",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"read_only": 1,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "posting_date",
"fieldtype": "Date",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Posting Date",
"length": 0,
"no_copy": 0,
"oldfieldname": "posting_date",
"oldfieldtype": "Date",
"permlevel": 0,
"print_hide": 0,
"read_only": 1, "read_only": 1,
"report_hide": 0, "report_hide": 0,
"reqd": 0, "reqd": 0,
@ -243,12 +201,38 @@
"oldfieldtype": "Date", "oldfieldtype": "Date",
"permlevel": 0, "permlevel": 0,
"print_hide": 0, "print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 1, "read_only": 1,
"report_hide": 0, "report_hide": 0,
"reqd": 0, "reqd": 0,
"search_index": 0, "search_index": 0,
"set_only_once": 0, "set_only_once": 0,
"unique": 0 "unique": 0
},
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "clearance_date",
"fieldtype": "Date",
"hidden": 0,
"ignore_user_permissions": 0,
"in_filter": 0,
"in_list_view": 1,
"label": "Clearance Date",
"length": 0,
"no_copy": 0,
"oldfieldname": "clearance_date",
"oldfieldtype": "Date",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
} }
], ],
"hide_heading": 0, "hide_heading": 0,
@ -260,12 +244,14 @@
"issingle": 0, "issingle": 0,
"istable": 1, "istable": 1,
"max_attachments": 0, "max_attachments": 0,
"modified": "2015-11-16 06:29:42.254366", "menu_index": 0,
"modified": "2015-11-30 12:52:01.090839",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Accounts", "module": "Accounts",
"name": "Bank Reconciliation Detail", "name": "Bank Reconciliation Detail",
"owner": "Administrator", "owner": "Administrator",
"permissions": [], "permissions": [],
"read_only": 0, "read_only": 0,
"read_only_onload": 0 "read_only_onload": 0,
"version": 0
} }

View File

@ -12,16 +12,18 @@ def execute(filters=None):
columns = get_columns() columns = get_columns()
if not filters.get("account"): return columns, [] if not filters.get("account"): return columns, []
account_currency = frappe.db.get_value("Account", filters.account, "account_currency")
data = get_entries(filters) data = get_entries(filters)
from erpnext.accounts.utils import get_balance_on from erpnext.accounts.utils import get_balance_on
balance_as_per_system = get_balance_on(filters["account"], filters["report_date"]) balance_as_per_system = get_balance_on(filters["account"], filters["report_date"])
total_debit, total_credit = 0,0 total_debit, total_credit = 0,0
for d in data: for d in data:
total_debit += flt(d[2]) total_debit += flt(d.debit_in_account_currency)
total_credit += flt(d[3]) total_credit += flt(d.credit_in_account_currency)
amounts_not_reflected_in_system = frappe.db.sql(""" amounts_not_reflected_in_system = frappe.db.sql("""
select sum(jvd.debit_in_account_currency - jvd.credit_in_account_currency) select sum(jvd.debit_in_account_currency - jvd.credit_in_account_currency)
@ -37,39 +39,112 @@ def execute(filters=None):
+ amounts_not_reflected_in_system + amounts_not_reflected_in_system
data += [ data += [
get_balance_row(_("System Balance"), balance_as_per_system), get_balance_row(_("System Balance"), balance_as_per_system, account_currency),
[""]*len(columns), {},
["", '"' + _("Amounts not reflected in bank") + '"', total_debit, total_credit, "", "", "", "", ""], {
get_balance_row(_("Amounts not reflected in system"), amounts_not_reflected_in_system), "journal_entry": '"' + _("Amounts not reflected in bank") + '"',
[""]*len(columns), "debit": total_debit,
get_balance_row(_("Expected balance as per bank"), bank_bal) "credit": total_credit,
"account_currency": account_currency
},
get_balance_row(_("Amounts not reflected in system"), amounts_not_reflected_in_system,
account_currency),
{},
get_balance_row(_("Expected balance as per bank"), bank_bal, account_currency)
] ]
return columns, data return columns, data
def get_columns(): def get_columns():
return [_("Posting Date") + ":Date:100", _("Journal Entry") + ":Link/Journal Entry:220", return [
_("Debit") + ":Currency:120", _("Credit") + ":Currency:120", {
_("Against Account") + ":Link/Account:200", _("Reference") + "::100", "fieldname": "posting_date",
_("Ref Date") + ":Date:110", _("Clearance Date") + ":Date:110", _("Currency") + ":Link/Currency:70" "label": _("Posting Date"),
"fieldtype": "Date",
"width": 100
},
{
"fieldname": "journal_entry",
"label": _("Journal Entry"),
"fieldtype": "Link",
"options": "Journal Entry",
"width": 220
},
{
"fieldname": "debit",
"label": _("Debit"),
"fieldtype": "Currency",
"options": "account_currency",
"width": 120
},
{
"fieldname": "credit",
"label": _("Credit"),
"fieldtype": "Currency",
"options": "account_currency",
"width": 120
},
{
"fieldname": "against_account",
"label": _("Against Account"),
"fieldtype": "Link",
"options": "Account",
"width": 200
},
{
"fieldname": "reference",
"label": _("Reference"),
"fieldtype": "Data",
"width": 100
},
{
"fieldname": "ref_date",
"label": _("Ref Date"),
"fieldtype": "Date",
"width": 110
},
{
"fieldname": "clearance_date",
"label": _("Clearance Date"),
"fieldtype": "Date",
"width": 110
},
{
"fieldname": "account_currency",
"label": _("Currency"),
"fieldtype": "Link",
"options": "Currency",
"width": 100
}
] ]
def get_entries(filters): def get_entries(filters):
entries = frappe.db.sql("""select entries = frappe.db.sql("""select
jv.posting_date, jv.name, jvd.debit_in_account_currency, jvd.credit_in_account_currency, jv.posting_date, jv.name as journal_entry, jvd.debit_in_account_currency as debit,
jvd.against_account, jv.cheque_no, jv.cheque_date, jv.clearance_date, jvd.account_currency jvd.credit_in_account_currency as credit, jvd.against_account,
jv.cheque_no as reference, jv.cheque_date as ref_date, jv.clearance_date, jvd.account_currency
from from
`tabJournal Entry Account` jvd, `tabJournal Entry` jv `tabJournal Entry Account` jvd, `tabJournal Entry` jv
where jvd.parent = jv.name and jv.docstatus=1 where jvd.parent = jv.name and jv.docstatus=1
and jvd.account = %(account)s and jv.posting_date <= %(report_date)s and jvd.account = %(account)s and jv.posting_date <= %(report_date)s
and ifnull(jv.clearance_date, '4000-01-01') > %(report_date)s and ifnull(jv.clearance_date, '4000-01-01') > %(report_date)s
and ifnull(jv.is_opening, 'No') = 'No' and ifnull(jv.is_opening, 'No') = 'No'
order by jv.name DESC""", filters, as_list=1) order by jv.name DESC""", filters, as_dict=1)
return entries return entries
def get_balance_row(label, amount): def get_balance_row(label, amount, account_currency):
if amount > 0: if amount > 0:
return ["", '"' + label + '"', amount, 0, "", "", "", "", ""] return {
"journal_entry": '"' + label + '"',
"debit": amount,
"credit": 0,
"account_currency": account_currency
}
else: else:
return ["", '"' + label + '"', 0, abs(amount), "", "", "", "", ""] return {
"journal_entry": '"' + label + '"',
"debit": 0,
"credit": abs(amount),
"account_currency": account_currency
}