From 7eb90d3d5c870563a9fa652d72c02d3a92e00117 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 2 Dec 2013 20:12:18 +0530 Subject: [PATCH 01/13] Stock Ageing report migated to Script report --- stock/report/stock_ageing/__init__.py | 0 stock/report/stock_ageing/stock_ageing.js | 40 +++++++++ stock/report/stock_ageing/stock_ageing.py | 99 ++++++++++++++++++++++ stock/report/stock_ageing/stock_ageing.txt | 21 +++++ 4 files changed, 160 insertions(+) create mode 100644 stock/report/stock_ageing/__init__.py create mode 100644 stock/report/stock_ageing/stock_ageing.js create mode 100644 stock/report/stock_ageing/stock_ageing.py create mode 100644 stock/report/stock_ageing/stock_ageing.txt diff --git a/stock/report/stock_ageing/__init__.py b/stock/report/stock_ageing/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/stock/report/stock_ageing/stock_ageing.js b/stock/report/stock_ageing/stock_ageing.js new file mode 100644 index 0000000000..f9e84b8a65 --- /dev/null +++ b/stock/report/stock_ageing/stock_ageing.js @@ -0,0 +1,40 @@ +// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +// License: GNU General Public License v3. See license.txt + +wn.query_reports["Stock Ageing"] = { + "filters": [ + { + "fieldname":"company", + "label": wn._("Company"), + "fieldtype": "Link", + "options": "Company", + "default": wn.defaults.get_user_default("company"), + "reqd": 1 + }, + { + "fieldname":"to_date", + "label": wn._("To Date"), + "fieldtype": "Date", + "default": wn.datetime.get_today(), + "reqd": 1 + }, + { + "fieldname":"warehouse", + "label": wn._("Warehouse"), + "fieldtype": "Link", + "options": "Warehouse" + }, + { + "fieldname":"item_code", + "label": wn._("Item"), + "fieldtype": "Link", + "options": "Item" + }, + { + "fieldname":"brand", + "label": wn._("Brand"), + "fieldtype": "Link", + "options": "Brand" + } + ] +} \ No newline at end of file diff --git a/stock/report/stock_ageing/stock_ageing.py b/stock/report/stock_ageing/stock_ageing.py new file mode 100644 index 0000000000..f688ed96ef --- /dev/null +++ b/stock/report/stock_ageing/stock_ageing.py @@ -0,0 +1,99 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +import webnotes +from webnotes.utils import date_diff +from webnotes import _ + +def execute(filters=None): + + columns = get_columns() + item_details = get_fifo_queue(filters) + to_date = filters["to_date"] + data = [] + for item, item_dict in item_details.items(): + fifo_queue = item_dict["fifo_queue"] + details = item_dict["details"] + if not fifo_queue: continue + + average_age = get_average_age(fifo_queue, to_date) + earliest_age = date_diff(to_date, fifo_queue[0][1]) + latest_age = date_diff(to_date, fifo_queue[-1][1]) + + data.append([item, details.item_name, details.description, details.brand, + average_age, earliest_age, latest_age, details.stock_uom]) + + return columns, data + +def get_average_age(fifo_queue, to_date): + batch_age = age_qty = total_qty = 0.0 + for batch in fifo_queue: + batch_age = date_diff(to_date, batch[1]) + age_qty += batch_age * batch[0] + total_qty += batch[0] + + return (age_qty / total_qty) if total_qty else 0.0 + +def get_columns(): + return ["Item Code:Link/Item:100", "Item Name::100", "Description::200", + "Brand:Link/Brand:100", "Average Age:Float:100", "Earliest:Int:80", + "Latest:Int:80", "UOM:Link/UOM:100"] + +def get_fifo_queue(filters): + item_details = {} + for d in get_stock_ledger_entries(filters): + item_details.setdefault(d.name, {"details": d, "fifo_queue": []}) + fifo_queue = item_details[d.name]["fifo_queue"] + if d.actual_qty > 0: + fifo_queue.append([d.actual_qty, d.posting_date]) + else: + qty_to_pop = abs(d.actual_qty) + while qty_to_pop: + batch = fifo_queue[0] if fifo_queue else [0, None] + if 0 < batch[0] <= qty_to_pop: + # if batch qty > 0 + # not enough or exactly same qty in current batch, clear batch + qty_to_pop -= batch[0] + fifo_queue.pop(0) + else: + # all from current batch + batch[0] -= qty_to_pop + qty_to_pop = 0 + + return item_details + +def get_stock_ledger_entries(filters): + if not filters.get("company"): + webnotes.throw(_("Company is mandatory")) + if not filters.get("to_date"): + webnotes.throw(_("To Date is mandatory")) + + return webnotes.conn.sql("""select + item.name, item.item_name, brand, description, item.stock_uom, actual_qty, posting_date + from `tabStock Ledger Entry` sle, + (select name, item_name, description, stock_uom, brand + from `tabItem` {item_conditions}) item + where item_code = item.name and + company = %(company)s and + posting_date <= %(to_date)s + {sle_conditions} + order by posting_date, posting_time, sle.name"""\ + .format(item_conditions=get_item_conditions(filters), + sle_conditions=get_sle_conditions(filters)), filters, as_dict=True) + +def get_item_conditions(filters): + conditions = [] + if filters.get("item_code"): + conditions.append("item_code=%(item_code)s") + if filters.get("brand"): + conditions.append("brand=%(brand)s") + + return "where {}".format(" and ".join(conditions)) if conditions else "" + +def get_sle_conditions(filters): + conditions = [] + if filters.get("warehouse"): + conditions.append("warehouse=%(warehouse)s") + + return "and {}".format(" and ".join(conditions)) if conditions else "" \ No newline at end of file diff --git a/stock/report/stock_ageing/stock_ageing.txt b/stock/report/stock_ageing/stock_ageing.txt new file mode 100644 index 0000000000..b88ebce5ed --- /dev/null +++ b/stock/report/stock_ageing/stock_ageing.txt @@ -0,0 +1,21 @@ +[ + { + "creation": "2013-12-02 17:09:31", + "docstatus": 0, + "modified": "2013-12-02 17:09:31", + "modified_by": "Administrator", + "owner": "Administrator" + }, + { + "doctype": "Report", + "is_standard": "Yes", + "name": "__common__", + "ref_doctype": "Item", + "report_name": "Stock Ageing", + "report_type": "Script Report" + }, + { + "doctype": "Report", + "name": "Stock Ageing" + } +] \ No newline at end of file From 47e40242bdf9f2937855f9faff3e9625c7e50c1e Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 2 Dec 2013 23:13:36 +0530 Subject: [PATCH 02/13] [minor] removed old stock ageing grid report --- stock/page/stock_ageing/README.md | 1 - stock/page/stock_ageing/__init__.py | 1 - stock/page/stock_ageing/stock_ageing.js | 183 ----------------- stock/page/stock_ageing/stock_ageing.txt | 37 ---- stock/page/stock_home/stock_home.js | 5 +- stock/page/stock_ledger/README.md | 1 - stock/page/stock_ledger/__init__.py | 1 - stock/page/stock_ledger/stock_ledger.js | 247 ----------------------- stock/page/stock_ledger/stock_ledger.txt | 41 ---- 9 files changed, 3 insertions(+), 514 deletions(-) delete mode 100644 stock/page/stock_ageing/README.md delete mode 100644 stock/page/stock_ageing/__init__.py delete mode 100644 stock/page/stock_ageing/stock_ageing.js delete mode 100644 stock/page/stock_ageing/stock_ageing.txt delete mode 100644 stock/page/stock_ledger/README.md delete mode 100644 stock/page/stock_ledger/__init__.py delete mode 100644 stock/page/stock_ledger/stock_ledger.js delete mode 100644 stock/page/stock_ledger/stock_ledger.txt diff --git a/stock/page/stock_ageing/README.md b/stock/page/stock_ageing/README.md deleted file mode 100644 index e8597b2194..0000000000 --- a/stock/page/stock_ageing/README.md +++ /dev/null @@ -1 +0,0 @@ -Average "age" of an Item in a particular Warehouse based on First-in-first-out (FIFO). \ No newline at end of file diff --git a/stock/page/stock_ageing/__init__.py b/stock/page/stock_ageing/__init__.py deleted file mode 100644 index baffc48825..0000000000 --- a/stock/page/stock_ageing/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from __future__ import unicode_literals diff --git a/stock/page/stock_ageing/stock_ageing.js b/stock/page/stock_ageing/stock_ageing.js deleted file mode 100644 index 6c626e22ed..0000000000 --- a/stock/page/stock_ageing/stock_ageing.js +++ /dev/null @@ -1,183 +0,0 @@ -// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors -// License: GNU General Public License v3. See license.txt - - -wn.pages['stock-ageing'].onload = function(wrapper) { - wn.ui.make_app_page({ - parent: wrapper, - title: wn._('Stock Ageing'), - single_column: true - }); - - new erpnext.StockAgeing(wrapper); - - - wrapper.appframe.add_module_icon("Stock") - -} - -wn.require("app/js/stock_grid_report.js"); - -erpnext.StockAgeing = erpnext.StockGridReport.extend({ - init: function(wrapper) { - this._super({ - title: wn._("Stock Ageing"), - page: wrapper, - parent: $(wrapper).find('.layout-main'), - appframe: wrapper.appframe, - doctypes: ["Item", "Warehouse", "Stock Ledger Entry", "Item Group", "Brand", "Serial No"], - }) - }, - setup_columns: function() { - this.columns = [ - {id: "name", name: wn._("Item"), field: "name", width: 300, - link_formatter: { - open_btn: true, - doctype: '"Item"' - }}, - {id: "item_name", name: wn._("Item Name"), field: "item_name", - width: 100, formatter: this.text_formatter}, - {id: "description", name: wn._("Description"), field: "description", - width: 200, formatter: this.text_formatter}, - {id: "brand", name: wn._("Brand"), field: "brand", width: 100}, - {id: "average_age", name: wn._("Average Age"), field: "average_age", - formatter: this.currency_formatter}, - {id: "earliest", name: wn._("Earliest"), field: "earliest", - formatter: this.currency_formatter}, - {id: "latest", name: wn._("Latest"), field: "latest", - formatter: this.currency_formatter}, - {id: "stock_uom", name: "UOM", field: "stock_uom", width: 100}, - ]; - }, - filters: [ - {fieldtype:"Select", label: wn._("Warehouse"), link:"Warehouse", - default_value: "Select Warehouse..."}, - {fieldtype:"Select", label: wn._("Brand"), link:"Brand", - default_value: "Select Brand...", filter: function(val, item, opts) { - return val == opts.default_value || item.brand == val; - }, link_formatter: {filter_input: "brand"}}, - {fieldtype:"Select", label: wn._("Plot By"), - options: ["Average Age", "Earliest", "Latest"]}, - {fieldtype:"Date", label: wn._("To Date")}, - {fieldtype:"Button", label: wn._("Refresh"), icon:"icon-refresh icon-white"}, - {fieldtype:"Button", label: wn._("Reset Filters")} - ], - setup_filters: function() { - var me = this; - this._super(); - this.trigger_refresh_on_change(["warehouse", "plot_by", "brand"]); - this.show_zero_check(); - }, - init_filter_values: function() { - this._super(); - this.filter_inputs.to_date.val(dateutil.obj_to_user(new Date())); - }, - prepare_data: function() { - var me = this; - - if(!this.data) { - me._data = wn.report_dump.data["Item"]; - me.item_by_name = me.make_name_map(me._data); - } - - this.data = [].concat(this._data); - - this.serialized_buying_rates = this.get_serialized_buying_rates(); - - $.each(this.data, function(i, d) { - me.reset_item_values(d); - }); - - this.prepare_balances(); - - // filter out brand - this.data = $.map(this.data, function(d) { - return me.apply_filter(d, "brand") ? d : null; - }); - - // filter out rows with zero values - this.data = $.map(this.data, function(d) { - return me.apply_zero_filter(null, d, null, me) ? d : null; - }); - }, - prepare_balances: function() { - var me = this; - var to_date = dateutil.str_to_obj(this.to_date); - var data = wn.report_dump.data["Stock Ledger Entry"]; - - this.item_warehouse = {}; - - for(var i=0, j=data.length; i to_date) - break; - } - } - - $.each(me.data, function(i, item) { - var full_fifo_stack = []; - if(me.is_default("warehouse")) { - $.each(me.item_warehouse[item.name] || {}, function(i, wh) { - full_fifo_stack = full_fifo_stack.concat(wh.fifo_stack || []) - }); - } else { - full_fifo_stack = me.get_item_warehouse(me.warehouse, item.name).fifo_stack || []; - } - - var age_qty = total_qty = 0.0; - var min_age = max_age = null; - - $.each(full_fifo_stack, function(i, batch) { - var batch_age = dateutil.get_diff(me.to_date, batch[2]); - age_qty += batch_age * batch[0]; - total_qty += batch[0]; - max_age = Math.max(max_age, batch_age); - if(min_age===null) min_age=batch_age; - else min_age = Math.min(min_age, batch_age); - }); - - item.average_age = total_qty.toFixed(2)==0.0 ? 0 - : (age_qty / total_qty).toFixed(2); - item.earliest = max_age || 0.0; - item.latest = min_age || 0.0; - }); - - this.data = this.data.sort(function(a, b) { - var sort_by = me.plot_by.replace(" ", "_").toLowerCase(); - return b[sort_by] - a[sort_by]; - }); - }, - get_plot_data: function() { - var data = []; - var me = this; - - data.push({ - label: me.plot_by, - data: $.map(me.data, function(item, idx) { - return [[idx+1, item[me.plot_by.replace(" ", "_").toLowerCase() ]]] - }), - bars: {show: true}, - }); - - return data.length ? data : false; - }, - get_plot_options: function() { - var me = this; - return { - grid: { hoverable: true, clickable: true }, - xaxis: { - ticks: $.map(me.data, function(item, idx) { return [[idx+1, item.name]] }), - max: 15 - }, - series: { downsample: { threshold: 1000 } } - } - } -}); \ No newline at end of file diff --git a/stock/page/stock_ageing/stock_ageing.txt b/stock/page/stock_ageing/stock_ageing.txt deleted file mode 100644 index cd1cfbd1c9..0000000000 --- a/stock/page/stock_ageing/stock_ageing.txt +++ /dev/null @@ -1,37 +0,0 @@ -[ - { - "creation": "2012-09-21 20:15:14", - "docstatus": 0, - "modified": "2013-07-11 14:44:08", - "modified_by": "Administrator", - "owner": "Administrator" - }, - { - "doctype": "Page", - "icon": "icon-table", - "module": "Stock", - "name": "__common__", - "page_name": "stock-ageing", - "standard": "Yes", - "title": "Stock Ageing" - }, - { - "doctype": "Page Role", - "name": "__common__", - "parent": "stock-ageing", - "parentfield": "roles", - "parenttype": "Page" - }, - { - "doctype": "Page", - "name": "stock-ageing" - }, - { - "doctype": "Page Role", - "role": "Analytics" - }, - { - "doctype": "Page Role", - "role": "Material Manager" - } -] \ No newline at end of file diff --git a/stock/page/stock_home/stock_home.js b/stock/page/stock_home/stock_home.js index 4be5a46601..ec432425b5 100644 --- a/stock/page/stock_home/stock_home.js +++ b/stock/page/stock_home/stock_home.js @@ -150,8 +150,9 @@ wn.module_page["Stock"] = [ "label": wn._("Stock Level") }, { - "page":"stock-ageing", - "label": wn._("Stock Ageing") + "label":wn._("Stock Ageing"), + doctype: "Item", + route: "query-report/Stock Ageing" }, ] }, diff --git a/stock/page/stock_ledger/README.md b/stock/page/stock_ledger/README.md deleted file mode 100644 index 774498b77e..0000000000 --- a/stock/page/stock_ledger/README.md +++ /dev/null @@ -1 +0,0 @@ -Stock movement report based on Stock Ledger Entry. \ No newline at end of file diff --git a/stock/page/stock_ledger/__init__.py b/stock/page/stock_ledger/__init__.py deleted file mode 100644 index baffc48825..0000000000 --- a/stock/page/stock_ledger/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from __future__ import unicode_literals diff --git a/stock/page/stock_ledger/stock_ledger.js b/stock/page/stock_ledger/stock_ledger.js deleted file mode 100644 index 08a455e1d3..0000000000 --- a/stock/page/stock_ledger/stock_ledger.js +++ /dev/null @@ -1,247 +0,0 @@ -// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors -// License: GNU General Public License v3. See license.txt - -wn.pages['stock-ledger'].onload = function(wrapper) { - wn.ui.make_app_page({ - parent: wrapper, - title: wn._('Stock Ledger'), - single_column: true - }); - - new erpnext.StockLedger(wrapper); - wrapper.appframe.add_module_icon("Stock") -} - -wn.require("app/js/stock_grid_report.js"); - -erpnext.StockLedger = erpnext.StockGridReport.extend({ - init: function(wrapper) { - this._super({ - title: wn._("Stock Ledger"), - page: wrapper, - parent: $(wrapper).find('.layout-main'), - appframe: wrapper.appframe, - doctypes: ["Item", "Item Group", "Warehouse", "Stock Ledger Entry", "Brand", "Serial No"], - }) - }, - - setup_columns: function() { - this.hide_balance = (this.is_default("item_code") || this.voucher_no) ? true : false; - this.columns = [ - {id: "posting_datetime", name: wn._("Posting Date"), field: "posting_datetime", width: 120, - formatter: this.date_formatter}, - {id: "item_code", name: wn._("Item Code"), field: "item_code", width: 160, - link_formatter: { - filter_input: "item_code", - open_btn: true, - doctype: '"Item"', - }}, - {id: "description", name: wn._("Description"), field: "description", width: 200, - formatter: this.text_formatter}, - {id: "warehouse", name: wn._("Warehouse"), field: "warehouse", width: 100, - link_formatter: {filter_input: "warehouse"}}, - {id: "brand", name: wn._("Brand"), field: "brand", width: 100}, - {id: "stock_uom", name: wn._("UOM"), field: "stock_uom", width: 100}, - {id: "qty", name: wn._("Qty"), field: "qty", width: 100, - formatter: this.currency_formatter}, - {id: "balance", name: wn._("Balance Qty"), field: "balance", width: 100, - formatter: this.currency_formatter, - hidden: this.hide_balance}, - {id: "balance_value", name: wn._("Balance Value"), field: "balance_value", width: 100, - formatter: this.currency_formatter, hidden: this.hide_balance}, - {id: "voucher_type", name: wn._("Voucher Type"), field: "voucher_type", width: 120}, - {id: "voucher_no", name: wn._("Voucher No"), field: "voucher_no", width: 160, - link_formatter: { - filter_input: "voucher_no", - open_btn: true, - doctype: "dataContext.voucher_type" - }}, - ]; - - }, - filters: [ - {fieldtype:"Select", label: wn._("Warehouse"), link:"Warehouse", - default_value: "Select Warehouse...", filter: function(val, item, opts) { - return item.warehouse == val || val == opts.default_value; - }}, - {fieldtype:"Link", label: wn._("Item Code"), link:"Item", default_value: "Select Item...", - filter: function(val, item, opts) { - return item.item_code == val || !val; - }}, - {fieldtype:"Select", label: "Brand", link:"Brand", - default_value: "Select Brand...", filter: function(val, item, opts) { - return val == opts.default_value || item.brand == val || item._show; - }, link_formatter: {filter_input: "brand"}}, - {fieldtype:"Data", label: wn._("Voucher No"), - filter: function(val, item, opts) { - if(!val) return true; - return (item.voucher_no && item.voucher_no.indexOf(val)!=-1); - }}, - {fieldtype:"Date", label: wn._("From Date"), filter: function(val, item) { - return dateutil.str_to_obj(val) <= dateutil.str_to_obj(item.posting_date); - }}, - {fieldtype:"Label", label: wn._("To")}, - {fieldtype:"Date", label: wn._("To Date"), filter: function(val, item) { - return dateutil.str_to_obj(val) >= dateutil.str_to_obj(item.posting_date); - }}, - {fieldtype:"Button", label: wn._("Refresh"), icon:"icon-refresh icon-white"}, - {fieldtype:"Button", label: wn._("Reset Filters")} - ], - - setup_filters: function() { - var me = this; - this._super(); - - this.wrapper.bind("apply_filters_from_route", function() { me.toggle_enable_brand(); }); - this.filter_inputs.item_code.change(function() { me.toggle_enable_brand(); }); - - this.trigger_refresh_on_change(["item_code", "warehouse", "brand"]); - }, - - toggle_enable_brand: function() { - if(!this.filter_inputs.item_code.val()) { - this.filter_inputs.brand.prop("disabled", false); - } else { - this.filter_inputs.brand - .val(this.filter_inputs.brand.get(0).opts.default_value) - .prop("disabled", true); - } - }, - - init_filter_values: function() { - this._super(); - this.filter_inputs.warehouse.get(0).selectedIndex = 0; - }, - prepare_data: function() { - var me = this; - if(!this.item_by_name) - this.item_by_name = this.make_name_map(wn.report_dump.data["Item"]); - var data = wn.report_dump.data["Stock Ledger Entry"]; - var out = []; - - var opening = { - item_code: "On " + dateutil.str_to_user(this.from_date), qty: 0.0, balance: 0.0, - id:"_opening", _show: true, _style: "font-weight: bold", balance_value: 0.0 - } - var total_in = { - item_code: "Total In", qty: 0.0, balance: 0.0, balance_value: 0.0, - id:"_total_in", _show: true, _style: "font-weight: bold" - } - var total_out = { - item_code: "Total Out", qty: 0.0, balance: 0.0, balance_value: 0.0, - id:"_total_out", _show: true, _style: "font-weight: bold" - } - - // clear balance - $.each(wn.report_dump.data["Item"], function(i, item) { - item.balance = item.balance_value = 0.0; - }); - - // initialize warehouse-item map - this.item_warehouse = {}; - this.serialized_buying_rates = this.get_serialized_buying_rates(); - var from_datetime = dateutil.str_to_obj(me.from_date + " 00:00:00"); - var to_datetime = dateutil.str_to_obj(me.to_date + " 23:59:59"); - - // - for(var i=0, j=data.length; i 0) { - total_in.qty += sl.qty; - total_in.balance_value += value_diff; - } else { - total_out.qty += (-1 * sl.qty); - total_out.balance_value += value_diff; - } - } - } - - if(!before_end) break; - - // apply filters - if(me.apply_filters(sl)) { - out.push(sl); - } - - // update balance - if((!me.is_default("warehouse") ? me.apply_filter(sl, "warehouse") : true)) { - sl.balance = me.item_by_name[sl.item_code].balance + sl.qty; - me.item_by_name[sl.item_code].balance = sl.balance; - - sl.balance_value = me.item_by_name[sl.item_code].balance_value + value_diff; - me.item_by_name[sl.item_code].balance_value = sl.balance_value; - } - } - - if(me.item_code && !me.voucher_no) { - var closing = { - item_code: "On " + dateutil.str_to_user(this.to_date), - balance: (out.length ? out[out.length-1].balance : 0), qty: 0, - balance_value: (out.length ? out[out.length-1].balance_value : 0), - id:"_closing", _show: true, _style: "font-weight: bold" - }; - total_out.balance_value = -total_out.balance_value; - var out = [opening].concat(out).concat([total_in, total_out, closing]); - } - - this.data = out; - }, - get_plot_data: function() { - var data = []; - var me = this; - if(me.hide_balance) return false; - data.push({ - label: me.item_code, - data: [[dateutil.str_to_obj(me.from_date).getTime(), me.data[0].balance]] - .concat($.map(me.data, function(col, idx) { - if (col.posting_datetime) { - return [[dateutil.str_to_obj(col.posting_datetime).getTime(), col.balance - col.qty], - [dateutil.str_to_obj(col.posting_datetime).getTime(), col.balance]] - } - return null; - })).concat([ - // closing - [dateutil.str_to_obj(me.to_date).getTime(), me.data[me.data.length - 1].balance] - ]), - points: {show: true}, - lines: {show: true, fill: true}, - }); - return data; - }, - get_plot_options: function() { - return { - grid: { hoverable: true, clickable: true }, - xaxis: { mode: "time", - min: dateutil.str_to_obj(this.from_date).getTime(), - max: dateutil.str_to_obj(this.to_date).getTime(), - }, - series: { downsample: { threshold: 1000 } } - } - }, - get_tooltip_text: function(label, x, y) { - var d = new Date(x); - var date = dateutil.obj_to_user(d) + " " + d.getHours() + ":" + d.getMinutes(); - var value = format_number(y); - return value.bold() + " on " + date; - } -}); \ No newline at end of file diff --git a/stock/page/stock_ledger/stock_ledger.txt b/stock/page/stock_ledger/stock_ledger.txt deleted file mode 100644 index 9c2a4b75e5..0000000000 --- a/stock/page/stock_ledger/stock_ledger.txt +++ /dev/null @@ -1,41 +0,0 @@ -[ - { - "creation": "2012-09-21 20:15:14", - "docstatus": 0, - "modified": "2013-07-11 14:44:19", - "modified_by": "Administrator", - "owner": "Administrator" - }, - { - "doctype": "Page", - "icon": "icon-table", - "module": "Stock", - "name": "__common__", - "page_name": "stock-ledger", - "standard": "Yes", - "title": "Stock Ledger" - }, - { - "doctype": "Page Role", - "name": "__common__", - "parent": "stock-ledger", - "parentfield": "roles", - "parenttype": "Page" - }, - { - "doctype": "Page", - "name": "stock-ledger" - }, - { - "doctype": "Page Role", - "role": "Analytics" - }, - { - "doctype": "Page Role", - "role": "Material Manager" - }, - { - "doctype": "Page Role", - "role": "Material User" - } -] \ No newline at end of file From bc6df5c71b861c6f83d5381e0642c25e6f31fe99 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 4 Dec 2013 16:42:23 +0530 Subject: [PATCH 03/13] [patch] [minor] deleted old stock ledger and stock ageing page --- patches/patch_list.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/patches/patch_list.py b/patches/patch_list.py index 437f3227a7..1a9e75f39b 100644 --- a/patches/patch_list.py +++ b/patches/patch_list.py @@ -256,4 +256,6 @@ patch_list = [ "patches.1311.p06_fix_report_columns", "execute:webnotes.delete_doc('DocType', 'Documentation Tool')", "execute:webnotes.delete_doc('Report', 'Stock Ledger') #2013-11-29", + "execute:webnotes.delete_doc('Page', 'stock-ledger') #2013-12-04", + "execute:webnotes.delete_doc('Page', 'stock-ageing') #2013-12-04", ] \ No newline at end of file From 9b0a6d426c646af1bdc27ecf938b9d6d647e827f Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 4 Dec 2013 17:18:05 +0530 Subject: [PATCH 04/13] [patch] [minor] deleted old stock ledger and stock ageing page --- patches/1312/__init__.py | 0 patches/1312/p01_delete_old_stock_reports.py | 11 + patches/patch_list.py | 3 +- stock/page/stock_ageing/README.md | 1 - stock/page/stock_ageing/__init__.py | 1 - stock/page/stock_ageing/stock_ageing.js | 183 -------------- stock/page/stock_ageing/stock_ageing.txt | 37 --- stock/page/stock_ledger/README.md | 1 - stock/page/stock_ledger/__init__.py | 1 - stock/page/stock_ledger/stock_ledger.js | 247 ------------------- stock/page/stock_ledger/stock_ledger.txt | 41 --- 11 files changed, 12 insertions(+), 514 deletions(-) create mode 100644 patches/1312/__init__.py create mode 100644 patches/1312/p01_delete_old_stock_reports.py delete mode 100644 stock/page/stock_ageing/README.md delete mode 100644 stock/page/stock_ageing/__init__.py delete mode 100644 stock/page/stock_ageing/stock_ageing.js delete mode 100644 stock/page/stock_ageing/stock_ageing.txt delete mode 100644 stock/page/stock_ledger/README.md delete mode 100644 stock/page/stock_ledger/__init__.py delete mode 100644 stock/page/stock_ledger/stock_ledger.js delete mode 100644 stock/page/stock_ledger/stock_ledger.txt diff --git a/patches/1312/__init__.py b/patches/1312/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/patches/1312/p01_delete_old_stock_reports.py b/patches/1312/p01_delete_old_stock_reports.py new file mode 100644 index 0000000000..ffa783fc1e --- /dev/null +++ b/patches/1312/p01_delete_old_stock_reports.py @@ -0,0 +1,11 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +# License: GNU General Public License v3. See license.txt + +def execute(): + import webnotes, os + + webnotes.delete_doc('Page', 'stock-ledger') + webnotes.delete_doc('Page', 'stock-ageing') + + os.system("rm -rf app/stock/page/stock_ledger") + os.system("rm -rf app/stock/page/stock_ageing") \ No newline at end of file diff --git a/patches/patch_list.py b/patches/patch_list.py index 1a9e75f39b..0ebe5e2540 100644 --- a/patches/patch_list.py +++ b/patches/patch_list.py @@ -256,6 +256,5 @@ patch_list = [ "patches.1311.p06_fix_report_columns", "execute:webnotes.delete_doc('DocType', 'Documentation Tool')", "execute:webnotes.delete_doc('Report', 'Stock Ledger') #2013-11-29", - "execute:webnotes.delete_doc('Page', 'stock-ledger') #2013-12-04", - "execute:webnotes.delete_doc('Page', 'stock-ageing') #2013-12-04", + "patches.1312.p01_delete_old_stock_reports", ] \ No newline at end of file diff --git a/stock/page/stock_ageing/README.md b/stock/page/stock_ageing/README.md deleted file mode 100644 index e8597b2194..0000000000 --- a/stock/page/stock_ageing/README.md +++ /dev/null @@ -1 +0,0 @@ -Average "age" of an Item in a particular Warehouse based on First-in-first-out (FIFO). \ No newline at end of file diff --git a/stock/page/stock_ageing/__init__.py b/stock/page/stock_ageing/__init__.py deleted file mode 100644 index baffc48825..0000000000 --- a/stock/page/stock_ageing/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from __future__ import unicode_literals diff --git a/stock/page/stock_ageing/stock_ageing.js b/stock/page/stock_ageing/stock_ageing.js deleted file mode 100644 index 6c626e22ed..0000000000 --- a/stock/page/stock_ageing/stock_ageing.js +++ /dev/null @@ -1,183 +0,0 @@ -// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors -// License: GNU General Public License v3. See license.txt - - -wn.pages['stock-ageing'].onload = function(wrapper) { - wn.ui.make_app_page({ - parent: wrapper, - title: wn._('Stock Ageing'), - single_column: true - }); - - new erpnext.StockAgeing(wrapper); - - - wrapper.appframe.add_module_icon("Stock") - -} - -wn.require("app/js/stock_grid_report.js"); - -erpnext.StockAgeing = erpnext.StockGridReport.extend({ - init: function(wrapper) { - this._super({ - title: wn._("Stock Ageing"), - page: wrapper, - parent: $(wrapper).find('.layout-main'), - appframe: wrapper.appframe, - doctypes: ["Item", "Warehouse", "Stock Ledger Entry", "Item Group", "Brand", "Serial No"], - }) - }, - setup_columns: function() { - this.columns = [ - {id: "name", name: wn._("Item"), field: "name", width: 300, - link_formatter: { - open_btn: true, - doctype: '"Item"' - }}, - {id: "item_name", name: wn._("Item Name"), field: "item_name", - width: 100, formatter: this.text_formatter}, - {id: "description", name: wn._("Description"), field: "description", - width: 200, formatter: this.text_formatter}, - {id: "brand", name: wn._("Brand"), field: "brand", width: 100}, - {id: "average_age", name: wn._("Average Age"), field: "average_age", - formatter: this.currency_formatter}, - {id: "earliest", name: wn._("Earliest"), field: "earliest", - formatter: this.currency_formatter}, - {id: "latest", name: wn._("Latest"), field: "latest", - formatter: this.currency_formatter}, - {id: "stock_uom", name: "UOM", field: "stock_uom", width: 100}, - ]; - }, - filters: [ - {fieldtype:"Select", label: wn._("Warehouse"), link:"Warehouse", - default_value: "Select Warehouse..."}, - {fieldtype:"Select", label: wn._("Brand"), link:"Brand", - default_value: "Select Brand...", filter: function(val, item, opts) { - return val == opts.default_value || item.brand == val; - }, link_formatter: {filter_input: "brand"}}, - {fieldtype:"Select", label: wn._("Plot By"), - options: ["Average Age", "Earliest", "Latest"]}, - {fieldtype:"Date", label: wn._("To Date")}, - {fieldtype:"Button", label: wn._("Refresh"), icon:"icon-refresh icon-white"}, - {fieldtype:"Button", label: wn._("Reset Filters")} - ], - setup_filters: function() { - var me = this; - this._super(); - this.trigger_refresh_on_change(["warehouse", "plot_by", "brand"]); - this.show_zero_check(); - }, - init_filter_values: function() { - this._super(); - this.filter_inputs.to_date.val(dateutil.obj_to_user(new Date())); - }, - prepare_data: function() { - var me = this; - - if(!this.data) { - me._data = wn.report_dump.data["Item"]; - me.item_by_name = me.make_name_map(me._data); - } - - this.data = [].concat(this._data); - - this.serialized_buying_rates = this.get_serialized_buying_rates(); - - $.each(this.data, function(i, d) { - me.reset_item_values(d); - }); - - this.prepare_balances(); - - // filter out brand - this.data = $.map(this.data, function(d) { - return me.apply_filter(d, "brand") ? d : null; - }); - - // filter out rows with zero values - this.data = $.map(this.data, function(d) { - return me.apply_zero_filter(null, d, null, me) ? d : null; - }); - }, - prepare_balances: function() { - var me = this; - var to_date = dateutil.str_to_obj(this.to_date); - var data = wn.report_dump.data["Stock Ledger Entry"]; - - this.item_warehouse = {}; - - for(var i=0, j=data.length; i to_date) - break; - } - } - - $.each(me.data, function(i, item) { - var full_fifo_stack = []; - if(me.is_default("warehouse")) { - $.each(me.item_warehouse[item.name] || {}, function(i, wh) { - full_fifo_stack = full_fifo_stack.concat(wh.fifo_stack || []) - }); - } else { - full_fifo_stack = me.get_item_warehouse(me.warehouse, item.name).fifo_stack || []; - } - - var age_qty = total_qty = 0.0; - var min_age = max_age = null; - - $.each(full_fifo_stack, function(i, batch) { - var batch_age = dateutil.get_diff(me.to_date, batch[2]); - age_qty += batch_age * batch[0]; - total_qty += batch[0]; - max_age = Math.max(max_age, batch_age); - if(min_age===null) min_age=batch_age; - else min_age = Math.min(min_age, batch_age); - }); - - item.average_age = total_qty.toFixed(2)==0.0 ? 0 - : (age_qty / total_qty).toFixed(2); - item.earliest = max_age || 0.0; - item.latest = min_age || 0.0; - }); - - this.data = this.data.sort(function(a, b) { - var sort_by = me.plot_by.replace(" ", "_").toLowerCase(); - return b[sort_by] - a[sort_by]; - }); - }, - get_plot_data: function() { - var data = []; - var me = this; - - data.push({ - label: me.plot_by, - data: $.map(me.data, function(item, idx) { - return [[idx+1, item[me.plot_by.replace(" ", "_").toLowerCase() ]]] - }), - bars: {show: true}, - }); - - return data.length ? data : false; - }, - get_plot_options: function() { - var me = this; - return { - grid: { hoverable: true, clickable: true }, - xaxis: { - ticks: $.map(me.data, function(item, idx) { return [[idx+1, item.name]] }), - max: 15 - }, - series: { downsample: { threshold: 1000 } } - } - } -}); \ No newline at end of file diff --git a/stock/page/stock_ageing/stock_ageing.txt b/stock/page/stock_ageing/stock_ageing.txt deleted file mode 100644 index cd1cfbd1c9..0000000000 --- a/stock/page/stock_ageing/stock_ageing.txt +++ /dev/null @@ -1,37 +0,0 @@ -[ - { - "creation": "2012-09-21 20:15:14", - "docstatus": 0, - "modified": "2013-07-11 14:44:08", - "modified_by": "Administrator", - "owner": "Administrator" - }, - { - "doctype": "Page", - "icon": "icon-table", - "module": "Stock", - "name": "__common__", - "page_name": "stock-ageing", - "standard": "Yes", - "title": "Stock Ageing" - }, - { - "doctype": "Page Role", - "name": "__common__", - "parent": "stock-ageing", - "parentfield": "roles", - "parenttype": "Page" - }, - { - "doctype": "Page", - "name": "stock-ageing" - }, - { - "doctype": "Page Role", - "role": "Analytics" - }, - { - "doctype": "Page Role", - "role": "Material Manager" - } -] \ No newline at end of file diff --git a/stock/page/stock_ledger/README.md b/stock/page/stock_ledger/README.md deleted file mode 100644 index 774498b77e..0000000000 --- a/stock/page/stock_ledger/README.md +++ /dev/null @@ -1 +0,0 @@ -Stock movement report based on Stock Ledger Entry. \ No newline at end of file diff --git a/stock/page/stock_ledger/__init__.py b/stock/page/stock_ledger/__init__.py deleted file mode 100644 index baffc48825..0000000000 --- a/stock/page/stock_ledger/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from __future__ import unicode_literals diff --git a/stock/page/stock_ledger/stock_ledger.js b/stock/page/stock_ledger/stock_ledger.js deleted file mode 100644 index 08a455e1d3..0000000000 --- a/stock/page/stock_ledger/stock_ledger.js +++ /dev/null @@ -1,247 +0,0 @@ -// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors -// License: GNU General Public License v3. See license.txt - -wn.pages['stock-ledger'].onload = function(wrapper) { - wn.ui.make_app_page({ - parent: wrapper, - title: wn._('Stock Ledger'), - single_column: true - }); - - new erpnext.StockLedger(wrapper); - wrapper.appframe.add_module_icon("Stock") -} - -wn.require("app/js/stock_grid_report.js"); - -erpnext.StockLedger = erpnext.StockGridReport.extend({ - init: function(wrapper) { - this._super({ - title: wn._("Stock Ledger"), - page: wrapper, - parent: $(wrapper).find('.layout-main'), - appframe: wrapper.appframe, - doctypes: ["Item", "Item Group", "Warehouse", "Stock Ledger Entry", "Brand", "Serial No"], - }) - }, - - setup_columns: function() { - this.hide_balance = (this.is_default("item_code") || this.voucher_no) ? true : false; - this.columns = [ - {id: "posting_datetime", name: wn._("Posting Date"), field: "posting_datetime", width: 120, - formatter: this.date_formatter}, - {id: "item_code", name: wn._("Item Code"), field: "item_code", width: 160, - link_formatter: { - filter_input: "item_code", - open_btn: true, - doctype: '"Item"', - }}, - {id: "description", name: wn._("Description"), field: "description", width: 200, - formatter: this.text_formatter}, - {id: "warehouse", name: wn._("Warehouse"), field: "warehouse", width: 100, - link_formatter: {filter_input: "warehouse"}}, - {id: "brand", name: wn._("Brand"), field: "brand", width: 100}, - {id: "stock_uom", name: wn._("UOM"), field: "stock_uom", width: 100}, - {id: "qty", name: wn._("Qty"), field: "qty", width: 100, - formatter: this.currency_formatter}, - {id: "balance", name: wn._("Balance Qty"), field: "balance", width: 100, - formatter: this.currency_formatter, - hidden: this.hide_balance}, - {id: "balance_value", name: wn._("Balance Value"), field: "balance_value", width: 100, - formatter: this.currency_formatter, hidden: this.hide_balance}, - {id: "voucher_type", name: wn._("Voucher Type"), field: "voucher_type", width: 120}, - {id: "voucher_no", name: wn._("Voucher No"), field: "voucher_no", width: 160, - link_formatter: { - filter_input: "voucher_no", - open_btn: true, - doctype: "dataContext.voucher_type" - }}, - ]; - - }, - filters: [ - {fieldtype:"Select", label: wn._("Warehouse"), link:"Warehouse", - default_value: "Select Warehouse...", filter: function(val, item, opts) { - return item.warehouse == val || val == opts.default_value; - }}, - {fieldtype:"Link", label: wn._("Item Code"), link:"Item", default_value: "Select Item...", - filter: function(val, item, opts) { - return item.item_code == val || !val; - }}, - {fieldtype:"Select", label: "Brand", link:"Brand", - default_value: "Select Brand...", filter: function(val, item, opts) { - return val == opts.default_value || item.brand == val || item._show; - }, link_formatter: {filter_input: "brand"}}, - {fieldtype:"Data", label: wn._("Voucher No"), - filter: function(val, item, opts) { - if(!val) return true; - return (item.voucher_no && item.voucher_no.indexOf(val)!=-1); - }}, - {fieldtype:"Date", label: wn._("From Date"), filter: function(val, item) { - return dateutil.str_to_obj(val) <= dateutil.str_to_obj(item.posting_date); - }}, - {fieldtype:"Label", label: wn._("To")}, - {fieldtype:"Date", label: wn._("To Date"), filter: function(val, item) { - return dateutil.str_to_obj(val) >= dateutil.str_to_obj(item.posting_date); - }}, - {fieldtype:"Button", label: wn._("Refresh"), icon:"icon-refresh icon-white"}, - {fieldtype:"Button", label: wn._("Reset Filters")} - ], - - setup_filters: function() { - var me = this; - this._super(); - - this.wrapper.bind("apply_filters_from_route", function() { me.toggle_enable_brand(); }); - this.filter_inputs.item_code.change(function() { me.toggle_enable_brand(); }); - - this.trigger_refresh_on_change(["item_code", "warehouse", "brand"]); - }, - - toggle_enable_brand: function() { - if(!this.filter_inputs.item_code.val()) { - this.filter_inputs.brand.prop("disabled", false); - } else { - this.filter_inputs.brand - .val(this.filter_inputs.brand.get(0).opts.default_value) - .prop("disabled", true); - } - }, - - init_filter_values: function() { - this._super(); - this.filter_inputs.warehouse.get(0).selectedIndex = 0; - }, - prepare_data: function() { - var me = this; - if(!this.item_by_name) - this.item_by_name = this.make_name_map(wn.report_dump.data["Item"]); - var data = wn.report_dump.data["Stock Ledger Entry"]; - var out = []; - - var opening = { - item_code: "On " + dateutil.str_to_user(this.from_date), qty: 0.0, balance: 0.0, - id:"_opening", _show: true, _style: "font-weight: bold", balance_value: 0.0 - } - var total_in = { - item_code: "Total In", qty: 0.0, balance: 0.0, balance_value: 0.0, - id:"_total_in", _show: true, _style: "font-weight: bold" - } - var total_out = { - item_code: "Total Out", qty: 0.0, balance: 0.0, balance_value: 0.0, - id:"_total_out", _show: true, _style: "font-weight: bold" - } - - // clear balance - $.each(wn.report_dump.data["Item"], function(i, item) { - item.balance = item.balance_value = 0.0; - }); - - // initialize warehouse-item map - this.item_warehouse = {}; - this.serialized_buying_rates = this.get_serialized_buying_rates(); - var from_datetime = dateutil.str_to_obj(me.from_date + " 00:00:00"); - var to_datetime = dateutil.str_to_obj(me.to_date + " 23:59:59"); - - // - for(var i=0, j=data.length; i 0) { - total_in.qty += sl.qty; - total_in.balance_value += value_diff; - } else { - total_out.qty += (-1 * sl.qty); - total_out.balance_value += value_diff; - } - } - } - - if(!before_end) break; - - // apply filters - if(me.apply_filters(sl)) { - out.push(sl); - } - - // update balance - if((!me.is_default("warehouse") ? me.apply_filter(sl, "warehouse") : true)) { - sl.balance = me.item_by_name[sl.item_code].balance + sl.qty; - me.item_by_name[sl.item_code].balance = sl.balance; - - sl.balance_value = me.item_by_name[sl.item_code].balance_value + value_diff; - me.item_by_name[sl.item_code].balance_value = sl.balance_value; - } - } - - if(me.item_code && !me.voucher_no) { - var closing = { - item_code: "On " + dateutil.str_to_user(this.to_date), - balance: (out.length ? out[out.length-1].balance : 0), qty: 0, - balance_value: (out.length ? out[out.length-1].balance_value : 0), - id:"_closing", _show: true, _style: "font-weight: bold" - }; - total_out.balance_value = -total_out.balance_value; - var out = [opening].concat(out).concat([total_in, total_out, closing]); - } - - this.data = out; - }, - get_plot_data: function() { - var data = []; - var me = this; - if(me.hide_balance) return false; - data.push({ - label: me.item_code, - data: [[dateutil.str_to_obj(me.from_date).getTime(), me.data[0].balance]] - .concat($.map(me.data, function(col, idx) { - if (col.posting_datetime) { - return [[dateutil.str_to_obj(col.posting_datetime).getTime(), col.balance - col.qty], - [dateutil.str_to_obj(col.posting_datetime).getTime(), col.balance]] - } - return null; - })).concat([ - // closing - [dateutil.str_to_obj(me.to_date).getTime(), me.data[me.data.length - 1].balance] - ]), - points: {show: true}, - lines: {show: true, fill: true}, - }); - return data; - }, - get_plot_options: function() { - return { - grid: { hoverable: true, clickable: true }, - xaxis: { mode: "time", - min: dateutil.str_to_obj(this.from_date).getTime(), - max: dateutil.str_to_obj(this.to_date).getTime(), - }, - series: { downsample: { threshold: 1000 } } - } - }, - get_tooltip_text: function(label, x, y) { - var d = new Date(x); - var date = dateutil.obj_to_user(d) + " " + d.getHours() + ":" + d.getMinutes(); - var value = format_number(y); - return value.bold() + " on " + date; - } -}); \ No newline at end of file diff --git a/stock/page/stock_ledger/stock_ledger.txt b/stock/page/stock_ledger/stock_ledger.txt deleted file mode 100644 index 9c2a4b75e5..0000000000 --- a/stock/page/stock_ledger/stock_ledger.txt +++ /dev/null @@ -1,41 +0,0 @@ -[ - { - "creation": "2012-09-21 20:15:14", - "docstatus": 0, - "modified": "2013-07-11 14:44:19", - "modified_by": "Administrator", - "owner": "Administrator" - }, - { - "doctype": "Page", - "icon": "icon-table", - "module": "Stock", - "name": "__common__", - "page_name": "stock-ledger", - "standard": "Yes", - "title": "Stock Ledger" - }, - { - "doctype": "Page Role", - "name": "__common__", - "parent": "stock-ledger", - "parentfield": "roles", - "parenttype": "Page" - }, - { - "doctype": "Page", - "name": "stock-ledger" - }, - { - "doctype": "Page Role", - "role": "Analytics" - }, - { - "doctype": "Page Role", - "role": "Material Manager" - }, - { - "doctype": "Page Role", - "role": "Material User" - } -] \ No newline at end of file From 690c75fa0daf3b839f519b063499fe2ca3ce239f Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 4 Dec 2013 19:16:32 +0530 Subject: [PATCH 05/13] [report] migrated stock level report to script report and renamed to Stock Projected Qty --- patches/1312/p01_delete_old_stock_reports.py | 4 +- stock/page/stock_home/stock_home.js | 7 +-- stock/report/stock_projected_qty/__init__.py | 0 .../stock_projected_qty.js | 33 ++++++++++++ .../stock_projected_qty.py | 54 +++++++++++++++++++ .../stock_projected_qty.txt | 22 ++++++++ 6 files changed, 116 insertions(+), 4 deletions(-) create mode 100644 stock/report/stock_projected_qty/__init__.py create mode 100644 stock/report/stock_projected_qty/stock_projected_qty.js create mode 100644 stock/report/stock_projected_qty/stock_projected_qty.py create mode 100644 stock/report/stock_projected_qty/stock_projected_qty.txt diff --git a/patches/1312/p01_delete_old_stock_reports.py b/patches/1312/p01_delete_old_stock_reports.py index ffa783fc1e..17c8947478 100644 --- a/patches/1312/p01_delete_old_stock_reports.py +++ b/patches/1312/p01_delete_old_stock_reports.py @@ -6,6 +6,8 @@ def execute(): webnotes.delete_doc('Page', 'stock-ledger') webnotes.delete_doc('Page', 'stock-ageing') + webnotes.delete_doc('Page', 'stock-level') os.system("rm -rf app/stock/page/stock_ledger") - os.system("rm -rf app/stock/page/stock_ageing") \ No newline at end of file + os.system("rm -rf app/stock/page/stock_ageing") + os.system("rm -rf app/stock/page/stock_level") \ No newline at end of file diff --git a/stock/page/stock_home/stock_home.js b/stock/page/stock_home/stock_home.js index ec432425b5..3b6fd4cf40 100644 --- a/stock/page/stock_home/stock_home.js +++ b/stock/page/stock_home/stock_home.js @@ -138,7 +138,7 @@ wn.module_page["Stock"] = [ items: [ { "label":wn._("Stock Ledger"), - doctype: "Delivery Note", + doctype: "Item", route: "query-report/Stock Ledger" }, { @@ -146,8 +146,9 @@ wn.module_page["Stock"] = [ page: "stock-balance" }, { - "page":"stock-level", - "label": wn._("Stock Level") + "label":wn._("Stock Projected Qty"), + doctype: "Item", + route: "query-report/Stock Projected Qty" }, { "label":wn._("Stock Ageing"), diff --git a/stock/report/stock_projected_qty/__init__.py b/stock/report/stock_projected_qty/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/stock/report/stock_projected_qty/stock_projected_qty.js b/stock/report/stock_projected_qty/stock_projected_qty.js new file mode 100644 index 0000000000..a0ad755ed0 --- /dev/null +++ b/stock/report/stock_projected_qty/stock_projected_qty.js @@ -0,0 +1,33 @@ +// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +// License: GNU General Public License v3. See license.txt + +wn.query_reports["Stock Projected Qty"] = { + "filters": [ + { + "fieldname":"company", + "label": wn._("Company"), + "fieldtype": "Link", + "options": "Company", + "default": wn.defaults.get_user_default("company"), + "reqd": 1 + }, + { + "fieldname":"warehouse", + "label": wn._("Warehouse"), + "fieldtype": "Link", + "options": "Warehouse" + }, + { + "fieldname":"item_code", + "label": wn._("Item"), + "fieldtype": "Link", + "options": "Item" + }, + { + "fieldname":"brand", + "label": wn._("Brand"), + "fieldtype": "Link", + "options": "Brand" + } + ] +} \ No newline at end of file diff --git a/stock/report/stock_projected_qty/stock_projected_qty.py b/stock/report/stock_projected_qty/stock_projected_qty.py new file mode 100644 index 0000000000..126cc2c34e --- /dev/null +++ b/stock/report/stock_projected_qty/stock_projected_qty.py @@ -0,0 +1,54 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +import webnotes +from webnotes import _ + +def execute(filters=None): + columns = get_columns() + if not filters.get("company"): + webnotes.throw(_("Company is mandatory")) + + data = webnotes.conn.sql("""select + item.name, item.item_name, description, brand, warehouse, item.stock_uom, + actual_qty, planned_qty, indented_qty, ordered_qty, reserved_qty, + projected_qty, item.re_order_level, item.re_order_qty + from `tabBin` bin, + (select name, company from tabWarehouse {warehouse_conditions}) wh, + (select name, item_name, description, stock_uom, brand, re_order_level, re_order_qty + from `tabItem` {item_conditions}) item + where item_code = item.name and warehouse = wh.name + order by item.name, wh.name"""\ + .format(item_conditions=get_item_conditions(filters), + warehouse_conditions=get_warehouse_conditions(filters)), filters, debug=1) + + return columns, data + +def get_columns(): + return ["Item Code:Link/Item:140", "Item Name::100", "Description::200", + "Brand:Link/Brand:100", "Warehouse:Link/Warehouse:120", "UOM:Link/UOM:100", + "Actual Qty:Float:100", "Planned Qty:Float:100", "Requested Qty:Float:110", + "Ordered Qty:Float:100", "Reserved Qty:Float:100", "Projected Qty:Float:100", + "Reorder Level:Float:100", "Reorder Qty:Float:100"] + +def get_item_conditions(filters): + conditions = [] + if filters.get("item_code"): + conditions.append("name=%(item_code)s") + if filters.get("brand"): + conditions.append("brand=%(brand)s") + + return "where {}".format(" and ".join(conditions)) if conditions else "" + +def get_warehouse_conditions(filters): + conditions = [] + if not filters.get("company"): + webnotes.throw(_("Company is mandatory")) + else: + conditions.append("company=%(company)s") + + if filters.get("warehouse"): + conditions.append("name=%(warehouse)s") + + return "where {}".format(" and ".join(conditions)) if conditions else "" \ No newline at end of file diff --git a/stock/report/stock_projected_qty/stock_projected_qty.txt b/stock/report/stock_projected_qty/stock_projected_qty.txt new file mode 100644 index 0000000000..1998f7ae74 --- /dev/null +++ b/stock/report/stock_projected_qty/stock_projected_qty.txt @@ -0,0 +1,22 @@ +[ + { + "creation": "2013-12-04 18:21:56", + "docstatus": 0, + "modified": "2013-12-04 18:21:56", + "modified_by": "Administrator", + "owner": "Administrator" + }, + { + "add_total_row": 1, + "doctype": "Report", + "is_standard": "Yes", + "name": "__common__", + "ref_doctype": "Item", + "report_name": "Stock Projected Qty", + "report_type": "Script Report" + }, + { + "doctype": "Report", + "name": "Stock Projected Qty" + } +] \ No newline at end of file From 01d2811ccd5b5815179ec757ef1aaf446b8d0084 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 4 Dec 2013 19:16:50 +0530 Subject: [PATCH 06/13] [report] migrated stock level report to script report and renamed to Stock Projected Qty --- stock/page/stock_level/README.md | 1 - stock/page/stock_level/__init__.py | 0 stock/page/stock_level/stock_level.js | 228 ------------------------- stock/page/stock_level/stock_level.txt | 37 ---- 4 files changed, 266 deletions(-) delete mode 100644 stock/page/stock_level/README.md delete mode 100644 stock/page/stock_level/__init__.py delete mode 100644 stock/page/stock_level/stock_level.js delete mode 100644 stock/page/stock_level/stock_level.txt diff --git a/stock/page/stock_level/README.md b/stock/page/stock_level/README.md deleted file mode 100644 index 43b2b0fbde..0000000000 --- a/stock/page/stock_level/README.md +++ /dev/null @@ -1 +0,0 @@ -Stock levels (actual, planned, reserved, ordered) for Items on a particular date. \ No newline at end of file diff --git a/stock/page/stock_level/__init__.py b/stock/page/stock_level/__init__.py deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/stock/page/stock_level/stock_level.js b/stock/page/stock_level/stock_level.js deleted file mode 100644 index c50879160e..0000000000 --- a/stock/page/stock_level/stock_level.js +++ /dev/null @@ -1,228 +0,0 @@ -// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors -// License: GNU General Public License v3. See license.txt - -wn.pages['stock-level'].onload = function(wrapper) { - wn.ui.make_app_page({ - parent: wrapper, - title: wn._('Stock Level'), - single_column: true - }); - - new erpnext.StockLevel(wrapper); - - - wrapper.appframe.add_module_icon("Stock") - ; -} - -wn.require("app/js/stock_grid_report.js"); - -erpnext.StockLevel = erpnext.StockGridReport.extend({ - init: function(wrapper) { - var me = this; - - this._super({ - title: wn._("Stock Level"), - page: wrapper, - parent: $(wrapper).find('.layout-main'), - appframe: wrapper.appframe, - doctypes: ["Item", "Warehouse", "Stock Ledger Entry", "Production Order", - "Material Request Item", "Purchase Order Item", "Sales Order Item", "Brand", "Serial No"], - }); - - this.wrapper.bind("make", function() { - wn.utils.set_footnote(me, me.wrapper.get(0), - "
    \ -
  • \ - Projected Qty = Actual Qty + Planned Qty + Requested Qty \ - + Ordered Qty - Reserved Qty
  • \ -
      \ -
    • "+wn._("Actual Qty: Quantity available in the warehouse.") +"
    • "+ - "
    • "+wn._("Planned Qty: Quantity, for which, Production Order has been raised,")+ - wn._("but is pending to be manufactured.")+ "
    • " + - "
    • "+wn._("Requested Qty: Quantity requested for purchase, but not ordered.") + "
    • " + - "
    • " + wn._("Ordered Qty: Quantity ordered for purchase, but not received.")+ "
    • " + - "
    • " + wn._("Reserved Qty: Quantity ordered for sale, but not delivered.") + "
    • " + - "
    \ -
"); - }); - }, - - setup_columns: function() { - this.columns = [ - {id: "item_code", name: wn._("Item Code"), field: "item_code", width: 160, - link_formatter: { - filter_input: "item_code", - open_btn: true, - doctype: '"Item"', - }}, - {id: "item_name", name: wn._("Item Name"), field: "item_name", width: 100, - formatter: this.text_formatter}, - {id: "description", name: wn._("Description"), field: "description", width: 200, - formatter: this.text_formatter}, - {id: "brand", name: wn._("Brand"), field: "brand", width: 100, - link_formatter: {filter_input: "brand"}}, - {id: "warehouse", name: wn._("Warehouse"), field: "warehouse", width: 100, - link_formatter: {filter_input: "warehouse"}}, - {id: "uom", name: wn._("UOM"), field: "uom", width: 60}, - {id: "actual_qty", name: wn._("Actual Qty"), - field: "actual_qty", width: 80, formatter: this.currency_formatter}, - {id: "planned_qty", name: wn._("Planned Qty"), - field: "planned_qty", width: 80, formatter: this.currency_formatter}, - {id: "requested_qty", name: wn._("Requested Qty"), - field: "requested_qty", width: 80, formatter: this.currency_formatter}, - {id: "ordered_qty", name: wn._("Ordered Qty"), - field: "ordered_qty", width: 80, formatter: this.currency_formatter}, - {id: "reserved_qty", name: wn._("Reserved Qty"), - field: "reserved_qty", width: 80, formatter: this.currency_formatter}, - {id: "projected_qty", name: wn._("Projected Qty"), - field: "projected_qty", width: 80, formatter: this.currency_formatter}, - {id: "re_order_level", name: wn._("Re-Order Level"), - field: "re_order_level", width: 80, formatter: this.currency_formatter}, - {id: "re_order_qty", name: wn._("Re-Order Qty"), - field: "re_order_qty", width: 80, formatter: this.currency_formatter}, - ]; - }, - - filters: [ - {fieldtype:"Link", label: wn._("Item Code"), link:"Item", default_value: "Select Item...", - filter: function(val, item, opts) { - return item.item_code == val || !val; - }}, - - {fieldtype:"Select", label: wn._("Warehouse"), link:"Warehouse", - default_value: "Select Warehouse...", filter: function(val, item, opts) { - return item.warehouse == val || val == opts.default_value; - }}, - - {fieldtype:"Select", label: wn._("Brand"), link:"Brand", - default_value: "Select Brand...", filter: function(val, item, opts) { - return val == opts.default_value || item.brand == val; - }}, - {fieldtype:"Button", label: wn._("Refresh"), icon:"icon-refresh icon-white"}, - {fieldtype:"Button", label: wn._("Reset Filters")} - ], - - setup_filters: function() { - var me = this; - this._super(); - - this.wrapper.bind("apply_filters_from_route", function() { me.toggle_enable_brand(); }); - this.filter_inputs.item_code.change(function() { me.toggle_enable_brand(); }); - - this.trigger_refresh_on_change(["item_code", "warehouse", "brand"]); - }, - - toggle_enable_brand: function() { - if(!this.filter_inputs.item_code.val()) { - this.filter_inputs.brand.prop("disabled", false); - } else { - this.filter_inputs.brand - .val(this.filter_inputs.brand.get(0).opts.default_value) - .prop("disabled", true); - } - }, - - init_filter_values: function() { - this._super(); - this.filter_inputs.warehouse.get(0).selectedIndex = 0; - }, - - prepare_data: function() { - var me = this; - - if(!this._data) { - this._data = []; - this.item_warehouse_map = {}; - this.item_by_name = this.make_name_map(wn.report_dump.data["Item"]); - this.calculate_quantities(); - } - - this.data = [].concat(this._data); - this.data = $.map(this.data, function(d) { - return me.apply_filters(d) ? d : null; - }); - - this.calculate_total(); - }, - - calculate_quantities: function() { - var me = this; - $.each([ - ["Stock Ledger Entry", "actual_qty"], - ["Production Order", "planned_qty"], - ["Material Request Item", "requested_qty"], - ["Purchase Order Item", "ordered_qty"], - ["Sales Order Item", "reserved_qty"]], - function(i, v) { - $.each(wn.report_dump.data[v[0]], function(i, item) { - var row = me.get_row(item.item_code, item.warehouse); - row[v[1]] += flt(item.qty); - }); - } - ); - - // sort by item, warehouse - this._data = $.map(Object.keys(this.item_warehouse_map).sort(), function(key) { - return me.item_warehouse_map[key]; - }); - - // calculate projected qty - $.each(this._data, function(i, row) { - row.projected_qty = row.actual_qty + row.planned_qty + row.requested_qty - + row.ordered_qty - row.reserved_qty; - }); - - // filter out rows with zero values - this._data = $.map(this._data, function(d) { - return me.apply_zero_filter(null, d, null, me) ? d : null; - }); - }, - - get_row: function(item_code, warehouse) { - var key = item_code + ":" + warehouse; - if(!this.item_warehouse_map[key]) { - var item = this.item_by_name[item_code]; - var row = { - item_code: item_code, - warehouse: warehouse, - description: item.description, - brand: item.brand, - item_name: item.item_name || item.name, - uom: item.stock_uom, - id: key, - } - this.reset_item_values(row); - - row["re_order_level"] = item.re_order_level - row["re_order_qty"] = item.re_order_qty - - this.item_warehouse_map[key] = row; - } - return this.item_warehouse_map[key]; - }, - - calculate_total: function() { - var me = this; - // show total if a specific item is selected and warehouse is not filtered - if(this.is_default("warehouse") && !this.is_default("item_code")) { - var total = { - id: "_total", - item_code: "Total", - _style: "font-weight: bold", - _show: true - }; - this.reset_item_values(total); - - $.each(this.data, function(i, row) { - $.each(me.columns, function(i, col) { - if (col.formatter==me.currency_formatter) { - total[col.id] += row[col.id]; - } - }); - }); - - this.data = this.data.concat([total]); - } - } -}) diff --git a/stock/page/stock_level/stock_level.txt b/stock/page/stock_level/stock_level.txt deleted file mode 100644 index bae3d9c9b2..0000000000 --- a/stock/page/stock_level/stock_level.txt +++ /dev/null @@ -1,37 +0,0 @@ -[ - { - "creation": "2012-12-31 10:52:14", - "docstatus": 0, - "modified": "2013-07-11 14:44:21", - "modified_by": "Administrator", - "owner": "Administrator" - }, - { - "doctype": "Page", - "icon": "icon-table", - "module": "Stock", - "name": "__common__", - "page_name": "stock-level", - "standard": "Yes", - "title": "Stock Level" - }, - { - "doctype": "Page Role", - "name": "__common__", - "parent": "stock-level", - "parentfield": "roles", - "parenttype": "Page" - }, - { - "doctype": "Page", - "name": "stock-level" - }, - { - "doctype": "Page Role", - "role": "Material Manager" - }, - { - "doctype": "Page Role", - "role": "Analytics" - } -] \ No newline at end of file From 86da17d5d9ae71272116c67876ce831d6b46f159 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 6 Dec 2013 13:23:31 +0530 Subject: [PATCH 07/13] [minor] removed mandatory validation in server side --- stock/report/stock_ageing/stock_ageing.py | 6 ------ .../stock_projected_qty/stock_projected_qty.py | 17 +++-------------- 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/stock/report/stock_ageing/stock_ageing.py b/stock/report/stock_ageing/stock_ageing.py index f688ed96ef..fa052050ca 100644 --- a/stock/report/stock_ageing/stock_ageing.py +++ b/stock/report/stock_ageing/stock_ageing.py @@ -4,7 +4,6 @@ from __future__ import unicode_literals import webnotes from webnotes.utils import date_diff -from webnotes import _ def execute(filters=None): @@ -64,11 +63,6 @@ def get_fifo_queue(filters): return item_details def get_stock_ledger_entries(filters): - if not filters.get("company"): - webnotes.throw(_("Company is mandatory")) - if not filters.get("to_date"): - webnotes.throw(_("To Date is mandatory")) - return webnotes.conn.sql("""select item.name, item.item_name, brand, description, item.stock_uom, actual_qty, posting_date from `tabStock Ledger Entry` sle, diff --git a/stock/report/stock_projected_qty/stock_projected_qty.py b/stock/report/stock_projected_qty/stock_projected_qty.py index 126cc2c34e..232c744c87 100644 --- a/stock/report/stock_projected_qty/stock_projected_qty.py +++ b/stock/report/stock_projected_qty/stock_projected_qty.py @@ -3,19 +3,17 @@ from __future__ import unicode_literals import webnotes -from webnotes import _ def execute(filters=None): columns = get_columns() - if not filters.get("company"): - webnotes.throw(_("Company is mandatory")) data = webnotes.conn.sql("""select item.name, item.item_name, description, brand, warehouse, item.stock_uom, actual_qty, planned_qty, indented_qty, ordered_qty, reserved_qty, projected_qty, item.re_order_level, item.re_order_qty from `tabBin` bin, - (select name, company from tabWarehouse {warehouse_conditions}) wh, + (select name, company from tabWarehouse + where company=%(company)s {warehouse_conditions}) wh, (select name, item_name, description, stock_uom, brand, re_order_level, re_order_qty from `tabItem` {item_conditions}) item where item_code = item.name and warehouse = wh.name @@ -42,13 +40,4 @@ def get_item_conditions(filters): return "where {}".format(" and ".join(conditions)) if conditions else "" def get_warehouse_conditions(filters): - conditions = [] - if not filters.get("company"): - webnotes.throw(_("Company is mandatory")) - else: - conditions.append("company=%(company)s") - - if filters.get("warehouse"): - conditions.append("name=%(warehouse)s") - - return "where {}".format(" and ".join(conditions)) if conditions else "" \ No newline at end of file + return " and name=%(warehouse)s" if filters.get("warehouse") else "" \ No newline at end of file From c313ca99ffc6b3a9342e09f432b536c8e39730c3 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 6 Dec 2013 16:36:23 +0530 Subject: [PATCH 08/13] [report]general ledger report migrated to script report --- accounts/report/general_ledger/__init__.py | 0 .../report/general_ledger/general_ledger.js | 51 +++++++++++++++++++ .../report/general_ledger/general_ledger.py | 49 ++++++++++++++++++ .../report/general_ledger/general_ledger.txt | 21 ++++++++ 4 files changed, 121 insertions(+) create mode 100644 accounts/report/general_ledger/__init__.py create mode 100644 accounts/report/general_ledger/general_ledger.js create mode 100644 accounts/report/general_ledger/general_ledger.py create mode 100644 accounts/report/general_ledger/general_ledger.txt diff --git a/accounts/report/general_ledger/__init__.py b/accounts/report/general_ledger/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/accounts/report/general_ledger/general_ledger.js b/accounts/report/general_ledger/general_ledger.js new file mode 100644 index 0000000000..b0cd485527 --- /dev/null +++ b/accounts/report/general_ledger/general_ledger.js @@ -0,0 +1,51 @@ +// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +// License: GNU General Public License v3. See license.txt + +wn.query_reports["General Ledger"] = { + "filters": [ + { + "fieldname":"company", + "label": wn._("Company"), + "fieldtype": "Link", + "options": "Company", + "default": wn.defaults.get_user_default("company"), + "reqd": 1 + }, + { + "fieldname":"account", + "label": wn._("Account"), + "fieldtype": "Link", + "options": "Account" + }, + { + "fieldname":"voucher_no", + "label": wn._("Voucher No"), + "fieldtype": "Data", + }, + { + "fieldtype": "Break", + }, + { + "fieldname":"from_date", + "label": wn._("From Date"), + "fieldtype": "Date", + "default": wn.datetime.add_months(wn.datetime.get_today(), -1), + "reqd": 1, + "width": "60px" + }, + { + "fieldname":"to_date", + "label": wn._("To Date"), + "fieldtype": "Date", + "default": wn.datetime.get_today(), + "reqd": 1, + "width": "60px" + }, + { + "fieldname":"group_by", + "label": wn._("Group by"), + "fieldtype": "Select", + "options": "\nAccount\nVoucher" + } + ] +} \ No newline at end of file diff --git a/accounts/report/general_ledger/general_ledger.py b/accounts/report/general_ledger/general_ledger.py new file mode 100644 index 0000000000..e99ea2016b --- /dev/null +++ b/accounts/report/general_ledger/general_ledger.py @@ -0,0 +1,49 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +import webnotes +from webnotes.utils import flt + +def execute(filters=None): + columns = get_columns() + if filters.get("group_by"): + data = get_grouped_gle(filters) + else: + data = get_gl_entries(filters) + + return columns, data + +def get_columns(): + return ["Posting Date:Date:100", "Account:Link/Account:200", "Debit:Currency:100", + "Credit:Currency:100", "Voucher Type::120", "Voucher No::160", "Remarks::200"] + +def get_gl_entries(filters): + return webnotes.conn.sql("""select + posting_date, account, debit, credit, voucher_type, voucher_no, cost_center, remarks + from `tabGL Entry` + where company=%(company)s + and posting_date between %(from_date)s and %(to_date)s + {conditions} + order by posting_date, account"""\ + .format(conditions=get_conditions(filters)), filters) + +def get_conditions(filters): + return " and account=%(account)s" if filters.get("account") else "" + +def get_grouped_gle(filters): + gle_map = {} + gle = get_gl_entries(filters) + for d in gle: + gle_map.setdefault(d[1 if filters["group_by"]=="Account" else 5], []).append(d) + + data = [] + for entries in gle_map.values(): + total_debit = total_credit = 0.0 + for entry in entries: + data.append(entry) + total_debit += flt(entry[2]) + total_credit += flt(entry[3]) + + data.append(["", "Total", total_debit, total_credit, "", "", ""]) + return data \ No newline at end of file diff --git a/accounts/report/general_ledger/general_ledger.txt b/accounts/report/general_ledger/general_ledger.txt new file mode 100644 index 0000000000..ef169dbe88 --- /dev/null +++ b/accounts/report/general_ledger/general_ledger.txt @@ -0,0 +1,21 @@ +[ + { + "creation": "2013-12-06 13:22:23", + "docstatus": 0, + "modified": "2013-12-06 13:22:23", + "modified_by": "Administrator", + "owner": "Administrator" + }, + { + "doctype": "Report", + "is_standard": "Yes", + "name": "__common__", + "ref_doctype": "GL Entry", + "report_name": "General Ledger", + "report_type": "Script Report" + }, + { + "doctype": "Report", + "name": "General Ledger" + } +] \ No newline at end of file From 4a8930fc67efcaa13853b9e4d81afa9b72bb3918 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 6 Dec 2013 18:07:23 +0530 Subject: [PATCH 09/13] [report]general ledger report migrated to script report --- accounts/report/general_ledger/general_ledger.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/accounts/report/general_ledger/general_ledger.py b/accounts/report/general_ledger/general_ledger.py index e99ea2016b..23c79d8996 100644 --- a/accounts/report/general_ledger/general_ledger.py +++ b/accounts/report/general_ledger/general_ledger.py @@ -16,7 +16,8 @@ def execute(filters=None): def get_columns(): return ["Posting Date:Date:100", "Account:Link/Account:200", "Debit:Currency:100", - "Credit:Currency:100", "Voucher Type::120", "Voucher No::160", "Remarks::200"] + "Credit:Currency:100", "Voucher Type::120", "Voucher No::160", + "Cost Center:Link/Cost Center:100", "Remarks::200"] def get_gl_entries(filters): return webnotes.conn.sql("""select From 57e89ff6f132bf47e818f26f437fce3a4d1b2205 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 17 Dec 2013 16:09:21 +0530 Subject: [PATCH 10/13] [reports] general ledger: grid report to script report --- accounts/page/accounts_home/accounts_home.js | 3 +- .../report/general_ledger/general_ledger.js | 12 ++--- .../report/general_ledger/general_ledger.py | 47 +++++++++++++++---- stock/report/stock_ageing/stock_ageing.py | 11 +++-- .../stock_projected_qty.py | 5 +- 5 files changed, 55 insertions(+), 23 deletions(-) diff --git a/accounts/page/accounts_home/accounts_home.js b/accounts/page/accounts_home/accounts_home.js index 69c7da1b7c..db7a20cc79 100644 --- a/accounts/page/accounts_home/accounts_home.js +++ b/accounts/page/accounts_home/accounts_home.js @@ -157,7 +157,8 @@ wn.module_page["Accounts"] = [ items: [ { "label":wn._("General Ledger"), - page: "general-ledger" + doctype: "GL Entry", + route: "query-report/General Ledger" }, { "label":wn._("Trial Balance"), diff --git a/accounts/report/general_ledger/general_ledger.js b/accounts/report/general_ledger/general_ledger.js index b0cd485527..7985277115 100644 --- a/accounts/report/general_ledger/general_ledger.js +++ b/accounts/report/general_ledger/general_ledger.js @@ -22,6 +22,12 @@ wn.query_reports["General Ledger"] = { "label": wn._("Voucher No"), "fieldtype": "Data", }, + { + "fieldname":"group_by", + "label": wn._("Group by"), + "fieldtype": "Select", + "options": "\nGroup by Account\nGroup by Voucher" + }, { "fieldtype": "Break", }, @@ -40,12 +46,6 @@ wn.query_reports["General Ledger"] = { "default": wn.datetime.get_today(), "reqd": 1, "width": "60px" - }, - { - "fieldname":"group_by", - "label": wn._("Group by"), - "fieldtype": "Select", - "options": "\nAccount\nVoucher" } ] } \ No newline at end of file diff --git a/accounts/report/general_ledger/general_ledger.py b/accounts/report/general_ledger/general_ledger.py index 23c79d8996..fcf8010715 100644 --- a/accounts/report/general_ledger/general_ledger.py +++ b/accounts/report/general_ledger/general_ledger.py @@ -4,16 +4,28 @@ from __future__ import unicode_literals import webnotes from webnotes.utils import flt +from webnotes import _ def execute(filters=None): + validate_filters(filters) columns = get_columns() + if filters.get("group_by"): data = get_grouped_gle(filters) else: data = get_gl_entries(filters) + if data: + data.append(get_total_row(data)) return columns, data +def validate_filters(filters): + if filters.get("account") and filters.get("group_by") == "Group by Account": + webnotes.throw(_("Can not filter based on Account, if grouped by Account")) + + if filters.get("voucher_no") and filters.get("group_by") == "Group by Voucher": + webnotes.throw(_("Can not filter based on Voucher No, if grouped by Voucher")) + def get_columns(): return ["Posting Date:Date:100", "Account:Link/Account:200", "Debit:Currency:100", "Credit:Currency:100", "Voucher Type::120", "Voucher No::160", @@ -27,24 +39,41 @@ def get_gl_entries(filters): and posting_date between %(from_date)s and %(to_date)s {conditions} order by posting_date, account"""\ - .format(conditions=get_conditions(filters)), filters) + .format(conditions=get_conditions(filters)), filters, as_list=1) def get_conditions(filters): - return " and account=%(account)s" if filters.get("account") else "" + conditions = [] + if filters.get("account"): + conditions.append("account=%(account)s") + if filters.get("voucher_no"): + conditions.append("voucher_no=%(voucher_no)s") + return "and {}".format(" and ".join(conditions)) if conditions else "" + def get_grouped_gle(filters): gle_map = {} gle = get_gl_entries(filters) for d in gle: - gle_map.setdefault(d[1 if filters["group_by"]=="Account" else 5], []).append(d) + gle_map.setdefault(d[1 if filters["group_by"]=="Group by Account" else 5], []).append(d) data = [] for entries in gle_map.values(): - total_debit = total_credit = 0.0 + subtotal_debit = subtotal_credit = 0.0 for entry in entries: data.append(entry) - total_debit += flt(entry[2]) - total_credit += flt(entry[3]) - - data.append(["", "Total", total_debit, total_credit, "", "", ""]) - return data \ No newline at end of file + subtotal_debit += flt(entry[2]) + subtotal_credit += flt(entry[3]) + + data.append(["", "Total", subtotal_debit, subtotal_credit, "", "", ""]) + + if data: + data.append(get_total_row(gle)) + return data + +def get_total_row(gle): + total_debit = total_credit = 0.0 + for d in gle: + total_debit += flt(d[2]) + total_credit += flt(d[3]) + + return ["", "Total Debit/Credit", total_debit, total_credit, "", "", ""] \ No newline at end of file diff --git a/stock/report/stock_ageing/stock_ageing.py b/stock/report/stock_ageing/stock_ageing.py index fa052050ca..defe7248d2 100644 --- a/stock/report/stock_ageing/stock_ageing.py +++ b/stock/report/stock_ageing/stock_ageing.py @@ -20,8 +20,8 @@ def execute(filters=None): earliest_age = date_diff(to_date, fifo_queue[0][1]) latest_age = date_diff(to_date, fifo_queue[-1][1]) - data.append([item, details.item_name, details.description, details.brand, - average_age, earliest_age, latest_age, details.stock_uom]) + data.append([item, details.item_name, details.description, details.item_group, + details.brand, average_age, earliest_age, latest_age, details.stock_uom]) return columns, data @@ -36,8 +36,8 @@ def get_average_age(fifo_queue, to_date): def get_columns(): return ["Item Code:Link/Item:100", "Item Name::100", "Description::200", - "Brand:Link/Brand:100", "Average Age:Float:100", "Earliest:Int:80", - "Latest:Int:80", "UOM:Link/UOM:100"] + "Item Group:Link/Item Group:100", "Brand:Link/Brand:100", "Average Age:Float:100", + "Earliest:Int:80", "Latest:Int:80", "UOM:Link/UOM:100"] def get_fifo_queue(filters): item_details = {} @@ -64,7 +64,8 @@ def get_fifo_queue(filters): def get_stock_ledger_entries(filters): return webnotes.conn.sql("""select - item.name, item.item_name, brand, description, item.stock_uom, actual_qty, posting_date + item.name, item.item_name, item_group, brand, description, item.stock_uom, + actual_qty, posting_date from `tabStock Ledger Entry` sle, (select name, item_name, description, stock_uom, brand from `tabItem` {item_conditions}) item diff --git a/stock/report/stock_projected_qty/stock_projected_qty.py b/stock/report/stock_projected_qty/stock_projected_qty.py index 232c744c87..11d519558d 100644 --- a/stock/report/stock_projected_qty/stock_projected_qty.py +++ b/stock/report/stock_projected_qty/stock_projected_qty.py @@ -8,13 +8,14 @@ def execute(filters=None): columns = get_columns() data = webnotes.conn.sql("""select - item.name, item.item_name, description, brand, warehouse, item.stock_uom, + item.name, item.item_name, description, item_group, brand, warehouse, item.stock_uom, actual_qty, planned_qty, indented_qty, ordered_qty, reserved_qty, projected_qty, item.re_order_level, item.re_order_qty from `tabBin` bin, (select name, company from tabWarehouse where company=%(company)s {warehouse_conditions}) wh, - (select name, item_name, description, stock_uom, brand, re_order_level, re_order_qty + (select name, item_name, description, stock_uom, item_group, + brand, re_order_level, re_order_qty from `tabItem` {item_conditions}) item where item_code = item.name and warehouse = wh.name order by item.name, wh.name"""\ From 592d27e7f10aeb0b183ba0f9695e212f6a78f252 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 17 Dec 2013 16:20:11 +0530 Subject: [PATCH 11/13] [reports] general ledger: grid report to script report --- accounts/page/general_ledger/README.md | 1 - accounts/page/general_ledger/__init__.py | 1 - .../page/general_ledger/general_ledger.css | 0 .../page/general_ledger/general_ledger.html | 0 .../page/general_ledger/general_ledger.js | 396 ------------------ .../page/general_ledger/general_ledger.txt | 41 -- patches/1312/p01_delete_old_stock_reports.py | 4 +- 7 files changed, 3 insertions(+), 440 deletions(-) delete mode 100644 accounts/page/general_ledger/README.md delete mode 100644 accounts/page/general_ledger/__init__.py delete mode 100644 accounts/page/general_ledger/general_ledger.css delete mode 100644 accounts/page/general_ledger/general_ledger.html delete mode 100644 accounts/page/general_ledger/general_ledger.js delete mode 100644 accounts/page/general_ledger/general_ledger.txt diff --git a/accounts/page/general_ledger/README.md b/accounts/page/general_ledger/README.md deleted file mode 100644 index 8c51e9152c..0000000000 --- a/accounts/page/general_ledger/README.md +++ /dev/null @@ -1 +0,0 @@ -General Ledger report (for all transactions and accounts). \ No newline at end of file diff --git a/accounts/page/general_ledger/__init__.py b/accounts/page/general_ledger/__init__.py deleted file mode 100644 index baffc48825..0000000000 --- a/accounts/page/general_ledger/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from __future__ import unicode_literals diff --git a/accounts/page/general_ledger/general_ledger.css b/accounts/page/general_ledger/general_ledger.css deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/accounts/page/general_ledger/general_ledger.html b/accounts/page/general_ledger/general_ledger.html deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/accounts/page/general_ledger/general_ledger.js b/accounts/page/general_ledger/general_ledger.js deleted file mode 100644 index 7eeab58416..0000000000 --- a/accounts/page/general_ledger/general_ledger.js +++ /dev/null @@ -1,396 +0,0 @@ -// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors -// License: GNU General Public License v3. See license.txt - -wn.pages['general-ledger'].onload = function(wrapper) { - wn.ui.make_app_page({ - parent: wrapper, - title: wn._('General Ledger'), - single_column: true - }); - - erpnext.general_ledger = new erpnext.GeneralLedger(wrapper); - wrapper.appframe.add_module_icon("Accounts") - -} - -erpnext.GeneralLedger = wn.views.GridReport.extend({ - init: function(wrapper) { - this._super({ - title: wn._("General Ledger"), - page: wrapper, - parent: $(wrapper).find('.layout-main'), - appframe: wrapper.appframe, - doctypes: ["Company", "Account", "GL Entry", "Cost Center"], - }); - }, - setup_columns: function() { - this.columns = [ - {id: "posting_date", name: wn._("Posting Date"), field: "posting_date", width: 100, - formatter: this.date_formatter}, - {id: "account", name: wn._("Account"), field: "account", width: 240, - link_formatter: { - filter_input: "account", - open_btn: true, - doctype: "'Account'" - }}, - {id: "against_account", name: wn._("Against Account"), field: "against_account", - width: 240, hidden: !this.account}, - - {id: "debit", name: wn._("Debit"), field: "debit", width: 100, - formatter: this.currency_formatter}, - {id: "credit", name: wn._("Credit"), field: "credit", width: 100, - formatter: this.currency_formatter}, - {id: "voucher_type", name: wn._("Voucher Type"), field: "voucher_type", width: 120}, - {id: "voucher_no", name: wn._("Voucher No"), field: "voucher_no", width: 160, - link_formatter: { - filter_input: "voucher_no", - open_btn: true, - doctype: "dataContext.voucher_type" - }}, - {id: "remarks", name: wn._("Remarks"), field: "remarks", width: 200, - formatter: this.text_formatter}, - - ]; - }, - - filters: [ - {fieldtype:"Select", label: wn._("Company"), link:"Company", default_value: wn._("Select Company..."), - filter: function(val, item, opts) { - return item.company == val || val == opts.default_value; - }}, - {fieldtype:"Link", label: wn._("Account"), link:"Account", - filter: function(val, item, opts, me) { - if(!val) { - return true; - } else { - // true if GL Entry belongs to selected - // account ledger or group - return me.is_child_account(val, item.account); - } - }}, - {fieldtype:"Data", label: wn._("Voucher No"), - filter: function(val, item, opts) { - if(!val) return true; - return (item.voucher_no && item.voucher_no.indexOf(val)!=-1); - }}, - {fieldtype:"Date", label: wn._("From Date"), filter: function(val, item) { - return dateutil.str_to_obj(val) <= dateutil.str_to_obj(item.posting_date); - }}, - {fieldtype:"Label", label: wn._("To")}, - {fieldtype:"Date", label: wn._("To Date"), filter: function(val, item) { - return dateutil.str_to_obj(val) >= dateutil.str_to_obj(item.posting_date); - }}, - {fieldtype: "Check", label: wn._("Group by Ledger")}, - {fieldtype: "Check", label: wn._("Group by Voucher")}, - {fieldtype:"Button", label: wn._("Refresh"), icon:"icon-refresh icon-white"}, - {fieldtype:"Button", label: wn._("Reset Filters")} - ], - setup_filters: function() { - this._super(); - var me = this; - - this.accounts_by_company = this.make_accounts_by_company(); - - // filter accounts options by company - this.filter_inputs.company.on("change", function() { - me.setup_account_filter(this); - me.refresh(); - }); - - this.trigger_refresh_on_change(["group_by_ledger", "group_by_voucher"]); - }, - setup_account_filter: function(company_filter) { - var me = this; - - var $account = me.filter_inputs.account; - var company = $(company_filter).val(); - var default_company = this.filter_inputs.company.get(0).opts.default_value; - var opts = $account.get(0).opts; - opts.list = $.map(wn.report_dump.data["Account"], function(ac) { - return (company===default_company || - me.accounts_by_company[company].indexOf(ac.name)!=-1) ? - ac.name : null; - }); - - this.set_autocomplete($account, opts.list); - - }, - init_filter_values: function() { - this._super(); - this.toggle_group_by_checks(); - this.filter_inputs.company.trigger("change"); - }, - apply_filters_from_route: function() { - this._super(); - this.toggle_group_by_checks(); - }, - make_accounts_by_company: function() { - var accounts_by_company = {}; - var me = this; - $.each(wn.report_dump.data["Account"], function(i, ac) { - if(!accounts_by_company[ac.company]) accounts_by_company[ac.company] = []; - accounts_by_company[ac.company].push(ac.name); - }); - return accounts_by_company; - }, - is_child_account: function(account, item_account) { - account = this.account_by_name[account]; - item_account = this.account_by_name[item_account]; - return ((item_account.lft >= account.lft) && (item_account.rgt <= account.rgt)); - }, - toggle_group_by_checks: function() { - this.make_account_by_name(); - - // this.filter_inputs.group_by_ledger - // .parent().toggle(!!(this.account_by_name[this.account] - // && this.account_by_name[this.account].group_or_ledger==="Group")); - // - // this.filter_inputs.group_by_voucher - // .parent().toggle(!!(this.account_by_name[this.account] - // && this.account_by_name[this.account].group_or_ledger==="Ledger")); - }, - prepare_data: function() { - var me = this; - var data = wn.report_dump.data["GL Entry"]; - var out = []; - - this.toggle_group_by_checks(); - - var from_date = dateutil.str_to_obj(this.from_date); - var to_date = dateutil.str_to_obj(this.to_date); - - if(to_date < from_date) { - msgprint(wn._("From Date must be before To Date")); - return; - } - - // add Opening, Closing, Totals rows - // if filtered by account and / or voucher - var opening = this.make_summary_row("Opening", this.account); - var totals = this.make_summary_row("Totals", this.account); - - var grouped_ledgers = {}; - $.each(data, function(i, item) { - if(me.apply_filter(item, "company") && - (me.account ? me.is_child_account(me.account, item.account) - : true) && (me.voucher_no ? item.voucher_no==me.voucher_no : true)) { - var date = dateutil.str_to_obj(item.posting_date); - - // create grouping by ledger - if(!grouped_ledgers[item.account]) { - grouped_ledgers[item.account] = { - entries: [], - entries_group_by_voucher: {}, - opening: me.make_summary_row("Opening", item.account), - totals: me.make_summary_row("Totals", item.account), - closing: me.make_summary_row("Closing (Opening + Totals)", - item.account) - }; - } - - if(!grouped_ledgers[item.account].entries_group_by_voucher[item.voucher_no]) { - grouped_ledgers[item.account].entries_group_by_voucher[item.voucher_no] = { - row: {}, - totals: {"debit": 0, "credit": 0} - } - } - - if(!me.voucher_no && (date < from_date || item.is_opening=="Yes")) { - opening.debit += item.debit; - opening.credit += item.credit; - - grouped_ledgers[item.account].opening.debit += item.debit; - grouped_ledgers[item.account].opening.credit += item.credit; - - } else if(date <= to_date) { - - totals.debit += item.debit; - totals.credit += item.credit; - - grouped_ledgers[item.account].totals.debit += item.debit; - grouped_ledgers[item.account].totals.credit += item.credit; - grouped_ledgers[item.account].entries_group_by_voucher[item.voucher_no] - .totals.debit += item.debit; - grouped_ledgers[item.account].entries_group_by_voucher[item.voucher_no] - .totals.credit += item.credit; - } - if(item.account) { - item.against_account = me.voucher_accounts[item.voucher_type + ":" - + item.voucher_no][(item.debit > 0 ? "credits" : "debits")].join(", "); - } - - if(me.apply_filters(item) && (me.voucher_no || item.is_opening=="No")) { - out.push(item); - grouped_ledgers[item.account].entries.push(item); - - if(grouped_ledgers[item.account].entries_group_by_voucher[item.voucher_no].row){ - grouped_ledgers[item.account].entries_group_by_voucher[item.voucher_no] - .row = $.extend({}, item); - } - } - } - }); - - var closing = this.make_summary_row("Closing (Opening + Totals)", this.account); - closing.debit = opening.debit + totals.debit; - closing.credit = opening.credit + totals.credit; - - if(me.account) { - me.appframe.set_title(wn._("General Ledger: ") + me.account); - - // group by ledgers - if(this.account_by_name[this.account].group_or_ledger==="Group" - && this.group_by_ledger) { - out = this.group_data_by_ledger(grouped_ledgers); - } - - if(this.account_by_name[this.account].group_or_ledger==="Ledger" - && this.group_by_voucher) { - out = this.group_data_by_voucher(grouped_ledgers); - } - - opening = me.get_balance(me.account_by_name[me.account].debit_or_credit, opening) - closing = me.get_balance(me.account_by_name[me.account].debit_or_credit, closing) - - out = [opening].concat(out).concat([totals, closing]); - } else { - me.appframe.set_title(wn._("General Ledger")); - out = out.concat([totals]); - } - - this.data = out; - }, - - group_data_by_ledger: function(grouped_ledgers) { - var me = this; - var out = [] - $.each(Object.keys(grouped_ledgers).sort(), function(i, account) { - if(grouped_ledgers[account].entries.length) { - grouped_ledgers[account].closing.debit = - grouped_ledgers[account].opening.debit - + grouped_ledgers[account].totals.debit; - - grouped_ledgers[account].closing.credit = - grouped_ledgers[account].opening.credit - + grouped_ledgers[account].totals.credit; - - grouped_ledgers[account].opening = - me.get_balance(me.account_by_name[me.account].debit_or_credit, - grouped_ledgers[account].opening) - grouped_ledgers[account].closing = - me.get_balance(me.account_by_name[me.account].debit_or_credit, - grouped_ledgers[account].closing) - - out = out.concat([grouped_ledgers[account].opening]) - .concat(grouped_ledgers[account].entries) - .concat([grouped_ledgers[account].totals, - grouped_ledgers[account].closing, - {id: "_blank" + i, debit: "", credit: ""}]); - } - }); - return [{id: "_blank_first", debit: "", credit: ""}].concat(out); - }, - - group_data_by_voucher: function(grouped_ledgers) { - var me = this; - var out = [] - $.each(Object.keys(grouped_ledgers).sort(), function(i, account) { - if(grouped_ledgers[account].entries.length) { - $.each(Object.keys(grouped_ledgers[account].entries_group_by_voucher), - function(j, voucher) { - voucher_dict = grouped_ledgers[account].entries_group_by_voucher[voucher]; - if(voucher_dict && - (voucher_dict.totals.debit || voucher_dict.totals.credit)) { - voucher_dict.row.debit = voucher_dict.totals.debit; - voucher_dict.row.credit = voucher_dict.totals.credit; - voucher_dict.row.id = "entry_grouped_by_" + voucher - out = out.concat(voucher_dict.row); - } - }); - } - }); - return out; - }, - - get_balance: function(debit_or_credit, balance) { - if(debit_or_credit == "Debit") { - balance.debit -= balance.credit; balance.credit = 0; - } else { - balance.credit -= balance.debit; balance.debit = 0; - } - return balance - }, - - make_summary_row: function(label, item_account) { - return { - account: label, - debit: 0.0, - credit: 0.0, - id: ["", label, item_account].join("_").replace(" ", "_").toLowerCase(), - _show: true, - _style: "font-weight: bold" - } - }, - - make_account_by_name: function() { - this.account_by_name = this.make_name_map(wn.report_dump.data["Account"]); - this.make_voucher_accounts_map(); - }, - - make_voucher_accounts_map: function() { - this.voucher_accounts = {}; - var data = wn.report_dump.data["GL Entry"]; - for(var i=0, j=data.length; i 0) { - va.debits.push(gl.account); - } else { - va.credits.push(gl.account); - } - } - }, - - get_plot_data: function() { - var data = []; - var me = this; - if(!me.account || me.voucher_no) return false; - var debit_or_credit = me.account_by_name[me.account].debit_or_credit; - var balance = debit_or_credit=="Debit" ? me.data[0].debit : me.data[0].credit; - data.push({ - label: me.account, - data: [[dateutil.str_to_obj(me.from_date).getTime(), balance]] - .concat($.map(me.data, function(col, idx) { - if (col.posting_date) { - var diff = (debit_or_credit == "Debit" ? 1 : -1) * (flt(col.debit) - flt(col.credit)); - balance += diff; - return [[dateutil.str_to_obj(col.posting_date).getTime(), balance - diff], - [dateutil.str_to_obj(col.posting_date).getTime(), balance]] - } - return null; - })).concat([ - // closing - [dateutil.str_to_obj(me.to_date).getTime(), balance] - ]), - points: {show: true}, - lines: {show: true, fill: true}, - }); - return data; - }, - get_plot_options: function() { - return { - grid: { hoverable: true, clickable: true }, - xaxis: { mode: "time", - min: dateutil.str_to_obj(this.from_date).getTime(), - max: dateutil.str_to_obj(this.to_date).getTime() }, - series: { downsample: { threshold: 1000 } } - } - }, -}); \ No newline at end of file diff --git a/accounts/page/general_ledger/general_ledger.txt b/accounts/page/general_ledger/general_ledger.txt deleted file mode 100644 index 2cc8a601e9..0000000000 --- a/accounts/page/general_ledger/general_ledger.txt +++ /dev/null @@ -1,41 +0,0 @@ -[ - { - "creation": "2012-09-14 11:25:48", - "docstatus": 0, - "modified": "2013-07-11 14:42:21", - "modified_by": "Administrator", - "owner": "Administrator" - }, - { - "doctype": "Page", - "icon": "icon-table", - "module": "Accounts", - "name": "__common__", - "page_name": "general-ledger", - "standard": "Yes", - "title": "General Ledger" - }, - { - "doctype": "Page Role", - "name": "__common__", - "parent": "general-ledger", - "parentfield": "roles", - "parenttype": "Page" - }, - { - "doctype": "Page", - "name": "general-ledger" - }, - { - "doctype": "Page Role", - "role": "Analytics" - }, - { - "doctype": "Page Role", - "role": "Accounts Manager" - }, - { - "doctype": "Page Role", - "role": "Accounts User" - } -] \ No newline at end of file diff --git a/patches/1312/p01_delete_old_stock_reports.py b/patches/1312/p01_delete_old_stock_reports.py index 17c8947478..eac9b7b844 100644 --- a/patches/1312/p01_delete_old_stock_reports.py +++ b/patches/1312/p01_delete_old_stock_reports.py @@ -7,7 +7,9 @@ def execute(): webnotes.delete_doc('Page', 'stock-ledger') webnotes.delete_doc('Page', 'stock-ageing') webnotes.delete_doc('Page', 'stock-level') + webnotes.delete_doc('Page', 'general-ledger') os.system("rm -rf app/stock/page/stock_ledger") os.system("rm -rf app/stock/page/stock_ageing") - os.system("rm -rf app/stock/page/stock_level") \ No newline at end of file + os.system("rm -rf app/stock/page/stock_level") + os.system("rm -rf app/accounts/page/general_ledger") \ No newline at end of file From a4080eb8400093c312ef9abd97ea3106004b148b Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 17 Dec 2013 17:45:50 +0530 Subject: [PATCH 12/13] [fix] [minor] item validation --- stock/doctype/item/item.py | 49 +++++++++++++++----------------------- 1 file changed, 19 insertions(+), 30 deletions(-) diff --git a/stock/doctype/item/item.py b/stock/doctype/item/item.py index a4985e9794..b5884b4111 100644 --- a/stock/doctype/item/item.py +++ b/stock/doctype/item/item.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals import webnotes -from webnotes.utils import cstr, flt, cint +from webnotes.utils import cstr, flt from webnotes.model.doc import addchild from webnotes.model.bean import getlist from webnotes import msgprint, _ @@ -116,40 +116,29 @@ class DocType(DocListController, WebsiteGenerator): self.doc.is_pro_applicable = "No" if self.doc.is_pro_applicable == 'Yes' and self.doc.is_stock_item == 'No': - msgprint("As Production Order can be made for this Item, then Is Stock Item Should be 'Yes' as we maintain it's stock. Refer Manufacturing and Inventory section.", raise_exception=1) + webnotes.throw(_("As Production Order can be made for this item, \ + it must be a stock item.")) if self.doc.has_serial_no == 'Yes' and self.doc.is_stock_item == 'No': msgprint("'Has Serial No' can not be 'Yes' for non-stock item", raise_exception=1) def check_for_active_boms(self): - def _check_for_active_boms(field_label): - if field_label in ['Is Active', 'Is Purchase Item']: - bom_mat = webnotes.conn.sql("""select distinct t1.parent - from `tabBOM Item` t1, `tabBOM` t2 where t2.name = t1.parent - and t1.item_code =%s and ifnull(t1.bom_no, '') = '' and t2.is_active = 1 - and t2.docstatus = 1 and t1.docstatus =1 """, self.doc.name) - if bom_mat and bom_mat[0][0]: - msgprint(_(field_label) + _(" should be 'Yes'. As Item: ") + self.doc.name + - _(" is present in one or many Active BOMs"), raise_exception=1) - - if ((field_label == 'Allow Production Order' - and self.doc.is_sub_contracted_item != 'Yes') - or (field_label == 'Is Sub Contracted Item' - and self.doc.is_manufactured_item != 'Yes')): - bom = webnotes.conn.sql("""select name from `tabBOM` where item = %s - and is_active = 1""", (self.doc.name,)) - if bom and bom[0][0]: - msgprint(_(field_label) + _(" should be 'Yes'. As Item: ") + self.doc.name + - _(" is present in one or many Active BOMs"), raise_exception=1) - - if not cint(self.doc.fields.get("__islocal")): - fl = {'is_manufactured_item' :'Allow Bill of Materials', - 'is_sub_contracted_item':'Is Sub Contracted Item', - 'is_purchase_item' :'Is Purchase Item', - 'is_pro_applicable' :'Allow Production Order'} - for d in fl: - if cstr(self.doc.fields.get(d)) != 'Yes': - _check_for_active_boms(fl[d]) + if self.doc.is_active != "Yes" or self.doc.is_purchase_item != "Yes": + bom_mat = webnotes.conn.sql("""select distinct t1.parent + from `tabBOM Item` t1, `tabBOM` t2 where t2.name = t1.parent + and t1.item_code =%s and ifnull(t1.bom_no, '') = '' and t2.is_active = 1 + and t2.docstatus = 1 and t1.docstatus =1 """, self.doc.name) + + if bom_mat and bom_mat[0][0]: + webnotes.throw(_("Item must be active and purchase item, \ + as it is present in one or many Active BOMs")) + + if self.doc.is_manufactured_item != "Yes": + bom = webnotes.conn.sql("""select name from `tabBOM` where item = %s + and is_active = 1""", (self.doc.name,)) + if bom and bom[0][0]: + webnotes.throw(_("""Allow Bill of Materials should be 'Yes'. Because one or many \ + active BOMs present for this item""")) def fill_customer_code(self): """ Append all the customer codes and insert into "customer_code" field of item table """ From ceb940ec17a4cd894254fbb0df7bf78cc63513ad Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 17 Dec 2013 17:53:05 +0530 Subject: [PATCH 13/13] [reports] [minor] patch to delete old report files --- patches/1312/p01_delete_old_stock_reports.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/patches/1312/p01_delete_old_stock_reports.py b/patches/1312/p01_delete_old_stock_reports.py index eac9b7b844..e8d620ba33 100644 --- a/patches/1312/p01_delete_old_stock_reports.py +++ b/patches/1312/p01_delete_old_stock_reports.py @@ -2,14 +2,16 @@ # License: GNU General Public License v3. See license.txt def execute(): - import webnotes, os + import webnotes, os, shutil + from webnotes.utils import get_base_path webnotes.delete_doc('Page', 'stock-ledger') webnotes.delete_doc('Page', 'stock-ageing') webnotes.delete_doc('Page', 'stock-level') webnotes.delete_doc('Page', 'general-ledger') - os.system("rm -rf app/stock/page/stock_ledger") - os.system("rm -rf app/stock/page/stock_ageing") - os.system("rm -rf app/stock/page/stock_level") - os.system("rm -rf app/accounts/page/general_ledger") \ No newline at end of file + for d in [["stock", "stock_ledger"], ["stock", "stock_ageing"], + ["stock", "stock_level"], ["accounts", "general_ledger"]]: + path = os.path.join(get_base_path(), "app", d[0], "page", d[1]) + if os.path.exists(path): + shutil.rmtree(path) \ No newline at end of file