From 49523d7f80de26d92bd83c03e31c53cb04c382e5 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Tue, 21 Feb 2017 14:20:26 +0530 Subject: [PATCH] [Fix] Company fiscal year issue in financial statement --- erpnext/accounts/report/balance_sheet/balance_sheet.py | 2 +- erpnext/accounts/report/cash_flow/cash_flow.py | 2 +- erpnext/accounts/report/financial_statements.py | 9 +++++---- .../profit_and_loss_statement.py | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/erpnext/accounts/report/balance_sheet/balance_sheet.py b/erpnext/accounts/report/balance_sheet/balance_sheet.py index 5ff8e3e228..7e57dce67a 100644 --- a/erpnext/accounts/report/balance_sheet/balance_sheet.py +++ b/erpnext/accounts/report/balance_sheet/balance_sheet.py @@ -8,7 +8,7 @@ from frappe.utils import flt, cint from erpnext.accounts.report.financial_statements import (get_period_list, get_columns, get_data) def execute(filters=None): - period_list = get_period_list(filters.from_fiscal_year, filters.to_fiscal_year, filters.periodicity) + period_list = get_period_list(filters.from_fiscal_year, filters.to_fiscal_year, filters.periodicity, filters.company) asset = get_data(filters.company, "Asset", "Debit", period_list, only_current_fiscal_year=False) liability = get_data(filters.company, "Liability", "Credit", period_list, only_current_fiscal_year=False) diff --git a/erpnext/accounts/report/cash_flow/cash_flow.py b/erpnext/accounts/report/cash_flow/cash_flow.py index 182878af37..d4d22525cb 100644 --- a/erpnext/accounts/report/cash_flow/cash_flow.py +++ b/erpnext/accounts/report/cash_flow/cash_flow.py @@ -10,7 +10,7 @@ from erpnext.accounts.utils import get_fiscal_year def execute(filters=None): - period_list = get_period_list(filters.from_fiscal_year, filters.to_fiscal_year, filters.periodicity) + period_list = get_period_list(filters.from_fiscal_year, filters.to_fiscal_year, filters.periodicity, filters.company) operation_accounts = { "section_name": "Operations", diff --git a/erpnext/accounts/report/financial_statements.py b/erpnext/accounts/report/financial_statements.py index bc4a220faa..695503749a 100644 --- a/erpnext/accounts/report/financial_statements.py +++ b/erpnext/accounts/report/financial_statements.py @@ -8,7 +8,7 @@ from frappe import _ from frappe.utils import (flt, getdate, get_first_day, get_last_day, date_diff, add_months, add_days, formatdate, cint) -def get_period_list(from_fiscal_year, to_fiscal_year, periodicity): +def get_period_list(from_fiscal_year, to_fiscal_year, periodicity, company): """Get a list of dict {"from_date": from_date, "to_date": to_date, "key": key, "label": label} Periodicity can be (Yearly, Quarterly, Monthly)""" @@ -50,7 +50,7 @@ def get_period_list(from_fiscal_year, to_fiscal_year, periodicity): # if a fiscal year ends before a 12 month period period.to_date = year_end_date - period.to_date_fiscal_year = get_date_fiscal_year(period.to_date) + period.to_date_fiscal_year = get_date_fiscal_year(period.to_date, company) period_list.append(period) @@ -142,15 +142,16 @@ def calculate_values(accounts_by_name, gl_entries_by_account, period_list, accum if entry.posting_date <= period.to_date: if (accumulated_values or entry.posting_date >= period.from_date) and \ (entry.fiscal_year == period.to_date_fiscal_year or not ignore_accumulated_values_for_fy): + frappe.errprint([entry.fiscal_year, period.to_date_fiscal_year]) d[period.key] = d.get(period.key, 0.0) + flt(entry.debit) - flt(entry.credit) if entry.posting_date < period_list[0].year_start_date: d["opening_balance"] = d.get("opening_balance", 0.0) + flt(entry.debit) - flt(entry.credit) -def get_date_fiscal_year(date): +def get_date_fiscal_year(date, company): from erpnext.accounts.utils import get_fiscal_year - return get_fiscal_year(date)[0] + return get_fiscal_year(date, company=company)[0] def accumulate_values_into_parents(accounts, accounts_by_name, period_list, accumulated_values): """accumulate children's values in parent accounts""" 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 747eb43006..e12fa063fb 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 @@ -8,7 +8,7 @@ from frappe.utils import flt from erpnext.accounts.report.financial_statements import (get_period_list, get_columns, get_data) def execute(filters=None): - period_list = get_period_list(filters.from_fiscal_year, filters.to_fiscal_year, filters.periodicity) + period_list = get_period_list(filters.from_fiscal_year, filters.to_fiscal_year, filters.periodicity, filters.company) income = get_data(filters.company, "Income", "Credit", period_list, filters = filters, accumulated_values=filters.accumulated_values, ignore_closing_entries=True, ignore_accumulated_values_for_fy= True)