diff --git a/account_financial_report/report/trial_balance.py b/account_financial_report/report/trial_balance.py
index 02d65e59..24abbb1a 100644
--- a/account_financial_report/report/trial_balance.py
+++ b/account_financial_report/report/trial_balance.py
@@ -308,182 +308,6 @@ 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)
- ])
-
- if self.filter_account_ids and unaffected_earnings_account not in \
- self.filter_account_ids:
- return True
-
- 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
- INNER JOIN account_move as am
- ON am.id = aml.move_id
- WHERE aml.date >= %(date_from)s
- AND aml.date <= %(date_to)s
- AND aml.company_id = %(company_id)s
- AND aml.account_id IN %(account_ids)s
- """
- if self.only_posted_moves:
- query_select_period_balances += """
- AND am.state = 'posted'
- """
- 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()
- 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)
- # P&L allocated in the current fiscal year.
- date = fields.Datetime.from_string(self.date_from)
- res = self.company_id.compute_fiscalyear_dates(date)
- fy_start_date = res['date_from']
- # Fetch the initial balance
- query_select_initial_pl_balance = """
- SELECT
- sum(aml.balance) as sum_balance
- FROM
- account_move_line as aml
- INNER JOIN
- account_move as am
- ON am.id = aml.move_id
- WHERE aml.date >= %(date_from)s
- AND aml.date < %(date_to)s
- AND aml.company_id = %(company_id)s
- AND aml.account_id IN %(account_ids)s
- """
- if self.only_posted_moves:
- query_select_initial_pl_balance += """
- AND am.state = 'posted'
- """
- query_select_initial_pl_balance_params = {
- 'date_from': fy_start_date,
- 'date_to': self.date_from,
- 'company_id': self.company_id.id,
- 'account_ids': tuple(pl_account_ids),
- }
- self.env.cr.execute(query_select_initial_pl_balance,
- query_select_initial_pl_balance_params)
- res = self.env.cr.fetchone()
- allocated_pl_initial_balance = res[0] or 0.0
- # Fetch the period balance
- query_select_period_pl_balance = """
- SELECT
- sum(aml.debit) as sum_debit,
- sum(aml.credit) as sum_credit
- FROM account_move_line as aml
- INNER JOIN account_move as am
- ON am.id = aml.move_id
- WHERE am.date >= %(date_from)s
- AND aml.date <= %(date_to)s
- AND aml.company_id = %(company_id)s
- AND aml.account_id IN %(account_ids)s
- """
- if self.only_posted_moves:
- query_select_period_pl_balance += """
- AND am.state = 'posted'
- """
- query_select_period_pl_balance_params = {
- 'date_from': self.date_from,
- 'date_to': self.date_to,
- 'company_id': self.company_id.id,
- 'account_ids': tuple(pl_account_ids),
- }
- self.env.cr.execute(query_select_period_pl_balance,
- query_select_period_pl_balance_params)
- res = self.env.cr.fetchone()
- allocated_pl_debit = res[0] or 0.0
- allocated_pl_credit = res[1] or 0.0
- allocated_pl_period_balance = allocated_pl_credit - allocated_pl_debit
- allocated_pl_final_balance = \
- allocated_pl_initial_balance + allocated_pl_period_balance
- allocated_pl_initial_balance = allocated_pl_initial_balance * -1
- query_inject_pl_allocation = """
- INSERT INTO
- report_trial_balance_account (
- report_id,
- create_uid,
- create_date,
- account_id,
- code,
- name,
- initial_balance,
- debit,
- credit,
- period_balance,
- final_balance,
- initial_balance_foreign_currency,
- final_balance_foreign_currency)
- VALUES (
- %(report_id)s,
- %(create_uid)s,
- NOW(),
- %(account_id)s,
- %(code)s,
- %(name)s,
- %(initial_balance)s,
- %(debit)s,
- %(credit)s,
- %(period_balance)s,
- %(final_balance)s,
- 0.0,
- 0.0
- )
- """
- query_inject_pl_allocation_params = {
- 'report_id': self.id,
- 'create_uid': self.env.uid,
- 'account_id': unaffected_earnings_account.id,
- 'code': unaffected_earnings_account.code,
- 'name': '%s (*)' % unaffected_earnings_account.name,
- 'initial_balance': allocated_pl_initial_balance,
- 'debit': allocated_pl_credit,
- 'credit': allocated_pl_debit,
- 'period_balance': allocated_pl_period_balance,
- 'final_balance': allocated_pl_final_balance
- }
- self.env.cr.execute(query_inject_pl_allocation,
- query_inject_pl_allocation_params)
-
def _inject_partner_values(self):
"""Inject report values for report_trial_balance_partner"""
query_inject_partner = """
diff --git a/account_financial_report/report/trial_balance_xlsx.py b/account_financial_report/report/trial_balance_xlsx.py
index 38929bd5..0f213938 100644
--- a/account_financial_report/report/trial_balance_xlsx.py
+++ b/account_financial_report/report/trial_balance_xlsx.py
@@ -13,13 +13,6 @@ class TrialBalanceXslx(models.AbstractModel):
def _get_report_name(self):
return _('Trial Balance')
- def _get_report_footer(self):
- return _('(*) This report applies the current year Profit and Loss '
- 'balances to the Undistributed Profit/Loss account.'
- 'To ensure that the Trial Balance totals total to zero, '
- 'this line represents the reversal of the current year '
- 'P&L Balance.')
-
def _get_report_columns(self, report):
if not report.show_partner_details:
res = {
diff --git a/account_financial_report/tests/test_general_ledger.py b/account_financial_report/tests/test_general_ledger.py
index ba5b4357..584069d8 100644
--- a/account_financial_report/tests/test_general_ledger.py
+++ b/account_financial_report/tests/test_general_ledger.py
@@ -54,8 +54,6 @@ class TestGeneralLedger(a_t_f_c.AbstractTestForeignCurrency):
]
-@common.at_install(False)
-@common.post_install(True)
class TestGeneralLedgerReport(common.TransactionCase):
def setUp(self):
@@ -344,10 +342,10 @@ class TestGeneralLedgerReport(common.TransactionCase):
# Check the initial and final balance
self.assertEqual(lines['unaffected'].initial_debit, 0)
- self.assertEqual(lines['unaffected'].initial_credit, 0)
+ self.assertEqual(lines['unaffected'].initial_credit, 1000)
self.assertEqual(lines['unaffected'].initial_balance, -1000)
- self.assertEqual(lines['unaffected'].final_debit, -0)
- self.assertEqual(lines['unaffected'].final_credit, 0)
+ self.assertEqual(lines['unaffected'].final_debit, 0)
+ self.assertEqual(lines['unaffected'].final_credit, 1000)
self.assertEqual(lines['unaffected'].final_balance, -1000)
# Add reversale move of the initial move the first day of fiscal year
@@ -369,11 +367,11 @@ class TestGeneralLedgerReport(common.TransactionCase):
# Check the initial and final balance
self.assertEqual(lines['unaffected'].initial_debit, 0)
- self.assertEqual(lines['unaffected'].initial_credit, 0)
+ self.assertEqual(lines['unaffected'].initial_credit, 1000)
self.assertEqual(lines['unaffected'].initial_balance, -1000)
- self.assertEqual(lines['unaffected'].final_debit, 0)
- self.assertEqual(lines['unaffected'].final_credit, 0)
- self.assertEqual(lines['unaffected'].final_balance, -1000)
+ self.assertEqual(lines['unaffected'].final_debit, 1000)
+ self.assertEqual(lines['unaffected'].final_credit, 1000)
+ self.assertEqual(lines['unaffected'].final_balance, 0)
# Add another move at the end day of fiscal year
# to check that it correctly used on report
@@ -393,11 +391,11 @@ class TestGeneralLedgerReport(common.TransactionCase):
# Check the initial and final balance
self.assertEqual(lines['unaffected'].initial_debit, 0)
- self.assertEqual(lines['unaffected'].initial_credit, 0)
+ self.assertEqual(lines['unaffected'].initial_credit, 1000)
self.assertEqual(lines['unaffected'].initial_balance, -1000)
- self.assertEqual(lines['unaffected'].final_debit, 0)
- self.assertEqual(lines['unaffected'].final_credit, 0)
- self.assertEqual(lines['unaffected'].final_balance, -4000)
+ self.assertEqual(lines['unaffected'].final_debit, 1000)
+ self.assertEqual(lines['unaffected'].final_credit, 4000)
+ self.assertEqual(lines['unaffected'].final_balance, -3000)
def test_04_unaffected_account_balance_2_years(self):
# Generate the general ledger line
@@ -427,10 +425,10 @@ class TestGeneralLedgerReport(common.TransactionCase):
self.assertEqual(len(lines['unaffected']), 1)
# Check the initial and final balance
- self.assertEqual(lines['unaffected'].initial_debit, 0)
+ self.assertEqual(lines['unaffected'].initial_debit, 1000)
self.assertEqual(lines['unaffected'].initial_credit, 0)
self.assertEqual(lines['unaffected'].initial_balance, 1000)
- self.assertEqual(lines['unaffected'].final_debit, 0)
+ self.assertEqual(lines['unaffected'].final_debit, 1000)
self.assertEqual(lines['unaffected'].final_credit, 0)
self.assertEqual(lines['unaffected'].final_balance, 1000)
@@ -460,9 +458,9 @@ class TestGeneralLedgerReport(common.TransactionCase):
self.assertEqual(len(lines['unaffected']), 1)
# Check the initial and final balance
- self.assertEqual(lines['unaffected'].initial_debit, 0)
+ self.assertEqual(lines['unaffected'].initial_debit, 500)
self.assertEqual(lines['unaffected'].initial_credit, 0)
self.assertEqual(lines['unaffected'].initial_balance, 500)
- self.assertEqual(lines['unaffected'].final_debit, 0)
+ self.assertEqual(lines['unaffected'].final_debit, 500)
self.assertEqual(lines['unaffected'].final_credit, 0)
self.assertEqual(lines['unaffected'].final_balance, 500)
diff --git a/account_financial_report/tests/test_trial_balance.py b/account_financial_report/tests/test_trial_balance.py
index cf386c0a..324cbcca 100644
--- a/account_financial_report/tests/test_trial_balance.py
+++ b/account_financial_report/tests/test_trial_balance.py
@@ -500,9 +500,8 @@ class TestTrialBalanceReport(common.TransactionCase):
self.assertEqual(lines['partner_receivable'].final_balance, -1000)
def test_04_undistributed_pl(self):
- # Generate the trial balance and check that we have 2 lines for the
- # undistributed P&L.
- move_name = 'journal previous fy'
+ # Add a P&L Move in the previous FY
+ move_name = 'current year pl move'
journal = self.env['account.journal'].search([], limit=1)
move_vals = {
'journal_id': journal.id,
@@ -513,16 +512,15 @@ class TestTrialBalanceReport(common.TransactionCase):
'name': move_name,
'debit': 0.0,
'credit': 1000.0,
- 'account_id': self.account100.id}),
+ 'account_id': self.account300.id}),
(0, 0, {
'name': move_name,
'debit': 1000.0,
'credit': 0.0,
- 'account_id': self.account110.id})
- ]}
+ 'account_id': self.account100.id})
+ ]}
move = self.env['account.move'].create(move_vals)
move.post()
-
# Generate the trial balance line
report_account_model = self.env['report_trial_balance_account']
company = self.env.ref('base.main_company')
@@ -541,17 +539,12 @@ class TestTrialBalanceReport(common.TransactionCase):
('report_id', '=', trial_balance.id),
('account_id', '=', self.account110.id),
])
- self.assertEqual(len(unaffected_balance_lines), 2)
- self.assertEqual(unaffected_balance_lines[0].initial_balance, 1000)
+ self.assertEqual(len(unaffected_balance_lines), 1)
+ self.assertEqual(unaffected_balance_lines[0].initial_balance, -1000)
self.assertEqual(unaffected_balance_lines[0].debit, 0)
self.assertEqual(unaffected_balance_lines[0].credit, 0)
- self.assertEqual(unaffected_balance_lines[0].final_balance, 1000)
- # Test P&L Allocation
- self.assertEqual(unaffected_balance_lines[1].initial_balance, 0)
- self.assertEqual(unaffected_balance_lines[1].debit, 0)
- self.assertEqual(unaffected_balance_lines[1].credit, 0)
- self.assertEqual(unaffected_balance_lines[1].final_balance, 0)
- # Add a P&L Move
+ self.assertEqual(unaffected_balance_lines[0].final_balance, -1000)
+ # Add a P&L Move to the current FY
move_name = 'current year pl move'
journal = self.env['account.journal'].search([], limit=1)
move_vals = {
@@ -587,18 +580,56 @@ class TestTrialBalanceReport(common.TransactionCase):
('report_id', '=', trial_balance.id),
('account_id', '=', self.account110.id),
])
- # The unaffected earnings account is affected by this new entry
- self.assertEqual(len(unaffected_balance_lines), 2)
- self.assertEqual(unaffected_balance_lines[0].initial_balance, 1000)
+ # The unaffected earnings account is not affected by a journal entry
+ # made to the P&L in the current fiscal year.
+ self.assertEqual(len(unaffected_balance_lines), 1)
+ self.assertEqual(unaffected_balance_lines[0].initial_balance, -1000)
+ self.assertEqual(unaffected_balance_lines[0].debit, 0)
+ self.assertEqual(unaffected_balance_lines[0].credit, 0)
+ self.assertEqual(unaffected_balance_lines[0].final_balance, -1000)
+ # Add a Move including Unaffected Earnings to the current FY
+ move_name = 'current year unaffected earnings move'
+ journal = self.env['account.journal'].search([], limit=1)
+ move_vals = {
+ 'journal_id': journal.id,
+ 'name': move_name,
+ 'date': self.date_start,
+ 'line_ids': [
+ (0, 0, {
+ 'name': move_name,
+ 'debit': 0.0,
+ 'credit': 1000.0,
+ 'account_id': self.account110.id}),
+ (0, 0, {
+ 'name': move_name,
+ 'debit': 1000.0,
+ 'credit': 0.0,
+ 'account_id': self.account100.id})
+ ]}
+ move = self.env['account.move'].create(move_vals)
+ move.post()
+ # Re Generate the trial balance line
+ trial_balance = self.env['report_trial_balance'].create({
+ 'date_from': self.date_start,
+ 'date_to': self.date_end,
+ 'only_posted_moves': True,
+ 'hide_account_balance_at_0': False,
+ 'hierarchy_on': 'none',
+ 'company_id': company.id,
+ 'fy_start_date': self.fy_date_start,
+ })
+ trial_balance.compute_data_for_report()
+ # The unaffected earnings account affected by a journal entry
+ # made to the unaffected earnings in the current fiscal year.
+ unaffected_balance_lines = report_account_model.search([
+ ('report_id', '=', trial_balance.id),
+ ('account_id', '=', self.account110.id),
+ ])
+ self.assertEqual(len(unaffected_balance_lines), 1)
+ self.assertEqual(unaffected_balance_lines[0].initial_balance, -1000)
self.assertEqual(unaffected_balance_lines[0].debit, 0)
self.assertEqual(unaffected_balance_lines[0].credit, 1000)
- self.assertEqual(unaffected_balance_lines[0].final_balance, 0)
- # The P&L is affected by this new entry, basically reversing the
- # P&L balances.
- self.assertEqual(unaffected_balance_lines[1].initial_balance, 0)
- self.assertEqual(unaffected_balance_lines[1].debit, 1000)
- self.assertEqual(unaffected_balance_lines[1].credit, 0)
- self.assertEqual(unaffected_balance_lines[1].final_balance, 1000)
+ self.assertEqual(unaffected_balance_lines[0].final_balance, -2000)
# The totals for the Trial Balance are zero
all_lines = report_account_model.search([
('report_id', '=', trial_balance.id),