mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-07 23:31:20 +00:00
fixed accumulated values for cash flow
This commit is contained in:
@@ -6,6 +6,7 @@ import frappe
|
|||||||
from frappe import _
|
from frappe import _
|
||||||
from erpnext.accounts.report.financial_statements import (get_period_list, get_columns, get_data)
|
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.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):
|
def execute(filters=None):
|
||||||
@@ -49,9 +50,9 @@ def execute(filters=None):
|
|||||||
|
|
||||||
# compute net profit / loss
|
# compute net profit / loss
|
||||||
income = get_data(filters.company, "Income", "Credit", period_list,
|
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,
|
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)
|
net_profit_loss = get_net_profit_loss(income, expense, period_list, filters.company)
|
||||||
|
|
||||||
@@ -98,18 +99,18 @@ def execute(filters=None):
|
|||||||
|
|
||||||
return columns, data
|
return columns, data
|
||||||
|
|
||||||
|
|
||||||
def get_account_type_based_data(company, account_type, period_list, accumulated_values):
|
def get_account_type_based_data(company, account_type, period_list, accumulated_values):
|
||||||
data = {}
|
data = {}
|
||||||
total = 0
|
total = 0
|
||||||
for period in period_list:
|
for period in period_list:
|
||||||
|
start_date = get_start_date(period, accumulated_values)
|
||||||
gl_sum = frappe.db.sql_list("""
|
gl_sum = frappe.db.sql_list("""
|
||||||
select sum(credit) - sum(debit)
|
select sum(credit) - sum(debit)
|
||||||
from `tabGL Entry`
|
from `tabGL Entry`
|
||||||
where company=%s and posting_date >= %s and posting_date <= %s
|
where company=%s and posting_date >= %s and posting_date <= %s
|
||||||
and voucher_type != 'Period Closing Voucher'
|
and voucher_type != 'Period Closing Voucher'
|
||||||
and account in ( SELECT name FROM tabAccount WHERE account_type = %s)
|
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))
|
period['to_date'], account_type))
|
||||||
|
|
||||||
if gl_sum and gl_sum[0]:
|
if gl_sum and gl_sum[0]:
|
||||||
@@ -125,6 +126,12 @@ def get_account_type_based_data(company, account_type, period_list, accumulated_
|
|||||||
data["total"] = total
|
data["total"] = total
|
||||||
return data
|
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):
|
def add_total_row_account(out, data, label, period_list, currency):
|
||||||
total_row = {
|
total_row = {
|
||||||
|
|||||||
@@ -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"])
|
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:
|
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:
|
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]
|
# 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])
|
year_end_date = getdate(to_fy_start_end_date[1])
|
||||||
|
|
||||||
validate_fiscal_year(year_start_date, year_end_date)
|
validate_fiscal_year(year_start_date, year_end_date)
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ def get_net_profit_loss(income, expense, period_list, company):
|
|||||||
return net_profit_loss
|
return net_profit_loss
|
||||||
|
|
||||||
def get_chart_data(filters, columns, income, expense, 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 = [], [], []
|
income_data, expense_data, net_profit = [], [], []
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user