Skip to content

Commit

Permalink
feat: Added Periodicity to Consolidate Financial Statements and Cost …
Browse files Browse the repository at this point in the history
…Center Financial Statements and Added Variance feature to Consolidated Financial Statements (#1793)

* single company consolidated financial statement report

* add periodicity for multiple company

* push changes related to totals

* added and update period list code consolidated financial statement for balance sheet, profit and loss and cash flow

* Add total for assests and equlity and liability (horizontal).

* update for get_provisional_profit_loss() for Total Assets, Equity and liability and also add variance changes.

* remove unused funtion and intentation

* made change for profit and losses and cash flow for consolidated statement and also made some changes in cost center statement to work the same.

* remove comment from profit and losses file

* remove unwanteed comment and optimized get_columns for periodicity

* optimized code in consolidated financial for prepare_data

* code optimzed in balance.py for provisional_profit_loss

* remove commented code in cost_center_financial_statements

* remove commented code in consolidated_financial_statement.py in add_total_row()

Co-authored-by: Imdadhussain <[email protected]>
  • Loading branch information
imdadhussain and Imdadhussain authored Nov 23, 2021
1 parent 7550e63 commit e1ccc60
Show file tree
Hide file tree
Showing 6 changed files with 313 additions and 158 deletions.
55 changes: 35 additions & 20 deletions erpnext/accounts/report/balance_sheet/balance_sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def create_equity_with_provisions(provisional_profit_loss, period_list):
equity.append({}) #blank line for better optics post adding the provisions to the equity summary
return equity

def get_provisional_profit_loss(asset, liability, equity, period_list, company, currency=None, consolidated=False):
def get_provisional_profit_loss(asset, liability, equity, period_list, company, companies=None, currency=None, consolidated=False):
provisional_profit_loss = {}
total_row = {}

Expand All @@ -137,25 +137,12 @@ def get_provisional_profit_loss(asset, liability, equity, period_list, company,
}
has_value = False

for period in period_list:
key = period if consolidated else period.key
effective_liability = 0.0
if liability:
effective_liability += flt(liability[-2].get(key))
if equity:
effective_liability += flt(equity[-2].get(key))

provisional_profit_loss[key] = flt(asset[-2].get(key)) - effective_liability
total_row[key] = effective_liability + provisional_profit_loss[key]

if provisional_profit_loss[key]:
has_value = True

total += flt(provisional_profit_loss[key])
provisional_profit_loss["total"] = total

total_row_total += flt(total_row[key])
total_row["total"] = total_row_total
if consolidated:
for company in companies:
total = total_row_total=0
has_value, provisional_profit_loss, total_row, total, total_row_total = add_periodicity_for_provisional_profit_loss(asset, liability, equity, period_list, provisional_profit_loss, total_row, total, total_row_total, has_value, consolidated, company)
else:
has_value, provisional_profit_loss, total_row, total, total_row_total = add_periodicity_for_provisional_profit_loss(asset, liability, equity, period_list, provisional_profit_loss, total_row, total, total_row_total, has_value, consolidated)

if has_value:
provisional_profit_loss.update({
Expand All @@ -172,6 +159,34 @@ def get_provisional_profit_loss(asset, liability, equity, period_list, company,

return provisional_profit_loss, total_row

def add_periodicity_for_provisional_profit_loss(asset, liability, equity, period_list, provisional_profit_loss, total_row, total, total_row_total, has_value, consolidated, company=None):
for period in period_list:
if consolidated:
key = f'{company}({period.key})'
else:
key = f'{period.key}'
effective_liability = 0.0
if liability:
effective_liability += flt(liability[-2].get(key))
if equity:
effective_liability += flt(equity[-2].get(key))

provisional_profit_loss[key] = flt(asset[-2].get(key)) - effective_liability
total_row[key] = effective_liability + provisional_profit_loss[key]

if provisional_profit_loss[key]:
has_value = True

total += flt(provisional_profit_loss[key])
total_row_total += flt(total_row[key])
if company:
provisional_profit_loss[f"{company}(total)"] = total
total_row[f"{company}(total)"] = total_row_total
else:
provisional_profit_loss["total"] = total
total_row["total"] = total_row_total
return has_value, provisional_profit_loss, total_row, total, total_row_total

def check_opening_balance(asset, liability, equity):
# Check if previous year balance sheet closed
opening_balance = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,31 @@ frappe.query_reports["Consolidated Financial Statement"] = {
"reqd": 1
},
{
"fieldname":"from_fiscal_year",
"label": __("Start Year"),
"fieldtype": "Link",
"options": "Fiscal Year",
"default": frappe.defaults.get_user_default("fiscal_year"),
"fieldname": "from_date",
"label": __("From Date"),
"fieldtype": "Date",
"default": frappe.defaults.get_user_default("year_start_date"),
"reqd": 1
},
{
"fieldname":"to_fiscal_year",
"label": __("End Year"),
"fieldtype": "Link",
"options": "Fiscal Year",
"default": frappe.defaults.get_user_default("fiscal_year"),
"fieldname": "to_date",
"label": __("To Date"),
"fieldtype": "Date",
"default": frappe.defaults.get_user_default("year_end_date"),
"reqd": 1
},
{
"fieldname": "periodicity",
"label": __("Periodicity"),
"fieldtype": "Select",
"options": [
{ "value": "Custom", "label": __("Custom Date Range") },
{ "value": "Monthly", "label": __("Monthly") },
{ "value": "Quarterly", "label": __("Quarterly") },
{ "value": "Half-Yearly", "label": __("Half-Yearly") },
{ "value": "Yearly", "label": __("Yearly") }
],
"default": "Yearly",
"reqd": 1
},
{
Expand All @@ -49,6 +61,16 @@ frappe.query_reports["Consolidated Financial Statement"] = {
"options": erpnext.get_presentation_currency_list(),
"default": frappe.defaults.get_user_default("Currency")
},
{
"fieldname": "cost_center",
"label": __("Cost Center"),
"fieldtype": "MultiSelectList",
get_data: function(txt) {
return frappe.db.get_link_options('Cost Center', txt, {
company: frappe.query_report.get_filter_value("company")
});
}
},
{
"fieldname":"accumulated_in_group_company",
"label": __("Accumulated Values in Group Company"),
Expand All @@ -60,6 +82,58 @@ frappe.query_reports["Consolidated Financial Statement"] = {
"label": __("Include Default Book Entries"),
"fieldtype": "Check",
"default": 1
},
{
"fieldname":"from_company",
"label": __("From Company"),
"fieldtype": "Link",
"options": "Company",
"hidden": 1,
"reqd": 0,
get_query: function () {
var company = frappe.query_report.get_filter_value("company");
company_list = {
doctype: "Company",
filters: {
"is_group": 0,
"parent_company": company,
},
};
return company_list
},
},
{
"fieldname":"to_company",
"label": __("To Company"),
"fieldtype": "Link",
"options": "Company",
"hidden": 1,
"reqd": 0,
get_query: function () {
var company = frappe.query_report.get_filter_value("company");
company_list = {
doctype: "Company",
filters: {
"is_group": 0,
"parent_company": company,
},
};
return company_list
},
},
{
"fieldname":"compare_with_company",
"label": __("Compare Statements"),
"fieldtype": "Check",
"default": 0,
on_change: () => {
let filter_based_on = frappe.query_report.get_filter_value('compare_with_company');
frappe.query_report.toggle_filter_display('from_company', filter_based_on === 0);
frappe.query_report.toggle_filter_display('to_company', filter_based_on === 0);
frappe.query_report.refresh();
},

}

]
}
Loading

0 comments on commit e1ccc60

Please sign in to comment.