Browse Source

[account_financial_report] improve the calculation in the Trial Balance

of undistributed profits/losses account, and provide a footer note
to the user explaining why will the ending balances will not be zero, but the
period's total profit and loss.
pull/481/head
Jordi Ballester Alomar 6 years ago
parent
commit
7ffa69b336
  1. 7
      account_financial_report/report/templates/trial_balance.xml
  2. 58
      account_financial_report/report/trial_balance.py

7
account_financial_report/report/templates/trial_balance.xml

@ -99,8 +99,15 @@
</div>
</t>
</t>
<!-- Display filters -->
<t t-call="account_financial_report.report_trial_balance_footer"/>
</div>
</template>
<template id="account_financial_report.report_trial_balance_footer">
(*) This report automates the application of the current period Profit and Loss balances to the Undistributed Profit/Loss account.
Therefore to check the correctness of the Trial Balance, consider that the Total Ending Balance is
going to be equal to the period's total Profit &amp; Loss, instead of zero.
</template>
<template id="account_financial_report.report_trial_balance_filters">
<div class="act_as_table data_table" style="width: 100%;">

58
account_financial_report/report/trial_balance.py

@ -308,6 +308,64 @@ WHERE
)
self.env.cr.execute(query_inject_account, query_inject_account_params)
# Inject current period debits and credits for the unaffected earnings
# account.
account_type = self.env.ref('account.data_unaffected_earnings')
unaffected_earnings_account = self.env['account.account'].search(
[
('user_type_id', '=', account_type.id),
('company_id', '=', self.company_id.id)
])
query_unaffected_earnings_account_ids = """
SELECT a.id
FROM account_account as a
INNER JOIN account_account_type as at
ON at.id = a.user_type_id
WHERE at.include_initial_balance = FALSE
"""
self.env.cr.execute(query_unaffected_earnings_account_ids)
pl_account_ids = [r[0] for r in self.env.cr.fetchall()]
unaffected_earnings_account_ids = pl_account_ids + [
unaffected_earnings_account.id]
query_select_period_balances = """
SELECT sum(aml.debit) as sum_debit,
sum(aml.credit) as sum_credit
FROM account_move_line as aml
WHERE date >= %(date_from)s
AND date <= %(date_to)s
AND company_id = %(company_id)s
AND account_id IN %(account_ids)s
"""
query_select_period_balances_params = {
'date_from': self.date_from,
'date_to': self.date_to,
'company_id': self.company_id.id,
'account_ids': tuple(unaffected_earnings_account_ids)
}
self.env.cr.execute(query_select_period_balances,
query_select_period_balances_params)
sum_debit, sum_credit = self.env.cr.fetchone()
unaffected_earnings_account_name = \
'%s (*)' % unaffected_earnings_account.name
query_update_unaffected_earnings_account = """
UPDATE report_trial_balance_account
SET
name = %(unaffected_earnings_account_name)s,
debit = %(sum_debit)s,
credit = %(sum_credit)s
WHERE account_id = %(unaffected_earning_account_id)s
"""
query_update_unaffected_earnings_account_params = {
'sum_debit': sum_debit,
'sum_credit': sum_credit,
'unaffected_earning_account_id': unaffected_earnings_account.id,
'unaffected_earnings_account_name':
unaffected_earnings_account_name
}
self.env.cr.execute(query_update_unaffected_earnings_account,
query_update_unaffected_earnings_account_params)
def _inject_partner_values(self):
"""Inject report values for report_trial_balance_partner"""
query_inject_partner = """

Loading…
Cancel
Save