From e64c357216142559b8784055f152716aa3b6510d Mon Sep 17 00:00:00 2001 From: deepeshgarg007 Date: Tue, 14 May 2019 08:50:45 +0530 Subject: [PATCH] fix: Commified function to get dimensions --- .../accounting_dimension.py | 21 +++++++++++++++-- .../budget_variance_report.js | 8 +++++++ .../budget_variance_report.py | 23 ++++++++++++------- .../report/general_ledger/general_ledger.js | 9 +------- erpnext/public/js/financial_statements.js | 8 +------ erpnext/public/js/utils.js | 8 +++++++ 6 files changed, 52 insertions(+), 25 deletions(-) diff --git a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py index 93a25e7c0a..e56492c18d 100644 --- a/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py +++ b/erpnext/accounts/doctype/accounting_dimension/accounting_dimension.py @@ -5,7 +5,6 @@ from __future__ import unicode_literals import frappe from frappe.model.document import Document -from frappe.custom.doctype.custom_field.custom_field import create_custom_fields from frappe.custom.doctype.custom_field.custom_field import create_custom_field from frappe import scrub from frappe.utils import cstr @@ -41,7 +40,25 @@ class AccountingDimension(Document): } for doctype in doclist: - create_custom_field(doctype, df) + + if doctype == "Budget": + df.update({ + "depends_on": "eval:doc.budget_against == '{0}'".format(self.document_type) + }) + + create_custom_field(doctype, df) + + property_setter = frappe.db.exists("Property Setter", "Budget-budget_against-options") + + if property_setter: + else: + frappe.get_doc({ + "doctype": "Property Setter", + "doc_type": "Budget", + "fieldname": "budget_against" + }) + else: + create_custom_field(doctype, df) def delete_accounting_dimension(self): doclist = ["GL Entry", "Sales Invoice", "Purchase Invoice", "Payment Entry", "BOM", "Sales Order", "Purchase Order", diff --git a/erpnext/accounts/report/budget_variance_report/budget_variance_report.js b/erpnext/accounts/report/budget_variance_report/budget_variance_report.js index cd9f9d956b..b2072f06f1 100644 --- a/erpnext/accounts/report/budget_variance_report/budget_variance_report.js +++ b/erpnext/accounts/report/budget_variance_report/budget_variance_report.js @@ -62,3 +62,11 @@ frappe.query_reports["Budget Variance Report"] = { }, ] } + +let dimension_filters = erpnext.get_dimension_filters(); + +dimension_filters.then((dimensions) => { + dimensions.forEach((dimension) => { + frappe.query_reports["Budget Variance Report"].filters[4].options.push(dimension["document_type"]); + }); +}); diff --git a/erpnext/accounts/report/budget_variance_report/budget_variance_report.py b/erpnext/accounts/report/budget_variance_report/budget_variance_report.py index fe8de367f2..fb4f5d0da2 100644 --- a/erpnext/accounts/report/budget_variance_report/budget_variance_report.py +++ b/erpnext/accounts/report/budget_variance_report/budget_variance_report.py @@ -19,9 +19,12 @@ def execute(filters=None): else: cost_centers = get_cost_centers(filters) + print(cost_centers) + period_month_ranges = get_period_month_ranges(filters["period"], filters["from_fiscal_year"]) cam_map = get_cost_center_account_month_map(filters) + print(cam_map) data = [] for cost_center in cost_centers: cost_center_items = cam_map.get(cost_center) @@ -45,8 +48,8 @@ def execute(filters=None): if(filters.get("show_cumulative")): last_total = period_data[0] - period_data[1] - - period_data[2] = period_data[0] - period_data[1] + + period_data[2] = period_data[0] - period_data[1] row += period_data totals[2] = totals[0] - totals[1] if filters["period"] != "Yearly" : @@ -56,7 +59,7 @@ def execute(filters=None): return columns, data def validate_filters(filters): - if filters.get("budget_against")=="Project" and filters.get("cost_center"): + if filters.get("budget_against") != "Cost Center" and filters.get("cost_center"): frappe.throw(_("Filter based on Cost Center is only applicable if Budget Against is selected as Cost Center")) def get_columns(filters): @@ -92,8 +95,11 @@ def get_cost_centers(filters): if filters.get("budget_against") == "Cost Center": cond = "order by lft" - return frappe.db.sql_list("""select name from `tab{tab}` where company=%s - {cond}""".format(tab=filters.get("budget_against"), cond=cond), filters.get("company")) + if filters.get("budget_against") in ["Cost Center", "Project"]: + return frappe.db.sql_list("""select name from `tab{tab}` where company=%s + {cond}""".format(tab=filters.get("budget_against"), cond=cond), filters.get("company")) + else: + return frappe.db.sql_list("""select name from `tab{tab}`""".format(tab=filters.get("budget_against"))) #Get cost center & target details def get_cost_center_target_details(filters): @@ -109,7 +115,7 @@ def get_cost_center_target_details(filters): """.format(budget_against=filters.get("budget_against").replace(" ", "_").lower(), cond=cond), (filters.from_fiscal_year,filters.to_fiscal_year,filters.budget_against, filters.company), as_dict=True) - + #Get target distribution details of accounts of cost center def get_target_distribution_details(filters): @@ -118,7 +124,7 @@ def get_target_distribution_details(filters): from `tabMonthly Distribution Percentage` mdp, `tabMonthly Distribution` md where mdp.parent=md.name and md.fiscal_year between %s and %s order by md.fiscal_year""",(filters.from_fiscal_year, filters.to_fiscal_year), as_dict=1): target_details.setdefault(d.name, {}).setdefault(d.month, flt(d.percentage_allocation)) - + return target_details #Get actual details from gl entry @@ -129,7 +135,7 @@ def get_actual_details(name, filters): if filters.get("budget_against") == "Cost Center": cc_lft, cc_rgt = frappe.db.get_value("Cost Center", name, ["lft", "rgt"]) cond = "lft>='{lft}' and rgt<='{rgt}'".format(lft = cc_lft, rgt=cc_rgt) - + ac_details = frappe.db.sql("""select gl.account, gl.debit, gl.credit,gl.fiscal_year, MONTHNAME(gl.posting_date) as month_name, b.{budget_against} as budget_against from `tabGL Entry` gl, `tabBudget Account` ba, `tabBudget` b @@ -153,6 +159,7 @@ def get_actual_details(name, filters): def get_cost_center_account_month_map(filters): import datetime cost_center_target_details = get_cost_center_target_details(filters) + print(cost_center_target_details) tdd = get_target_distribution_details(filters) cam_map = {} diff --git a/erpnext/accounts/report/general_ledger/general_ledger.js b/erpnext/accounts/report/general_ledger/general_ledger.js index 7db8786c35..481107e498 100644 --- a/erpnext/accounts/report/general_ledger/general_ledger.js +++ b/erpnext/accounts/report/general_ledger/general_ledger.js @@ -215,7 +215,7 @@ frappe.query_reports["General Ledger"] = { ] } -let dimension_filters = get_dimension_filters(); +let dimension_filters = erpnext.get_dimension_filters(); dimension_filters.then((dimensions) => { dimensions.forEach((dimension) => { @@ -228,10 +228,3 @@ dimension_filters.then((dimensions) => { }); }); -async function get_dimension_filters() { - let dimensions = await frappe.db.get_list('Accounting Dimension', { - fields: ['label', 'fieldname', 'document_type'], - }); - - return dimensions; -} diff --git a/erpnext/public/js/financial_statements.js b/erpnext/public/js/financial_statements.js index 77e67c49ed..2e4b8f28db 100644 --- a/erpnext/public/js/financial_statements.js +++ b/erpnext/public/js/financial_statements.js @@ -150,7 +150,7 @@ function get_filters(){ } ] - let dimension_filters = get_dimension_filters() + let dimension_filters = erpnext.get_dimension_filters() dimension_filters.then((dimensions) => { dimensions.forEach((dimension) => { @@ -166,10 +166,4 @@ function get_filters(){ return filters; } -async function get_dimension_filters() { - let dimensions = await frappe.db.get_list('Accounting Dimension', { - fields: ['label', 'fieldname', 'document_type'], - }); - return dimensions; -} diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js index 6860d6a238..540b5ea0ec 100755 --- a/erpnext/public/js/utils.js +++ b/erpnext/public/js/utils.js @@ -62,6 +62,14 @@ $.extend(erpnext, { $btn.on("click", function() { me.show_serial_batch_selector(grid_row.frm, grid_row.doc); }); + }, + + get_dimension_filters: async function() { + let dimensions = await frappe.db.get_list('Accounting Dimension', { + fields: ['label', 'fieldname', 'document_type'], + }); + + return dimensions; } });