[fix][balance sheet] Check if previous fiscal year is closed
This commit is contained in:
parent
a9ce706bfb
commit
443a7c13e4
@ -16,6 +16,8 @@ def execute(filters=None):
|
||||
|
||||
provisional_profit_loss = get_provisional_profit_loss(asset, liability, equity,
|
||||
period_list, filters.company)
|
||||
|
||||
message = check_opening_balance(asset, liability, equity)
|
||||
|
||||
data = []
|
||||
data.extend(asset or [])
|
||||
@ -26,7 +28,7 @@ def execute(filters=None):
|
||||
|
||||
columns = get_columns(filters.periodicity, period_list, company=filters.company)
|
||||
|
||||
return columns, data
|
||||
return columns, data, message
|
||||
|
||||
def get_provisional_profit_loss(asset, liability, equity, period_list, company):
|
||||
if asset and (liability or equity):
|
||||
@ -57,3 +59,14 @@ def get_provisional_profit_loss(asset, liability, equity, period_list, company):
|
||||
|
||||
if has_value:
|
||||
return provisional_profit_loss
|
||||
|
||||
def check_opening_balance(asset, liability, equity):
|
||||
# Check if previous year balance sheet closed
|
||||
opening_balance = flt(asset[0].get("opening_balance", 0))
|
||||
if liability:
|
||||
opening_balance -= flt(liability[0].get("opening_balance", 0))
|
||||
if equity:
|
||||
opening_balance -= flt(asset[0].get("opening_balance", 0))
|
||||
|
||||
if opening_balance:
|
||||
return _("Previous Financial Year is not closed")
|
@ -125,14 +125,20 @@ 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:
|
||||
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 accumulate_values_into_parents(accounts, accounts_by_name, period_list, accumulated_values):
|
||||
"""accumulate children's values in parent accounts"""
|
||||
for d in reversed(accounts):
|
||||
if d.parent_account:
|
||||
for period in period_list:
|
||||
accounts_by_name[d.parent_account][period.key] = accounts_by_name[d.parent_account].get(period.key, 0.0) + \
|
||||
d.get(period.key, 0.0)
|
||||
accounts_by_name[d.parent_account][period.key] = \
|
||||
accounts_by_name[d.parent_account].get(period.key, 0.0) + d.get(period.key, 0.0)
|
||||
|
||||
accounts_by_name[d.parent_account]["opening_balance"] = \
|
||||
accounts_by_name[d.parent_account].get("opening_balance", 0.0) + d.get("opening_balance", 0.0)
|
||||
|
||||
def prepare_data(accounts, balance_must_be, period_list, company_currency):
|
||||
data = []
|
||||
@ -150,13 +156,14 @@ def prepare_data(accounts, balance_must_be, period_list, company_currency):
|
||||
"indent": flt(d.indent),
|
||||
"year_start_date": year_start_date,
|
||||
"year_end_date": year_end_date,
|
||||
"currency": company_currency
|
||||
"currency": company_currency,
|
||||
"opening_balance": d.get("opening_balance", 0.0) * (1 if balance_must_be=="Debit" else -1)
|
||||
})
|
||||
for period in period_list:
|
||||
if d.get(period.key):
|
||||
if d.get(period.key) and balance_must_be=="Credit":
|
||||
# change sign based on Debit or Credit, since calculation is done using (debit - credit)
|
||||
d[period.key] *= (1 if balance_must_be=="Debit" else -1)
|
||||
|
||||
d[period.key] *= -1
|
||||
|
||||
row[period.key] = flt(d.get(period.key, 0.0), 3)
|
||||
|
||||
if abs(row[period.key]) >= 0.005:
|
||||
|
Loading…
Reference in New Issue
Block a user