From 8df49ca772c046f9d4e091bba36096bb1ec43512 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Fri, 21 Jun 2013 12:05:35 +0530 Subject: [PATCH 1/3] [buying] [fix] on change of currency, set conversion rate = 1 if currency=company currency --- buying/doctype/purchase_common/purchase_common.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/buying/doctype/purchase_common/purchase_common.js b/buying/doctype/purchase_common/purchase_common.js index dacee80e55..9e291f5f17 100644 --- a/buying/doctype/purchase_common/purchase_common.js +++ b/buying/doctype/purchase_common/purchase_common.js @@ -128,23 +128,27 @@ erpnext.buying.BuyingController = wn.ui.form.Controller.extend({ }, currency: function() { - this.set_dynamic_labels(); + if(this.frm.doc.currency === this.get_company_currency()) + this.frm.set_value("conversion_rate", 1.0); + + this.price_list_currency(); }, company: function() { - this.set_dynamic_labels(); + if(this.frm.fields_dict.currency) + this.set_dynamic_labels(); }, price_list_currency: function() { this.frm.toggle_reqd("plc_conversion_rate", !!(this.frm.doc.price_list_name && this.frm.doc.price_list_currency)); - this.set_dynamic_labels(); - if(this.frm.doc.price_list_currency === this.get_company_currency()) this.frm.set_value("plc_conversion_rate", 1.0); else if(this.frm.doc.price_list_currency === this.frm.doc.currency) this.frm.set_value("plc_conversion_rate", this.frm.doc.conversion_rate || 1.0); + + this.set_dynamic_labels(); }, set_dynamic_labels: function(doc, dt, dn) { From f78d16cca1d5a8e2606e5601f5f642c21ea4c28b Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 21 Jun 2013 15:13:49 +0530 Subject: [PATCH 2/3] [general ledger] group by voucher option --- .../page/general_ledger/general_ledger.js | 63 ++++++++++++++++++- patches/september_2012/repost_stock.py | 2 +- startup/report_data_map.py | 5 +- 3 files changed, 66 insertions(+), 4 deletions(-) diff --git a/accounts/page/general_ledger/general_ledger.js b/accounts/page/general_ledger/general_ledger.js index a462b70e93..dfba26cf6d 100644 --- a/accounts/page/general_ledger/general_ledger.js +++ b/accounts/page/general_ledger/general_ledger.js @@ -63,11 +63,21 @@ erpnext.GeneralLedger = wn.views.GridReport.extend({ open_btn: true, doctype: "dataContext.voucher_type" }}, + {id: "against_voucher_type", name: "Against Voucher Type", + field: "against_voucher_type", width: 120}, + {id: "against_voucher", name: "Against Voucher", + field: "against_voucher", width: 160, + link_formatter: { + filter_input: "against_voucher", + open_btn: true, + doctype: "dataContext.against_voucher_type" + }}, {id: "remarks", name: "Remarks", field: "remarks", width: 200, formatter: this.text_formatter}, ]; }, + filters: [ {fieldtype:"Select", label: "Company", link:"Company", default_value: "Select Company...", filter: function(val, item, opts) { @@ -96,6 +106,7 @@ erpnext.GeneralLedger = wn.views.GridReport.extend({ return dateutil.str_to_obj(val) >= dateutil.str_to_obj(item.posting_date); }}, {fieldtype: "Check", label: "Group by Ledger"}, + {fieldtype: "Check", label: "Group by Voucher"}, {fieldtype:"Button", label: "Refresh", icon:"icon-refresh icon-white", cssClass:"btn-info"}, {fieldtype:"Button", label: "Reset Filters"} ], @@ -116,9 +127,14 @@ erpnext.GeneralLedger = wn.views.GridReport.extend({ me.filter_inputs.group_by_ledger .parent().toggle(!!(me.account_by_name[$(this).val()] && me.account_by_name[$(this).val()].group_or_ledger==="Group")); + + me.filter_inputs.group_by_voucher + .parent().toggle(!!(me.account_by_name[$(this).val()] + && me.account_by_name[$(this).val()].group_or_ledger==="Ledger")); }); this.trigger_refresh_on_change(["group_by_ledger"]); + this.trigger_refresh_on_change(["group_by_voucher"]); }, setup_account_filter: function(company_filter) { var me = this; @@ -139,12 +155,14 @@ erpnext.GeneralLedger = wn.views.GridReport.extend({ init_filter_values: function() { this._super(); this.filter_inputs.group_by_ledger.parent().toggle(false); + this.filter_inputs.group_by_voucher.parent().toggle(false); this.filter_inputs.company.change(); this.filter_inputs.account.change(); }, apply_filters_from_route: function() { this._super(); this.filter_inputs.group_by_ledger.parent().toggle(false); + this.filter_inputs.group_by_voucher.parent().toggle(false); this.filter_inputs.company.change(); this.filter_inputs.account.change(); }, @@ -196,13 +214,21 @@ erpnext.GeneralLedger = wn.views.GridReport.extend({ 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] = { + entries: [], + totals: me.make_summary_row("Totals", item.voucher_no) + } + } + if(date < from_date || item.is_opening=="Yes") { opening.debit += item.debit; opening.credit += item.credit; @@ -215,6 +241,11 @@ erpnext.GeneralLedger = wn.views.GridReport.extend({ 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 + ":" @@ -224,6 +255,9 @@ erpnext.GeneralLedger = wn.views.GridReport.extend({ if(me.apply_filters(item) && item.is_opening=="No") { out.push(item); grouped_ledgers[item.account].entries.push(item); + + grouped_ledgers[item.account].entries_group_by_voucher[item.voucher_no] + .entries.push(item); } } }); @@ -241,6 +275,11 @@ erpnext.GeneralLedger = wn.views.GridReport.extend({ 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) @@ -283,6 +322,28 @@ erpnext.GeneralLedger = wn.views.GridReport.extend({ return [{id: "_blank_first", _no_format: true, 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).sort(), + function(j, voucher) { + if(grouped_ledgers[account].entries_group_by_voucher[voucher] + .entries.length) { + out = out.concat(grouped_ledgers[account] + .entries_group_by_voucher[voucher].entries) + .concat([ + grouped_ledgers[account].entries_group_by_voucher[voucher] + .totals, {id: "_blank" + j, _no_format: true, + debit: "", credit: ""}]); + } + }); + } + }); + return [{id: "_blank_first", _no_format: true, debit: "", credit: ""}].concat(out); + }, + get_balance: function(debit_or_credit, balance) { if(debit_or_credit == "Debit") { balance.debit -= balance.credit; balance.credit = 0; diff --git a/patches/september_2012/repost_stock.py b/patches/september_2012/repost_stock.py index 972070137a..deb218637e 100644 --- a/patches/september_2012/repost_stock.py +++ b/patches/september_2012/repost_stock.py @@ -22,7 +22,7 @@ def execute(): i=0 for d in res: try: - update_entries_after({ "item_code": d[0], "warehouse": d[1] }) + update_entries_after({ "item_code": d[0], "warehouse": d[1]}) except: pass i += 1 diff --git a/startup/report_data_map.py b/startup/report_data_map.py index 501db4f6ce..ae3a53fb40 100644 --- a/startup/report_data_map.py +++ b/startup/report_data_map.py @@ -47,8 +47,9 @@ data_map = { "order_by": "lft" }, "GL Entry": { - "columns": ["name", "account", "posting_date", "cost_center", "debit", "credit", "is_opening", - "company", "voucher_type", "voucher_no", "remarks"], + "columns": ["name", "account", "posting_date", "cost_center", "debit", "credit", + "is_opening", "company", "voucher_type", "voucher_no", "remarks", + "against_voucher_type", "against_voucher"], "conditions": ["ifnull(is_cancelled, 'No')='No'"], "order_by": "posting_date, account", "links": { From 4555d3bcf4d0a96b5e3f3e21d090e20c7ffd8ecc Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 21 Jun 2013 16:27:34 +0530 Subject: [PATCH 3/3] [report][trends] --- controllers/trends.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/controllers/trends.py b/controllers/trends.py index acbc744ae6..528f5e4d0e 100644 --- a/controllers/trends.py +++ b/controllers/trends.py @@ -89,9 +89,10 @@ def get_data(filters, conditions): row = webnotes.conn.sql("""select DISTINCT(%s) from `tab%s` t1, `tab%s Item` t2 %s where t2.parent = t1.name and t1.company = %s and t1.fiscal_year = %s and t1.docstatus = 1 and %s = %s - """%(sel_col, conditions["trans"], conditions["trans"], conditions["addl_tables"], "%s", "%s", - conditions["group_by"], "%s"), (filters.get("company"), filters.get("fiscal_year"), - data1[d][0]), as_list=1) + """ % + (sel_col, conditions["trans"], conditions["trans"], conditions["addl_tables"], + "%s", "%s", conditions["group_by"], "%s"), + (filters.get("company"), filters.get("fiscal_year"), data1[d][0]), as_list=1) for i in range(len(row)): des = ['' for q in range(len(conditions["columns"]))] @@ -100,9 +101,12 @@ def get_data(filters, conditions): row1 = webnotes.conn.sql(""" select %s , %s from `tab%s` t1, `tab%s Item` t2 %s where t2.parent = t1.name and t1.company = %s and t1.fiscal_year = %s and t1.docstatus = 1 and %s = %s and %s = %s - """ % (sel_col, conditions["period_wise_select"], conditions["trans"], conditions["trans"], - conditions["addl_tables"], "%s", "%s", sel_col, "%s", conditions["group_by"], "%s"), - (filters.get("company"), filters.get("fiscal_year"), row[i][0], data1[d][0]), as_list=1) + """ % + (sel_col, conditions["period_wise_select"], conditions["trans"], + conditions["trans"], conditions["addl_tables"], "%s", "%s", sel_col, + "%s", conditions["group_by"], "%s"), + (filters.get("company"), filters.get("fiscal_year"), row[i][0], + data1[d][0]), as_list=1) des[ind] = row[i] for j in range(1,len(conditions["columns"])-inc): @@ -110,14 +114,14 @@ def get_data(filters, conditions): data.append(des) else: - webnotes.errprint(["hii", conditions["addl_tables"]]) data = webnotes.conn.sql(""" select %s from `tab%s` t1, `tab%s Item` t2 %s where t2.parent = t1.name and t1.company = %s and t1.fiscal_year = %s and t1.docstatus = 1 %s group by %s - """%(query_details, conditions["trans"], conditions["trans"], conditions["addl_tables"], "%s", - "%s", cond,conditions["group_by"]), (filters.get("company"), - filters.get("fiscal_year")), as_list=1) + """ % + (query_details, conditions["trans"], conditions["trans"], conditions["addl_tables"], + "%s", "%s", cond,conditions["group_by"]), + (filters.get("company"), filters.get("fiscal_year")), as_list=1) return data @@ -139,7 +143,8 @@ def period_wise_colums_query(filters, trans): get_period_wise_columns(dt, filters.get("period"), pwc) query_details = get_period_wise_query(dt, trans_date, query_details) else: - pwc = [filters.get("fiscal_year")+" (Qty):Float:120", filters.get("fiscal_year")+" (Amt):Currency:120"] + pwc = [filters.get("fiscal_year") + " (Qty):Float:120", + filters.get("fiscal_year") + " (Amt):Currency:120"] query_details = " SUM(t2.qty), SUM(t1.grand_total)," query_details += 'SUM(t2.qty), SUM(t1.grand_total)' @@ -154,10 +159,9 @@ def get_period_wise_columns(bet_dates, period, pwc): get_mon(bet_dates[0]) + "-" + get_mon(bet_dates[1]) + " (Amt):Currency:120"] def get_period_wise_query(bet_dates, trans_date, query_details): - query_details += """SUM(IF(t1.%(trans_date)s BETWEEN '%(sd)s' AND '%(ed)s', t2.qty, NULL)), SUM(IF(t1.%(trans_date)s BETWEEN '%(sd)s' AND '%(ed)s', t1.grand_total, NULL)), - """%{"trans_date": trans_date, "sd": bet_dates[0],"ed": bet_dates[1]} + """ % {"trans_date": trans_date, "sd": bet_dates[0],"ed": bet_dates[1]} return query_details def get_period_date_ranges(period, fiscal_year):