From faefeaa644dd400745950a95b97520b5245fb293 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Tue, 24 Jun 2014 18:53:04 +0530 Subject: [PATCH 1/2] 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 0f1d5f6dabe..16d27d47fca 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 e50b2af35f3..97bcb6cf1c1 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 1f404db39a8..b57b765ad6e 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 ea576d5ae07..a4b1abbb6a6 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"); From 4864c9e96ad5caf92fc4f9df9f16249ad6fc3ed3 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Tue, 24 Jun 2014 18:53:17 +0530 Subject: [PATCH 2/2] Fixed gantt chart query for Task --- erpnext/projects/doctype/task/task.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/projects/doctype/task/task.py b/erpnext/projects/doctype/task/task.py index 7fbaa45138a..6b0b237a402 100644 --- a/erpnext/projects/doctype/task/task.py +++ b/erpnext/projects/doctype/task/task.py @@ -52,7 +52,7 @@ def get_events(start, end, filters=None): frappe.msgprint(_("No Permission"), raise_exception=1) conditions = build_match_conditions("Task") - conditions and (" and " + conditions) or "" + conditions = conditions and (" and " + conditions) or "" if filters: filters = json.loads(filters)