From ca4d9b54cd19e921baa5ddbbc7fdcb0f4c4efe98 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Mon, 22 Aug 2016 15:53:01 +0530 Subject: [PATCH] fixed accumulated values for cash flow --- .../accounts/report/cash_flow/cash_flow.py | 21 ++++++++++++------- .../accounts/report/financial_statements.py | 6 +++--- .../profit_and_loss_statement.py | 2 +- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/erpnext/accounts/report/cash_flow/cash_flow.py b/erpnext/accounts/report/cash_flow/cash_flow.py index 73b5c4bf1c6..24c5cd2cd1b 100644 --- a/erpnext/accounts/report/cash_flow/cash_flow.py +++ b/erpnext/accounts/report/cash_flow/cash_flow.py @@ -6,6 +6,7 @@ import frappe from frappe import _ from erpnext.accounts.report.financial_statements import (get_period_list, get_columns, get_data) from erpnext.accounts.report.profit_and_loss_statement.profit_and_loss_statement import get_net_profit_loss +from erpnext.accounts.utils import get_fiscal_year def execute(filters=None): @@ -49,9 +50,9 @@ def execute(filters=None): # compute net profit / loss income = get_data(filters.company, "Income", "Credit", period_list, - accumulated_values=filters.accumulated_values, ignore_closing_entries=True) + accumulated_values=filters.accumulated_values, ignore_closing_entries=True, ignore_accumulated_values_for_fy= True) expense = get_data(filters.company, "Expense", "Debit", period_list, - accumulated_values=filters.accumulated_values, ignore_closing_entries=True) + accumulated_values=filters.accumulated_values, ignore_closing_entries=True, ignore_accumulated_values_for_fy= True) net_profit_loss = get_net_profit_loss(income, expense, period_list, filters.company) @@ -98,33 +99,39 @@ def execute(filters=None): return columns, data - def get_account_type_based_data(company, account_type, period_list, accumulated_values): data = {} total = 0 for period in period_list: + start_date = get_start_date(period, accumulated_values) gl_sum = frappe.db.sql_list(""" select sum(credit) - sum(debit) from `tabGL Entry` where company=%s and posting_date >= %s and posting_date <= %s and voucher_type != 'Period Closing Voucher' and account in ( SELECT name FROM tabAccount WHERE account_type = %s) - """, (company, period["year_start_date"] if accumulated_values else period['from_date'], + """, (company, start_date if accumulated_values else period['from_date'], period['to_date'], account_type)) - + if gl_sum and gl_sum[0]: amount = gl_sum[0] if account_type == "Depreciation": amount *= -1 else: amount = 0 - + total += amount data.setdefault(period["key"], amount) - + data["total"] = total return data +def get_start_date(period, accumulated_values): + start_date = period["year_start_date"] + if accumulated_values: + start_date = get_fiscal_year(period.to_date)[1] + + return start_date def add_total_row_account(out, data, label, period_list, currency): total_row = { diff --git a/erpnext/accounts/report/financial_statements.py b/erpnext/accounts/report/financial_statements.py index fb82213c8e8..f6968a1c3b5 100644 --- a/erpnext/accounts/report/financial_statements.py +++ b/erpnext/accounts/report/financial_statements.py @@ -16,13 +16,13 @@ def get_period_list(from_fiscal_year, to_fiscal_year, periodicity): to_fy_start_end_date = frappe.db.get_value("Fiscal Year", to_fiscal_year, ["year_start_date", "year_end_date"]) if not from_fy_start_end_date: - frappe.throw(_("Fiscal Year {0} not found.").format(from_fiscal_year)) + frappe.throw(_("Start Year {0} not found.").format(from_fiscal_year)) if not to_fy_start_end_date: - frappe.throw(_("Fiscal Year {0} not found.").format(to_fiscal_year)) + frappe.throw(_("End Year {0} not found.").format(to_fiscal_year)) # start with first day, so as to avoid year to_dates like 2-April if ever they occur] - year_start_date = get_first_day(getdate(from_fy_start_end_date[0])) + year_start_date = getdate(from_fy_start_end_date[0]) year_end_date = getdate(to_fy_start_end_date[1]) validate_fiscal_year(year_start_date, year_end_date) diff --git a/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.py b/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.py index e15336b3bc5..3629d4de76c 100644 --- a/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.py +++ b/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.py @@ -54,7 +54,7 @@ def get_net_profit_loss(income, expense, period_list, company): return net_profit_loss def get_chart_data(filters, columns, income, expense, net_profit_loss): - x_intervals = ['x'] + [d.get("label") for d in columns[2:-1]] + x_intervals = ['x'] + [d.get("label") for d in columns[2:]] income_data, expense_data, net_profit = [], [], []