From 3cc9b3ef089bba022cc68e4bae6a3ba32463b7ae Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Tue, 22 Mar 2016 16:17:54 +0530 Subject: [PATCH] [enhancement] [minor] stock ledger, general ledger buttons in warehouse --- erpnext/stock/doctype/warehouse/warehouse.js | 22 +++++++++++++++++--- erpnext/stock/doctype/warehouse/warehouse.py | 8 +++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/erpnext/stock/doctype/warehouse/warehouse.js b/erpnext/stock/doctype/warehouse/warehouse.js index 22396b762e..586d248c79 100644 --- a/erpnext/stock/doctype/warehouse/warehouse.js +++ b/erpnext/stock/doctype/warehouse/warehouse.js @@ -1,9 +1,25 @@ // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -cur_frm.cscript.refresh = function(doc) { - cur_frm.toggle_display('warehouse_name', doc.__islocal); -} +frappe.ui.form.on("Warehouse", { + refresh: function(frm) { + frm.toggle_display('warehouse_name', frm.doc.__islocal); + + frm.add_custom_button(__("Stock Ledger"), function() { + frappe.set_route("query-report", "Stock Ledger", {"warehouse": frm.doc.name}); + }); + if(frm.doc.__onload && frm.doc.__onload.account) { + frm.add_custom_button(__("General Ledger"), function() { + frappe.route_options = { + "account": frm.doc.__onload.account, + "company": frm.doc.company + } + frappe.set_route("query-report", "General Ledger"); + }); + } + } +}); + cur_frm.set_query("create_account_under", function() { return { diff --git a/erpnext/stock/doctype/warehouse/warehouse.py b/erpnext/stock/doctype/warehouse/warehouse.py index 610c7b88a3..901b229cb8 100644 --- a/erpnext/stock/doctype/warehouse/warehouse.py +++ b/erpnext/stock/doctype/warehouse/warehouse.py @@ -14,6 +14,14 @@ class Warehouse(Document): if not self.warehouse_name.endswith(suffix): self.name = self.warehouse_name + suffix + def onload(self): + '''load account name for General Ledger Report''' + account = frappe.db.get_value("Account", { + "account_type": "Warehouse", "company": self.company, "warehouse": self.name}) + + if account: + self.set_onload('account', account) + def validate(self): if self.email_id: validate_email_add(self.email_id, True)