[IMP] account_financial_report: Remove 'Computed Accounts' option from 'trial balance'.

pull/965/head
Ernesto Tejeda 2022-05-31 00:14:19 -04:00 committed by Víctor Martínez
parent 8e67e42192
commit 545c9d1853
6 changed files with 34 additions and 279 deletions

View File

@ -46,57 +46,23 @@
<t t-foreach="trial_balance" t-as="balance">
<!-- Adapt -->
<t t-set="style" t-value="'font-size:12px;'" />
<t t-if="hierarchy_on == 'none'">
<t
t-call="account_financial_report.report_trial_balance_line"
/>
</t>
<t t-if="hierarchy_on == 'computed'">
<t t-if="balance['type'] == 'group_type'">
<t
t-set="style"
t-value="style + 'font-weight: bold; color: blue;'"
/>
<t
t-call="account_financial_report.report_trial_balance_line"
/>
</t>
<t t-if="balance['type'] == 'account_type'">
<t
t-call="account_financial_report.report_trial_balance_line"
/>
</t>
</t>
<!-- <t t-set="padding" t-value="line.level * 4"/>-->
<!-- <t t-if="hierarchy_on != 'none'">-->
<!-- <t t-set="style" t-value="'font-size: ' + str(14 - line.level) + 'px; margin-left: ' + str(line.level * 4) + 'px;'"/>-->
<!-- </t>-->
<t t-if="hierarchy_on == 'relation'">
<t t-if="balance['type'] == 'group_type'">
<t
t-set="style"
t-value="style + 'font-weight: bold; color: blue;'"
/>
<t
t-call="account_financial_report.report_trial_balance_line"
/>
</t>
<t t-if="balance['type'] == 'account_type'">
<t t-if="show_hierarchy">
<t t-if="limit_hierarchy_level">
<t t-if="show_hierarchy_level > balance['level']">
<t
t-if="show_hierarchy_level > balance['level'] and (not hide_parent_hierarchy_level or (show_hierarchy_level - 1) == balance['level'])"
>
<t
t-call="account_financial_report.report_trial_balance_line"
/>
</t>
</t>
<t t-if="not limit_hierarchy_level">
</t>
<t t-else="">
<t
t-call="account_financial_report.report_trial_balance_line"
/>
</t>
</t>
</t>
</t>
</div>
</t>
<!-- Display partner lines -->

View File

@ -662,7 +662,7 @@ class TrialBalanceReport(models.AbstractModel):
date_to = data["date_to"]
date_from = data["date_from"]
hide_account_at_0 = data["hide_account_at_0"]
hierarchy_on = data["hierarchy_on"]
show_hierarchy = data["show_hierarchy"]
show_hierarchy_level = data["show_hierarchy_level"]
foreign_currency = data["foreign_currency"]
only_posted_moves = data["only_posted_moves"]
@ -706,7 +706,7 @@ class TrialBalanceReport(models.AbstractModel):
],
}
)
if hierarchy_on == "relation":
if show_hierarchy:
groups_data = self._get_groups_data(
accounts_data, total_amount, foreign_currency
)
@ -716,14 +716,7 @@ class TrialBalanceReport(models.AbstractModel):
for trial in trial_balance:
counter = trial["complete_code"].count("/")
trial["level"] = counter
if hierarchy_on == "computed":
groups_data = self._get_computed_groups_data(
accounts_data, total_amount, foreign_currency
)
trial_balance = list(groups_data.values())
trial_balance += list(accounts_data.values())
trial_balance = sorted(trial_balance, key=lambda k: k["code"])
if hierarchy_on == "none":
else:
trial_balance = list(accounts_data.values())
trial_balance = sorted(trial_balance, key=lambda k: k["code"])
else:
@ -749,7 +742,8 @@ class TrialBalanceReport(models.AbstractModel):
"hide_account_at_0": data["hide_account_at_0"],
"show_partner_details": data["show_partner_details"],
"limit_hierarchy_level": data["limit_hierarchy_level"],
"hierarchy_on": hierarchy_on,
"show_hierarchy": show_hierarchy,
"hide_parent_hierarchy_level": data["hide_parent_hierarchy_level"],
"trial_balance": trial_balance,
"total_amount": total_amount,
"accounts_data": accounts_data,

View File

@ -183,7 +183,7 @@ class TrialBalanceXslx(models.AbstractModel):
total_amount = res_data["total_amount"]
partners_data = res_data["partners_data"]
accounts_data = res_data["accounts_data"]
hierarchy_on = res_data["hierarchy_on"]
show_hierarchy = res_data["show_hierarchy"]
show_partner_details = res_data["show_partner_details"]
show_hierarchy_level = res_data["show_hierarchy_level"]
foreign_currency = res_data["foreign_currency"]
@ -195,15 +195,7 @@ class TrialBalanceXslx(models.AbstractModel):
# For each account
if not show_partner_details:
for balance in trial_balance:
if hierarchy_on == "relation":
if limit_hierarchy_level:
if show_hierarchy_level > balance["level"]:
# Display account lines
self.write_line_from_dict(balance, report_data)
else:
self.write_line_from_dict(balance, report_data)
elif hierarchy_on == "computed":
if balance["type"] == "account_type":
if show_hierarchy:
if limit_hierarchy_level:
if show_hierarchy_level > balance["level"]:
# Display account lines

View File

@ -163,7 +163,7 @@ class TestTrialBalanceReport(AccountTestInvoicingCommon):
move.action_post()
def _get_report_lines(
self, with_partners=False, account_ids=False, hierarchy_on="computed"
self, with_partners=False, account_ids=False, show_hierarchy=False
):
company = self.env.user.company_id
trial_balance = self.env["trial.balance.report.wizard"].create(
@ -172,7 +172,7 @@ class TestTrialBalanceReport(AccountTestInvoicingCommon):
"date_to": self.date_end,
"target_move": "posted",
"hide_account_at_0": True,
"hierarchy_on": hierarchy_on,
"show_hierarchy": show_hierarchy,
"company_id": company.id,
"account_ids": account_ids,
"fy_start_date": self.fy_date_start,
@ -248,195 +248,9 @@ class TestTrialBalanceReport(AccountTestInvoicingCommon):
self.assertTrue(self.account100 in self.group1.compute_account_ids)
self.assertTrue(self.account200 in self.group2.compute_account_ids)
def test_01_account_balance_computed(self):
# Change code of the P&L for not being automatically included
# in group 1 balances
earning_accs = self.env["account.account"].search(
[
(
"user_type_id",
"=",
self.env.ref("account.data_unaffected_earnings").id,
),
("company_id", "=", self.env.user.company_id.id),
]
)
for acc in earning_accs:
acc.code = "999" + acc.code
# Generate the general ledger line
res_data = self._get_report_lines()
trial_balance = res_data["trial_balance"]
check_receivable_account = self.check_account_in_report(
self.account100.id, trial_balance
)
self.assertFalse(check_receivable_account)
check_income_account = self.check_account_in_report(
self.account200.id, trial_balance
)
self.assertFalse(check_income_account)
self.assertTrue(
self.check_account_in_report(self.unaffected_account.id, trial_balance)
)
# Add a move at the previous day of the first day of fiscal year
# to check the initial balance
self._add_move(
date=self.previous_fy_date_end,
receivable_debit=1000,
receivable_credit=0,
income_debit=0,
income_credit=1000,
)
# Re Generate the trial balance line
res_data = self._get_report_lines()
trial_balance = res_data["trial_balance"]
check_receivable_account = self.check_account_in_report(
self.account100.id, trial_balance
)
self.assertTrue(check_receivable_account)
check_income_account = self.check_account_in_report(
self.account200.id, trial_balance
)
self.assertFalse(check_income_account)
# Check the initial and final balance
account_receivable_lines = self._get_account_lines(
self.account100.id, trial_balance
)
group1_lines = self._get_group_lines(self.group1.id, trial_balance)
self.assertEqual(account_receivable_lines["initial_balance"], 1000)
self.assertEqual(account_receivable_lines["debit"], 0)
self.assertEqual(account_receivable_lines["credit"], 0)
self.assertEqual(account_receivable_lines["final_balance"], 1000)
self.assertEqual(group1_lines["initial_balance"], 1000)
self.assertEqual(group1_lines["debit"], 0)
self.assertEqual(group1_lines["credit"], 0)
self.assertEqual(group1_lines["final_balance"], 1000)
# Add reversed move of the initial move the first day of fiscal year
# to check the first day of fiscal year is not used
# to compute the initial balance
self._add_move(
date=self.fy_date_start,
receivable_debit=0,
receivable_credit=1000,
income_debit=1000,
income_credit=0,
)
# Re Generate the trial balance line
res_data = self._get_report_lines()
trial_balance = res_data["trial_balance"]
check_receivable_account = self.check_account_in_report(
self.account100.id, trial_balance
)
self.assertTrue(check_receivable_account)
check_income_account = self.check_account_in_report(
self.account200.id, trial_balance
)
self.assertTrue(check_income_account)
# Re Generate the trial balance line with an account filter
res_data = self._get_report_lines(
account_ids=(self.account100 + self.account200).ids
)
trial_balance = res_data["trial_balance"]
self.assertTrue(self.check_account_in_report(self.account100.id, trial_balance))
self.assertTrue(self.check_account_in_report(self.account200.id, trial_balance))
# Unaffected account should not be present
self.assertFalse(
self.check_account_in_report(self.unaffected_account.id, trial_balance)
)
# Check the initial and final balance
account_receivable_lines = self._get_account_lines(
self.account100.id, trial_balance
)
account_income_lines = self._get_account_lines(
self.account200.id, trial_balance
)
group1_lines = self._get_group_lines(self.group1.id, trial_balance)
group2_lines = self._get_group_lines(self.group2.id, trial_balance)
self.assertEqual(account_receivable_lines["initial_balance"], 1000)
self.assertEqual(account_receivable_lines["debit"], 0)
self.assertEqual(account_receivable_lines["credit"], 1000)
self.assertEqual(account_receivable_lines["final_balance"], 0)
self.assertEqual(account_income_lines["initial_balance"], 0)
self.assertEqual(account_income_lines["debit"], 1000)
self.assertEqual(account_income_lines["credit"], 0)
self.assertEqual(account_income_lines["final_balance"], 1000)
self.assertEqual(group1_lines["initial_balance"], 1000)
self.assertEqual(group1_lines["debit"], 0)
self.assertEqual(group1_lines["credit"], 1000)
self.assertEqual(group1_lines["final_balance"], 0)
self.assertEqual(group2_lines["initial_balance"], 0)
self.assertEqual(group2_lines["debit"], 1000)
self.assertEqual(group2_lines["credit"], 0)
self.assertEqual(group2_lines["final_balance"], 1000)
# Add another move at the end day of fiscal year
# to check that it correctly used on report
self._add_move(
date=self.fy_date_end,
receivable_debit=0,
receivable_credit=1000,
income_debit=1000,
income_credit=0,
)
# Re Generate the trial balance line
res_data = self._get_report_lines()
trial_balance = res_data["trial_balance"]
check_receivable_account = self.check_account_in_report(
self.account100.id, trial_balance
)
self.assertTrue(check_receivable_account)
check_income_account = self.check_account_in_report(
self.account200.id, trial_balance
)
self.assertTrue(check_income_account)
# Check the initial and final balance
account_receivable_lines = self._get_account_lines(
self.account100.id, trial_balance
)
account_income_lines = self._get_account_lines(
self.account200.id, trial_balance
)
group1_lines = self._get_group_lines(self.group1.id, trial_balance)
group2_lines = self._get_group_lines(self.group2.id, trial_balance)
self.assertEqual(account_receivable_lines["initial_balance"], 1000)
self.assertEqual(account_receivable_lines["debit"], 0)
self.assertEqual(account_receivable_lines["credit"], 2000)
self.assertEqual(account_receivable_lines["final_balance"], -1000)
self.assertEqual(account_income_lines["initial_balance"], 0)
self.assertEqual(account_income_lines["debit"], 2000)
self.assertEqual(account_income_lines["credit"], 0)
self.assertEqual(account_income_lines["final_balance"], 2000)
self.assertEqual(group1_lines["initial_balance"], 1000)
self.assertEqual(group1_lines["debit"], 0)
self.assertEqual(group1_lines["credit"], 2000)
self.assertEqual(group1_lines["final_balance"], -1000)
self.assertEqual(group2_lines["initial_balance"], 0)
self.assertEqual(group2_lines["debit"], 2000)
self.assertEqual(group2_lines["credit"], 0)
self.assertEqual(group2_lines["final_balance"], 2000)
def test_02_account_balance_hierarchy(self):
# Generate the general ledger line
res_data = self._get_report_lines(hierarchy_on="relation")
res_data = self._get_report_lines(show_hierarchy=True)
trial_balance = res_data["trial_balance"]
check_receivable_account = self.check_account_in_report(
self.account100.id, trial_balance
@ -458,7 +272,7 @@ class TestTrialBalanceReport(AccountTestInvoicingCommon):
)
# Re Generate the trial balance line
res_data = self._get_report_lines(hierarchy_on="relation")
res_data = self._get_report_lines(show_hierarchy=True)
trial_balance = res_data["trial_balance"]
check_receivable_account = self.check_account_in_report(
self.account100.id, trial_balance
@ -497,7 +311,7 @@ class TestTrialBalanceReport(AccountTestInvoicingCommon):
)
# Re Generate the trial balance line
res_data = self._get_report_lines(hierarchy_on="relation")
res_data = self._get_report_lines(show_hierarchy=True)
trial_balance = res_data["trial_balance"]
check_receivable_account = self.check_account_in_report(
self.account100.id, trial_balance
@ -549,7 +363,7 @@ class TestTrialBalanceReport(AccountTestInvoicingCommon):
)
# Re Generate the trial balance line
res_data = self._get_report_lines(hierarchy_on="relation")
res_data = self._get_report_lines(show_hierarchy=True)
trial_balance = res_data["trial_balance"]
check_receivable_account = self.check_account_in_report(
self.account100.id, trial_balance
@ -715,7 +529,7 @@ class TestTrialBalanceReport(AccountTestInvoicingCommon):
"date_to": self.date_end,
"target_move": "posted",
"hide_account_at_0": False,
"hierarchy_on": "none",
"show_hierarchy": False,
"company_id": company.id,
"fy_start_date": self.fy_date_start,
}
@ -768,7 +582,7 @@ class TestTrialBalanceReport(AccountTestInvoicingCommon):
"date_to": self.date_end,
"target_move": "posted",
"hide_account_at_0": False,
"hierarchy_on": "none",
"show_hierarchy": False,
"company_id": company.id,
"fy_start_date": self.fy_date_start,
}
@ -822,7 +636,7 @@ class TestTrialBalanceReport(AccountTestInvoicingCommon):
"date_to": self.date_end,
"target_move": "posted",
"hide_account_at_0": False,
"hierarchy_on": "none",
"show_hierarchy": False,
"company_id": company.id,
"fy_start_date": self.fy_date_start,
}

View File

@ -26,19 +26,9 @@ class TrialBalanceReportWizard(models.TransientModel):
required=True,
default="posted",
)
hierarchy_on = fields.Selection(
[
("computed", "Computed Accounts"),
("relation", "Child Accounts"),
("none", "No hierarchy"),
],
required=True,
default="none",
help="""Computed Accounts: Use when the account group have codes
that represent prefixes of the actual accounts.\n
Child Accounts: Use when your account groups are hierarchical.\n
No hierarchy: Use to display just the accounts, without any grouping.
""",
show_hierarchy = fields.Boolean(
string="Show hierarchy",
help="Use when your account groups are hierarchical",
)
limit_hierarchy_level = fields.Boolean("Limit hierarchy levels")
show_hierarchy_level = fields.Integer("Hierarchy Levels to display", default=1)
@ -96,12 +86,12 @@ class TrialBalanceReportWizard(models.TransientModel):
lambda a: a.company_id == self.company_id
)
@api.constrains("hierarchy_on", "show_hierarchy_level")
@api.constrains("show_hierarchy", "show_hierarchy_level")
def _check_show_hierarchy_level(self):
for rec in self:
if rec.hierarchy_on != "none" and rec.show_hierarchy_level <= 0:
if rec.show_hierarchy and rec.show_hierarchy_level <= 0:
raise UserError(
_("The hierarchy level to filter on must be " "greater than 0.")
_("The hierarchy level to filter on must be greater than 0.")
)
@api.depends("date_from")
@ -261,7 +251,7 @@ class TrialBalanceReportWizard(models.TransientModel):
"partner_ids": self.partner_ids.ids or [],
"journal_ids": self.journal_ids.ids or [],
"fy_start_date": self.fy_start_date,
"hierarchy_on": self.hierarchy_on,
"show_hierarchy": self.show_hierarchy,
"limit_hierarchy_level": self.limit_hierarchy_level,
"show_hierarchy_level": self.show_hierarchy_level,
"hide_parent_hierarchy_level": self.hide_parent_hierarchy_level,

View File

@ -28,13 +28,12 @@
<field name="hide_account_at_0" />
<field name="show_partner_details" />
<field
name="hierarchy_on"
widget="radio"
name="show_hierarchy"
attrs="{'invisible':[('show_partner_details','=',True)]}"
/>
<field
name="limit_hierarchy_level"
attrs="{'invisible':['|', ('hierarchy_on','in',['none', 'computed']),('show_partner_details','=',True)]}"
attrs="{'invisible':['|', ('show_hierarchy','=',False),('show_partner_details','=',True)]}"
/>
<field
name="show_hierarchy_level"