Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added Periodicity to Consolidate Financial Statements and Cost Center Financial Statements and Added Variance feature to Consolidated Financial Statements #1793

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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