From faefeaa644dd400745950a95b97520b5245fb293 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Tue, 24 Jun 2014 18:53:04 +0530 Subject: [PATCH] Warehouse query filtered by company --- erpnext/controllers/queries.py | 1 + .../public/js/controllers/stock_controller.js | 37 +++++++++++++++++-- erpnext/public/js/queries.js | 6 +++ erpnext/public/js/transaction.js | 2 + 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/erpnext/controllers/queries.py b/erpnext/controllers/queries.py index 0f1d5f6dab..16d27d47fc 100644 --- a/erpnext/controllers/queries.py +++ b/erpnext/controllers/queries.py @@ -254,3 +254,4 @@ def get_account_list(doctype, txt, searchfield, start, page_len, filters): return frappe.widgets.reportview.execute("Account", filters = filter_list, fields = ["name", "parent_account"], limit_start=start, limit_page_length=page_len, as_list=True) + diff --git a/erpnext/public/js/controllers/stock_controller.js b/erpnext/public/js/controllers/stock_controller.js index e50b2af35f..97bcb6cf1c 100644 --- a/erpnext/public/js/controllers/stock_controller.js +++ b/erpnext/public/js/controllers/stock_controller.js @@ -4,6 +4,37 @@ frappe.provide("erpnext.stock"); erpnext.stock.StockController = frappe.ui.form.Controller.extend({ + onload: function() { + // warehouse query if company + if (this.frm.fields_dict.company) { + this.setup_warehouse_query(); + } + }, + + setup_warehouse_query: function() { + var me = this; + + var _set_warehouse_query = function(doctype, parentfield) { + var warehouse_link_fields = frappe.meta.get_docfields(doctype, me.frm.doc.name, + {"fieldtype": "Link", "options": "Warehouse"}); + $.each(warehouse_link_fields, function(i, df) { + me.frm.set_query(df.fieldname, parentfield, function() { + return erpnext.queries.warehouse(me.frm.doc); + }) + }); + }; + + _set_warehouse_query(me.frm.doc.doctype); + + // warehouse field in tables + var table_fields = frappe.meta.get_docfields(me.frm.doc.doctype, me.frm.doc.name, + {"fieldtype": "Table"}); + + $.each(table_fields, function(i, df) { + _set_warehouse_query(df.options, df.fieldname); + }); + }, + show_stock_ledger: function() { var me = this; if(this.frm.doc.docstatus===1) { @@ -17,12 +48,12 @@ erpnext.stock.StockController = frappe.ui.form.Controller.extend({ frappe.set_route("query-report", "Stock Ledger"); }, "icon-bar-chart"); } - + }, show_general_ledger: function() { var me = this; - if(this.frm.doc.docstatus===1 && cint(frappe.defaults.get_default("auto_accounting_for_stock"))) { + if(this.frm.doc.docstatus===1 && cint(frappe.defaults.get_default("auto_accounting_for_stock"))) { cur_frm.appframe.add_button(__('Accounting Ledger'), function() { frappe.route_options = { voucher_no: me.frm.doc.name, @@ -46,4 +77,4 @@ erpnext.stock.StockController = frappe.ui.form.Controller.extend({ } refresh_field(this.frm.cscript.fname); } -}); \ No newline at end of file +}); diff --git a/erpnext/public/js/queries.js b/erpnext/public/js/queries.js index 1f404db39a..b57b765ad6 100644 --- a/erpnext/public/js/queries.js +++ b/erpnext/public/js/queries.js @@ -67,5 +67,11 @@ $.extend(erpnext.queries, { employee: function() { return { query: "erpnext.controllers.queries.employee_query" } + }, + + warehouse: function(doc) { + return { + filters: [["Warehouse", "company", "in", ["", doc.company]]] + } } }); diff --git a/erpnext/public/js/transaction.js b/erpnext/public/js/transaction.js index ea576d5ae0..a4b1abbb6a 100644 --- a/erpnext/public/js/transaction.js +++ b/erpnext/public/js/transaction.js @@ -7,6 +7,8 @@ frappe.require("assets/erpnext/js/controllers/stock_controller.js"); erpnext.TransactionController = erpnext.stock.StockController.extend({ onload: function() { var me = this; + this._super(); + if(this.frm.doc.__islocal) { var today = get_today(), currency = frappe.defaults.get_user_default("currency");