brotherton-erpnext/erpnext/accounts/report/balance_sheet/balance_sheet.py

53 lines
1.6 KiB
Python
Raw Normal View History

2014-07-14 13:36:52 +00:00
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
2014-07-21 10:43:06 +00:00
from frappe import _
from frappe.utils import flt
2014-07-22 13:32:11 +00:00
from erpnext.accounts.report.financial_statements import (get_period_list, get_columns, get_data)
2014-07-14 13:36:52 +00:00
def execute(filters=None):
period_list = get_period_list(filters.fiscal_year, filters.periodicity, from_beginning=True)
2014-07-14 13:36:52 +00:00
2014-07-22 13:32:11 +00:00
asset = get_data(filters.company, "Asset", "Debit", period_list)
liability = get_data(filters.company, "Liability", "Credit", period_list)
equity = get_data(filters.company, "Equity", "Credit", period_list)
2014-07-21 10:43:06 +00:00
provisional_profit_loss = get_provisional_profit_loss(asset, liability, equity, period_list)
2014-07-14 13:36:52 +00:00
data = []
2014-07-21 10:43:06 +00:00
data.extend(asset or [])
data.extend(liability or [])
data.extend(equity or [])
if provisional_profit_loss:
data.append(provisional_profit_loss)
2014-07-17 13:42:28 +00:00
columns = get_columns(period_list)
2014-07-17 13:42:28 +00:00
return columns, data
2014-07-17 13:42:28 +00:00
2014-07-21 10:43:06 +00:00
def get_provisional_profit_loss(asset, liability, equity, period_list):
if asset and (liability or equity):
provisional_profit_loss = {
"account_name": _("Provisional Profit / Loss (Credit)"),
"account": None,
2014-07-22 13:32:11 +00:00
"warn_if_negative": True
2014-07-21 10:43:06 +00:00
}
has_value = False
for period in period_list:
effective_liability = 0.0
if liability:
effective_liability += flt(liability[-2][period.key])
if equity:
effective_liability += flt(equity[-2][period.key])
provisional_profit_loss[period.key] = flt(asset[-2][period.key]) - effective_liability
if provisional_profit_loss[period.key]:
has_value = True
2014-07-17 13:42:28 +00:00
2014-07-21 10:43:06 +00:00
if has_value:
return provisional_profit_loss