Merge branch 'master' of github.com:webnotes/erpnext

This commit is contained in:
Nabin Hait
2012-09-19 12:22:24 +05:30
11 changed files with 418 additions and 131 deletions

View File

@@ -29,12 +29,26 @@ wn.pages['financial-analytics'].onload = function(wrapper) {
erpnext.FinancialAnalytics = erpnext.AccountTreeGrid.extend({
filters: [
{fieldtype:"Select", label: "PL or BS", options:["Profit and Loss", "Balance Sheet"],
filter: function(val, item, opts) {
if(val=='Profit and Loss') {
return item.is_pl_account=='Yes' || item._show;
} else {
return item.is_pl_account=='No' || item._show;
}
filter: function(val, item, opts, me) {
if(item._show) return true;
// pl or bs
var out = (val=='Profit and Loss') ? item.is_pl_account=='Yes' : item.is_pl_account!='Yes';
if(!out) return false;
// show only non-zero values
if(!me.show_zero) {
for(var i=0, j=me.columns.length; i<j; i++) {
var col = me.columns[i];
if(col.formatter==me.currency_formatter) {
if(flt(item[col.field]) > 0.001) {
return true;
}
}
}
return false;
}
return true;
}},
{fieldtype:"Select", label: "Company", link:"Company", default_value: "Select Company...",
filter: function(val, item, opts) {
@@ -51,18 +65,15 @@ erpnext.FinancialAnalytics = erpnext.AccountTreeGrid.extend({
{fieldtype:"Button", label: "Reset Filters"}
],
setup_columns: function() {
this.columns = [
var std_columns = [
{id: "check", name: "Plot", field: "check", width: 30,
formatter: function(row, cell, value, columnDef, dataContext) {
return repl("<input type='checkbox' account='%(name)s' \
class='plot-check' %(checked)s>", {
"name": dataContext.name,
"checked": dataContext.checked ? "checked" : ""
})
}},
formatter: this.check_formatter},
{id: "name", name: "Account", field: "name", width: 300,
formatter: this.account_formatter},
{id: "opening", name: "Opening", field: "opening", hidden: true,
formatter: this.currency_formatter}
];
this.columns = [];
var me = this;
var range = this.filter_inputs.range.val();
@@ -70,27 +81,34 @@ erpnext.FinancialAnalytics = erpnext.AccountTreeGrid.extend({
this.to_date = dateutil.user_to_str(this.filter_inputs.to_date.val());
var date_diff = dateutil.get_diff(this.to_date, this.from_date);
me.column_map = {};
me.column_map = {};
var add_column = function(date) {
me.columns.push({
id: date,
name: dateutil.str_to_user(date),
field: date,
formatter: me.currency_formatter,
width: 100
});
}
var build_columns = function(condition) {
// add column for each date range
for(var i=0; i < date_diff; i++) {
var date = dateutil.add_days(me.from_date, i);
if(!condition) condition = function() { return true; }
if(condition(date)) {
me.columns.push({
from_date: date,
id: date,
name: dateutil.str_to_user(date),
field: date,
formatter: me.currency_formatter,
width: 100
});
}
if(condition(date)) add_column(date);
me.last_date = date;
me.column_map[date] = me.columns[me.columns.length-1];
if(me.columns.length) {
me.column_map[date] = me.columns[me.columns.length-1];
}
}
}
// make columns for all date ranges
if(range=='Daily') {
build_columns();
} else if(range=='Weekly') {
@@ -110,13 +128,38 @@ erpnext.FinancialAnalytics = erpnext.AccountTreeGrid.extend({
});
} else if(range=='Yearly') {
build_columns(function(date) {
if(!me.last_date) return true;
if(!me.last_date) return true;
return $.map(wn.report_dump.data['Fiscal Year'], function(v) {
return date==v.year_start_date ? true : null;
}).length;
});
}
// set label as last date of period
$.each(this.columns, function(i, col) {
col.name = me.columns[i+1]
? dateutil.str_to_user(dateutil.add_days(me.columns[i+1].id, -1))
: dateutil.str_to_user(me.to_date);
});
me.columns = std_columns.concat(me.columns);
},
setup_filters: function() {
var me = this;
this._super();
this.filter_inputs.pl_or_bs.change(function() {
me.filter_inputs.refresh.click();
});
this.wrapper.bind('make', function() {
me.wrapper.find('.show-zero').toggle(true).find('input').click(function(){
me.refresh();
});
me.wrapper.on("click", ".plot-check", function() {
var checked = $(this).attr("checked");
me.account_by_name[$(this).attr("data-id")].checked = checked ? true : false;
me.render_plot();
});
});
},
init_filter_values: function() {
this._super();
@@ -127,7 +170,7 @@ erpnext.FinancialAnalytics = erpnext.AccountTreeGrid.extend({
$.each(wn.report_dump.data['GL Entry'], function(i, gl) {
var posting_date = dateutil.str_to_obj(gl.posting_date);
var account = me.accounts_by_name[gl.account];
var account = me.account_by_name[gl.account];
var col = me.column_map[gl.posting_date];
if(col) {
@@ -162,38 +205,27 @@ erpnext.FinancialAnalytics = erpnext.AccountTreeGrid.extend({
})
}
this.update_groups();
this.accounts_initialized = true;
this.show_zero = $('.show-zero input:checked').length;
},
add_balance: function(field, account, gl) {
account[field] = flt(account[field]) +
((account.debit_or_credit == "Debit" ? 1 : -1) * (gl.debit - gl.credit))
((account.debit_or_credit == "Debit" ? 1 : -1) * (flt(gl.debit) - flt(gl.credit)))
},
init_account: function(d) {
// set 0 values for all columns
var me = this;
$.each(this.columns, function(i, col) {
if (col.formatter==me.currency_formatter) {
d[col.from_date] = 0;
d[col.id] = 0;
}
});
},
init_refresh: function() {
var me = this;
$.each(this.accounts || [], function(i, account) {
account.checked && me.preset_checks.push(account.name);
});
},
init_plot: function() {
var me = this;
if(this.preset_checks.length) {
$.each(me.preset_checks, function(i, name) {
me.accounts_by_name[name].checked = true;
});
} else {
$.each(this.accounts, function(i, account) {
if(!account.parent_account) {
account.checked = true;
}
});
// check for default graphs
if(!this.accounts_initialized && !d.parent_account) {
d.checked = true;
}
},
get_plot_data: function() {
var data = [];
@@ -205,22 +237,35 @@ erpnext.FinancialAnalytics = erpnext.AccountTreeGrid.extend({
data.push({
label: account.name,
data: $.map(me.columns, function(col, idx) {
if(col.formatter==me.currency_formatter)
return [[idx, account[col.field]]]
})
if(col.formatter==me.currency_formatter && !col.hidden) {
if (pl_or_bs == "Profit and Loss") {
return [[dateutil.str_to_obj(col.id).getTime(), account[col.field]],
[dateutil.user_to_obj(col.name).getTime(), account[col.field]]];
} else {
return [[dateutil.user_to_obj(col.name).getTime(), account[col.field]]];
}
}
}),
points: {show: true},
lines: {show: true, fill: true},
});
if(pl_or_bs == "Balance Sheet") {
// prepend opening for balance sheet accounts
data[data.length-1].data = [[dateutil.str_to_obj(me.from_date).getTime(),
account.opening]].concat(data[data.length-1].data);
}
}
});
return data;
},
add_grid_events: function() {
this._super();
var me = this;
this.wrapper.find('.plot-check').click(function() {
var checked = $(this).attr("checked");
me.accounts_by_name[$(this).attr("account")].checked = checked ? true : false;
me.render_plot();
});
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() }
}
}
})

View File

@@ -41,11 +41,11 @@ wn.pages['general-ledger'].onload = function(wrapper) {
filters: [
{fieldtype:"Select", label: "Company", link:"Company", default_value: "Select Company...",
filter: function(val, item, opts) {
return item.company == val || val == opts.default_value || item._show;
return item.company == val || val == opts.default_value;
}},
{fieldtype:"Select", label: "Account", link:"Account", default_value: "Select Account...",
filter: function(val, item, opts, me) {
if(val == opts.default_value || item._show) {
if(val == opts.default_value) {
return true;
} else {
// true if GL Entry belongs to selected
@@ -56,14 +56,14 @@ wn.pages['general-ledger'].onload = function(wrapper) {
{fieldtype:"Data", label: "Voucher No",
filter: function(val, item, opts) {
if(!val) return true;
return (item.voucher_no && item.voucher_no.indexOf(val)!=-1) || item._show;
return (item.voucher_no && item.voucher_no.indexOf(val)!=-1);
}},
{fieldtype:"Date", label: "From Date", filter: function(val, item) {
return item._show || dateutil.user_to_obj(val) <= dateutil.str_to_obj(item.posting_date);
return dateutil.str_to_obj(val) <= dateutil.str_to_obj(item.posting_date);
}},
{fieldtype:"Label", label: "To"},
{fieldtype:"Date", label: "To Date", filter: function(val, item) {
return item._show || dateutil.user_to_obj(val) >= dateutil.str_to_obj(item.posting_date);
return dateutil.str_to_obj(val) >= dateutil.str_to_obj(item.posting_date);
}},
{fieldtype:"Button", label: "Refresh", icon:"icon-refresh icon-white", cssClass:"btn-info"},
{fieldtype:"Button", label: "Reset Filters"}
@@ -85,14 +85,15 @@ wn.pages['general-ledger'].onload = function(wrapper) {
// add Opening, Closing, Totals rows
// if filtered by account and / or voucher
var data = wn.report_dump.data["GL Entry"];
this.make_account_by_name();
var out = [];
if(!this.account_by_name)
this.account_by_name = this.make_name_map(wn.report_dump.data["Account"]);
var me = this;
var account = this.filter_inputs.account.val();
var from_date = dateutil.user_to_obj(this.filter_inputs.from_date.val());
var to_date = dateutil.user_to_obj(this.filter_inputs.to_date.val());
var voucher_no = this.filter_inputs.voucher_no.val();
var default_account = this.filter_inputs.account.get(0).opts.default_value;
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("From Date must be before To Date");
@@ -109,8 +110,8 @@ wn.pages['general-ledger'].onload = function(wrapper) {
}
$.each(data, function(i, item) {
if((account!=default_account ? me.is_child_account(account, item.account) : true) &&
(voucher_no ? item.voucher_no==voucher_no : true)) {
if((!me.is_default("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);
@@ -121,6 +122,10 @@ wn.pages['general-ledger'].onload = function(wrapper) {
totals.debit += item.debit;
totals.credit += item.credit;
}
if(me.apply_filters(item)) {
out.push(item);
}
}
})
@@ -131,21 +136,14 @@ wn.pages['general-ledger'].onload = function(wrapper) {
}
if(account != default_account) {
var out = [opening].concat(data).concat([totals, closing]);
if(!me.is_default("account")) {
var out = [opening].concat(out).concat([totals, closing]);
} else {
var out = data.concat([totals]);
var out = out.concat([totals]);
}
this.prepare_data_view(out);
},
make_account_by_name: function() {
this.account_by_name = {};
var me = this;
$.each(wn.report_dump.data['Account'], function(i, v) {
me.account_by_name[v.name] = v;
})
}
});
}

View File

@@ -580,4 +580,8 @@ patch_list = [
'patch_module': 'patches.september_2012',
'patch_file': 'customer_permission_patch',
},
{
'patch_module': 'patches.september_2012',
'patch_file': 'add_stock_ledger_entry_index',
},
]

View File

@@ -0,0 +1,10 @@
import webnotes
def execute():
webnotes.conn.commit()
try:
webnotes.conn.sql("""alter table `tabStock Ledger Entry` add index posting_sort_index(posting_date, posting_time, name)""")webnotes.conn.commit()
except Exception, e:
if e.args[0]!=1061: raise e
webnotes.conn.begin()

View File

@@ -15,6 +15,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
# mappings for table dumps
# "remember to add indexes!"
data_map = {
"Account": {
"columns": ["name", "parent_account", "lft", "rgt", "debit_or_credit", "is_pl_account",
@@ -30,7 +34,11 @@ data_map = {
"columns": ["account", "posting_date", "cost_center", "debit", "credit", "is_opening",
"company", "voucher_type", "voucher_no", "remarks"],
"conditions": ["ifnull(is_cancelled, 'No')='No'"],
"order_by": "posting_date, account"
"order_by": "posting_date, account",
"links": {
"account": ["Account", "name"],
"company": ["Company", "name"]
}
},
"Company": {
"columns": ["name"],
@@ -39,5 +47,29 @@ data_map = {
"Fiscal Year": {
"columns": ["name", "year_start_date",
"adddate(adddate(year_start_date, interval 1 year), interval -1 day) as year_end_date"]
},
"Stock Ledger Entry": {
"columns": ["posting_date", "posting_time", "item_code", "warehouse", "actual_qty as qty",
"voucher_type", "voucher_no"],
"conditions": ["ifnull(is_cancelled, 'No')='No'"],
"order_by": "posting_date, posting_time, name",
"links": {
"item_code": ["Item", "name"],
"warehouse": ["Warehouse", "name"]
},
"force_index": "posting_sort_index"
},
"Item": {
"columns": ["name", "if(item_name=name, '', item_name) as item_name",
"item_group", "stock_uom", "brand"],
"order_by": "name"
},
"Item Group": {
"columns": ["name", "lft", "rgt", "parent_item_group"],
"order_by": "lft"
},
"Warehouse": {
"columns": ["name"],
"order_by": "name"
}
}

View File

@@ -0,0 +1 @@
from __future__ import unicode_literals

View File

@@ -0,0 +1,147 @@
wn.pages['stock-ledger'].onload = function(wrapper) {
wn.ui.make_app_page({
parent: wrapper,
title: 'Stock Ledger',
single_column: true
});
erpnext.stock_ledger = new wn.views.GridReport({
title: "Stock Ledger",
page: wrapper,
parent: $(wrapper).find('.layout-main'),
appframe: wrapper.appframe,
doctypes: ["Item", "Item Group", "Warehouse", "Stock Ledger Entry"],
setup_columns: function() {
this.columns = [
{id: "posting_datetime", name: "Posting Date", field: "posting_datetime", width: 120,
formatter: this.date_formatter},
{id: "item_code", name: "Item Code", field: "item_code", width: 160,
link_formatter: {
filter_input: "item_code",
open_btn: true,
doctype: '"Item"'
}},
{id: "warehouse", name: "Warehouse", field: "warehouse", width: 100,
link_formatter: {filter_input: "warehouse"}},
{id: "qty", name: "Qty", field: "qty", width: 100,
formatter: this.currency_formatter},
{id: "balance", name: "Balance", field: "balance", width: 100,
formatter: this.currency_formatter},
{id: "voucher_type", name: "Voucher Type", field: "voucher_type", width: 120},
{id: "voucher_no", name: "Voucher No", field: "voucher_no", width: 160,
link_formatter: {
filter_input: "voucher_no",
open_btn: true,
doctype: "dataContext.voucher_type"
}},
{id: "description", name: "Description", field: "description", width: 200,
formatter: this.text_formatter},
];
},
filters: [
{fieldtype:"Select", label: "Warehouse", link:"Warehouse", default_value: "Select Warehouse...",
filter: function(val, item, opts) {
return item.warehouse == val || val == opts.default_value;
}},
{fieldtype:"Select", label: "Item Code", link:"Item", default_value: "Select Item...",
filter: function(val, item, opts) {
return item.item_code == val || val == opts.default_value;
}},
{fieldtype:"Data", label: "Voucher No",
filter: function(val, item, opts) {
if(!val) return true;
return (item.voucher_no && item.voucher_no.indexOf(val)!=-1);
}},
{fieldtype:"Date", label: "From Date", filter: function(val, item) {
return dateutil.str_to_obj(val) <= dateutil.str_to_obj(item.posting_date);
}},
{fieldtype:"Label", label: "To"},
{fieldtype:"Date", label: "To Date", filter: function(val, item) {
return dateutil.str_to_obj(val) >= dateutil.str_to_obj(item.posting_date);
}},
{fieldtype:"Button", label: "Refresh", icon:"icon-refresh icon-white", cssClass:"btn-info"},
{fieldtype:"Button", label: "Reset Filters"}
],
init_filter_values: function() {
this.filter_inputs.warehouse.get(0).selectedIndex = 0;
this.filter_inputs.item_code.get(0).selectedIndex = 0;
this.filter_inputs.from_date.val(dateutil.str_to_user(sys_defaults.year_start_date));
this.filter_inputs.to_date.val(dateutil.str_to_user(sys_defaults.year_end_date));
this.filter_inputs.voucher_no.val("");
},
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 = [];
if(this.to_date < this.from_date) {
msgprint("From Date must be before To Date");
return;
}
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"
}
var total_in = {
item_code: "Total In", qty: 0.0, balance: 0.0,
id:"_total_in", _show: true, _style: "font-weight: bold"
}
var total_out = {
item_code: "Total Out", qty: 0.0, balance: 0.0,
id:"_total_out", _show: true, _style: "font-weight: bold"
}
// clear balance
$.each(wn.report_dump.data["Item"], function(i, item) { item.balance = 0.0; });
//
for(var i=0, j=data.length; i<j; i++) {
var sl = data[i];
sl.description = me.item_by_name[sl.item_code].description;
sl.posting_datetime = sl.posting_date + " " + sl.posting_time;
var posting_datetime = dateutil.str_to_obj(sl.posting_datetime);
// opening, transactions, closing, total in, total out
var before_end = posting_datetime <= dateutil.str_to_obj(me.to_date + " 23:59:59");
if((!me.is_default("item_code") ? me.apply_filter(sl, "item_code") : true)
&& me.apply_filter(sl, "warehouse") && me.apply_filter(sl, "voucher_no")) {
if(posting_datetime < dateutil.str_to_obj(me.from_date)) {
opening.balance += sl.qty;
} else if(before_end) {
if(sl.qty > 0) total_in.qty += sl.qty;
else total_out.qty += (-1 * sl.qty);
}
}
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;
}
}
if(me.item_code != me.item_code_default && !me.voucher_no) {
var closing = {
item_code: "On " + dateutil.str_to_user(this.to_date),
balane: me.item_by_name[sl.item_code].balance, qty: 0,
id:"_closing", _show: true, _style: "font-weight: bold"
};
var out = [opening].concat(out).concat([total_in, total_out, closing]);
}
this.data = out;
this.prepare_data_view(out);
},
});
}

View File

@@ -0,0 +1,28 @@
# Page, stock-ledger
[
# These values are common in all dictionaries
{
u'creation': '2012-09-18 14:55:15',
u'docstatus': 0,
u'modified': '2012-09-18 14:55:15',
u'modified_by': u'Administrator',
u'owner': u'Administrator'
},
# These values are common for all Page
{
u'doctype': u'Page',
'module': u'Stock',
u'name': u'__common__',
'page_name': u'stock-ledger',
'standard': u'Yes',
'title': u'Stock Ledger'
},
# Page, stock-ledger
{
u'doctype': u'Page',
u'name': u'stock-ledger'
}
]