mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-01 03:09:09 +00:00
stock balance report and inclusion of filter on brand in all stock reports
This commit is contained in:
@@ -14,41 +14,55 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
wn.pages['stock-analytics'].onload = function(wrapper) {
|
||||
wn.ui.make_app_page({
|
||||
parent: wrapper,
|
||||
title: 'Stock Analytics',
|
||||
single_column: true
|
||||
});
|
||||
|
||||
new erpnext.StockAnalytics(wrapper);
|
||||
|
||||
wrapper.appframe.add_home_breadcrumb()
|
||||
wrapper.appframe.add_module_breadcrumb("Stock")
|
||||
wrapper.appframe.add_breadcrumb("icon-bar-chart")
|
||||
}
|
||||
|
||||
wn.require("app/js/stock_grid_report.js");
|
||||
|
||||
// done so that it doesn't throw error when inherited in stock-balance report
|
||||
if(wn.pages["stock-analytics"]) {
|
||||
wn.pages['stock-analytics'].onload = function(wrapper) {
|
||||
wn.ui.make_app_page({
|
||||
parent: wrapper,
|
||||
title: 'Stock Analytics',
|
||||
single_column: true
|
||||
});
|
||||
|
||||
new erpnext.StockAnalytics(wrapper);
|
||||
|
||||
wrapper.appframe.add_home_breadcrumb()
|
||||
wrapper.appframe.add_module_breadcrumb("Stock")
|
||||
wrapper.appframe.add_breadcrumb("icon-bar-chart")
|
||||
}
|
||||
}
|
||||
|
||||
erpnext.StockAnalytics = erpnext.StockGridReport.extend({
|
||||
init: function(wrapper) {
|
||||
this._super({
|
||||
init: function(wrapper, opts) {
|
||||
var args = {
|
||||
title: "Stock Analytics",
|
||||
page: wrapper,
|
||||
parent: $(wrapper).find('.layout-main'),
|
||||
appframe: wrapper.appframe,
|
||||
doctypes: ["Item", "Item Group", "Warehouse", "Stock Ledger Entry", "Fiscal Year"],
|
||||
doctypes: ["Item", "Item Group", "Warehouse", "Stock Ledger Entry", "Brand",
|
||||
"Fiscal Year"],
|
||||
tree_grid: {
|
||||
show: true,
|
||||
parent_field: "parent_item_group",
|
||||
formatter: function(item) {
|
||||
return repl('<a href="#stock-ledger/item=%(enc_value)s">%(value)s</a>', {
|
||||
value: item.name,
|
||||
enc_value: encodeURIComponent(item.name)
|
||||
});
|
||||
if(!item.is_group) {
|
||||
return repl('<a href="#stock-ledger/item_code=%(enc_value)s">%(value)s</a>',
|
||||
{
|
||||
value: item.name,
|
||||
enc_value: encodeURIComponent(item.name)
|
||||
});
|
||||
} else {
|
||||
return item.name;
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
})
|
||||
},
|
||||
}
|
||||
|
||||
if(opts) $.extend(args, opts);
|
||||
|
||||
this._super(args);
|
||||
},
|
||||
setup_columns: function() {
|
||||
var std_columns = [
|
||||
@@ -56,11 +70,12 @@ erpnext.StockAnalytics = erpnext.StockGridReport.extend({
|
||||
formatter: this.check_formatter},
|
||||
{id: "name", name: "Item", field: "name", width: 300,
|
||||
formatter: this.tree_formatter},
|
||||
{id: "brand", name: "Brand", field: "brand", width: 200},
|
||||
{id: "opening", name: "Opening", field: "opening", hidden: true,
|
||||
formatter: this.currency_formatter}
|
||||
];
|
||||
|
||||
this.make_date_range_columns();
|
||||
this.make_date_range_columns();
|
||||
this.columns = std_columns.concat(this.columns);
|
||||
},
|
||||
filters: [
|
||||
@@ -69,10 +84,12 @@ erpnext.StockAnalytics = erpnext.StockGridReport.extend({
|
||||
filter: function(val, item, opts, me) {
|
||||
return me.apply_zero_filter(val, item, opts, me);
|
||||
}},
|
||||
{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;
|
||||
}},
|
||||
{fieldtype:"Select", label: "Warehouse", link:"Warehouse",
|
||||
default_value: "Select Warehouse..."},
|
||||
{fieldtype:"Select", label: "Fiscal Year", link:"Fiscal Year",
|
||||
default_value: "Select Fiscal Year..."},
|
||||
{fieldtype:"Date", label: "From Date"},
|
||||
{fieldtype:"Label", label: "To"},
|
||||
{fieldtype:"Date", label: "To Date"},
|
||||
@@ -84,28 +101,15 @@ erpnext.StockAnalytics = erpnext.StockGridReport.extend({
|
||||
setup_filters: function() {
|
||||
var me = this;
|
||||
this._super();
|
||||
|
||||
this.filter_inputs.fiscal_year.change(function() {
|
||||
var fy = $(this).val();
|
||||
$.each(wn.report_dump.data["Fiscal Year"], function(i, v) {
|
||||
if (v.name==fy) {
|
||||
me.filter_inputs.from_date.val(dateutil.str_to_user(v.year_start_date));
|
||||
me.filter_inputs.to_date.val(dateutil.str_to_user(v.year_end_date));
|
||||
}
|
||||
});
|
||||
me.set_route();
|
||||
});
|
||||
|
||||
this.filter_inputs.value_or_qty.change(function() {
|
||||
me.filter_inputs.refresh.click();
|
||||
});
|
||||
this.trigger_refresh_on_change(["value_or_qty", "brand", "warehouse", "range"]);
|
||||
|
||||
this.show_zero_check()
|
||||
this.show_zero_check();
|
||||
this.setup_plot_check();
|
||||
},
|
||||
init_filter_values: function() {
|
||||
this._super();
|
||||
this.filter_inputs.range.val('Monthly');
|
||||
this.filter_inputs.range && this.filter_inputs.range.val('Monthly');
|
||||
},
|
||||
prepare_data: function() {
|
||||
var me = this;
|
||||
@@ -153,7 +157,7 @@ erpnext.StockAnalytics = erpnext.StockGridReport.extend({
|
||||
sl.posting_datetime = sl.posting_date + " " + sl.posting_time;
|
||||
var posting_datetime = dateutil.str_to_obj(sl.posting_datetime);
|
||||
|
||||
if(me.is_default("warehouse") ? true : me.warehouse == sl.warehouse) {
|
||||
if(me.is_default("warehouse") ? true : me.warehouse == sl.warehouse) {
|
||||
var item = me.item_by_name[sl.item_code];
|
||||
|
||||
if(me.value_or_qty!="Quantity") {
|
||||
@@ -179,7 +183,7 @@ erpnext.StockAnalytics = erpnext.StockGridReport.extend({
|
||||
|
||||
$.each(this.data, function(i, item) {
|
||||
// update groups
|
||||
if(!item.is_group) {
|
||||
if(!item.is_group && me.apply_filter(item, "brand")) {
|
||||
var balance = item.opening;
|
||||
$.each(me.columns, function(i, col) {
|
||||
if(col.formatter==me.currency_formatter && !col.hidden) {
|
||||
@@ -199,7 +203,7 @@ erpnext.StockAnalytics = erpnext.StockGridReport.extend({
|
||||
}
|
||||
});
|
||||
parent = me.parent_map[parent];
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user