diff --git a/account_financial_report/README.rst b/account_financial_report/README.rst index 6d7b94e1af7..3625bd066b7 100644 --- a/account_financial_report/README.rst +++ b/account_financial_report/README.rst @@ -1,7 +1,3 @@ -.. image:: https://odoo-community.org/readme-banner-image - :target: https://odoo-community.org/get-involved?utm_source=readme - :alt: Odoo Community Association - ========================= Account Financial Reports ========================= @@ -17,7 +13,7 @@ Account Financial Reports .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png :target: https://odoo-community.org/page/development-status :alt: Beta -.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--financial--reporting-lightgray.png?logo=github @@ -56,6 +52,10 @@ Invoicing / Settings / Invoicing / OCA Aged Report Configuration you will be abl dynamic intervals that will appear on the Aged Partner Balance. For further information, check CONFIGURE.rst +In the Trial Balance, the flag *Hide accounts with 0 end balance* +allows the user to hide accounts that +have ending balance equal to 0 in the selected period. + **Table of contents** .. contents:: @@ -195,6 +195,9 @@ Contributors * Lois Rilo * Saran Lim. * Omar Castiñeira +* `PyTech `_: + + * Simone Rubino Much of the work in this module was done at a sprint in Sorrento, Italy in April 2016. diff --git a/account_financial_report/readme/CONTRIBUTORS.rst b/account_financial_report/readme/CONTRIBUTORS.rst index 2e947469744..0d9d0525d8e 100644 --- a/account_financial_report/readme/CONTRIBUTORS.rst +++ b/account_financial_report/readme/CONTRIBUTORS.rst @@ -35,6 +35,9 @@ * Lois Rilo * Saran Lim. * Omar Castiñeira +* `PyTech `_: + + * Simone Rubino Much of the work in this module was done at a sprint in Sorrento, Italy in April 2016. diff --git a/account_financial_report/readme/DESCRIPTION.rst b/account_financial_report/readme/DESCRIPTION.rst index 04e865e6f71..8cbd1f64e68 100644 --- a/account_financial_report/readme/DESCRIPTION.rst +++ b/account_financial_report/readme/DESCRIPTION.rst @@ -21,3 +21,7 @@ currency balances are not available. Invoicing / Settings / Invoicing / OCA Aged Report Configuration you will be able to set dynamic intervals that will appear on the Aged Partner Balance. For further information, check CONFIGURE.rst + +In the Trial Balance, the flag *Hide accounts with 0 end balance* +allows the user to hide accounts that +have ending balance equal to 0 in the selected period. diff --git a/account_financial_report/report/trial_balance.py b/account_financial_report/report/trial_balance.py index 63addd73a84..3426bbadbf1 100644 --- a/account_financial_report/report/trial_balance.py +++ b/account_financial_report/report/trial_balance.py @@ -1,10 +1,11 @@ # © 2016 Julien Coux (Camptocamp) # © 2018 Forest and Biomass Romania SA # Copyright 2020 ForgeFlow S.L. (https://www.forgeflow.com) +# Copyright 2025 Simone Rubino - PyTech # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from odoo import _, api, models +from odoo import _, api, exceptions, models from odoo.exceptions import UserError from odoo.tools.float_utils import float_is_zero @@ -375,19 +376,55 @@ def _compute_partner_amount( total_amount[acc_id][key] = value return total_amount, partners_data - def _remove_accounts_at_cero(self, total_amount, show_partner_details, company): - def is_removable(d): - rounding = company.currency_id.rounding - return ( - float_is_zero(d["initial_balance"], precision_rounding=rounding) - and float_is_zero(d["credit"], precision_rounding=rounding) - and float_is_zero(d["debit"], precision_rounding=rounding) - and float_is_zero(d["ending_balance"], precision_rounding=rounding) + def _is_removable(self, company, total_account_data, amounts_at_0): + """Return True when all keys in `amounts_at_0` have value 0 in `total_account_data`. + + The precision of `company`'s currency is used to check the values. + """ + rounding = company.currency_id.rounding + is_to_remove = False + for amount_at_0 in amounts_at_0: + if not float_is_zero( + total_account_data[amount_at_0], + precision_rounding=rounding, + ): + is_to_remove = False + break + else: + # All amounts are 0 + is_to_remove = True + return is_to_remove + + def _get_amounts_at_0_to_remove_account_data(self, mode): + """Return the amounts that must be checked for removing account lines.""" + mode_to_amounts_at_0 = { + "all": [ + "initial_balance", + "credit", + "debit", + "ending_balance", + ], + "end": [ + "ending_balance", + ], + } + amounts_at_0 = mode_to_amounts_at_0.get(mode, []) + if not amounts_at_0: + raise exceptions.UserError( + _( + "Mode %(mode)s for removing account lines at 0 not supported", + mode=mode, + ) ) + return amounts_at_0 + def _remove_accounts_at_cero( + self, total_amount, show_partner_details, company, mode="all" + ): + amounts_at_0 = self._get_amounts_at_0_to_remove_account_data(mode=mode) accounts_to_remove = [] for acc_id, ta_data in total_amount.items(): - if is_removable(ta_data): + if self._is_removable(company, ta_data, amounts_at_0): accounts_to_remove.append(acc_id) elif show_partner_details: partner_to_remove = [] @@ -395,7 +432,9 @@ def is_removable(d): # If the show_partner_details option is checked, # the partner data is in the same account data dict # but with the partner id as the key - if isinstance(key, int) and is_removable(value): + if isinstance(key, int) and self._is_removable( + company, value, amounts_at_0 + ): partner_to_remove.append(key) for partner_id in partner_to_remove: del ta_data[partner_id] @@ -416,6 +455,7 @@ def _get_data( only_posted_moves, show_partner_details, hide_account_at_0, + hide_account_at_end_0, unaffected_earnings_account, fy_start_date, grouped_by, @@ -549,6 +589,12 @@ def _get_data( total_amount, tb_initial_prt, tb_period_prt, foreign_currency ) # Remove accounts a 0 from collections + if hide_account_at_end_0: + company = self.env["res.company"].browse(company_id) + self._remove_accounts_at_cero( + total_amount, show_partner_details, company, mode="end" + ) + if hide_account_at_0: company = self.env["res.company"].browse(company_id) self._remove_accounts_at_cero(total_amount, show_partner_details, company) @@ -872,6 +918,7 @@ def _get_report_values(self, docids, data): date_to = data["date_to"] date_from = data["date_from"] hide_account_at_0 = data["hide_account_at_0"] + hide_account_at_end_0 = data["hide_account_at_end_0"] show_hierarchy = data["show_hierarchy"] show_hierarchy_level = data["show_hierarchy_level"] foreign_currency = data["foreign_currency"] @@ -890,6 +937,7 @@ def _get_report_values(self, docids, data): only_posted_moves, show_partner_details, hide_account_at_0, + hide_account_at_end_0, unaffected_earnings_account, fy_start_date, grouped_by, @@ -969,6 +1017,7 @@ def _get_report_values(self, docids, data): "date_to": data["date_to"], "only_posted_moves": data["only_posted_moves"], "hide_account_at_0": data["hide_account_at_0"], + "hide_account_at_end_0": data["hide_account_at_end_0"], "show_partner_details": data["show_partner_details"], "limit_hierarchy_level": data["limit_hierarchy_level"], "show_hierarchy": show_hierarchy, diff --git a/account_financial_report/static/description/index.html b/account_financial_report/static/description/index.html index 7b9a958d369..270c78ed746 100644 --- a/account_financial_report/static/description/index.html +++ b/account_financial_report/static/description/index.html @@ -3,7 +3,7 @@ -README.rst +Account Financial Reports -
+
+

Account Financial Reports

- - -Odoo Community Association - -
-

Account Financial Reports

-

Beta License: AGPL-3 OCA/account-financial-reporting Translate me on Weblate Try me on Runboat

+

Beta License: AGPL-3 OCA/account-financial-reporting Translate me on Weblate Try me on Runboat

This module adds a set of financial reports. They are accessible under Invoicing / Reporting / OCA accounting reports.

-

Maintainers

+

Maintainers

This module is maintained by the OCA.

Odoo Community Association @@ -565,6 +567,5 @@

Maintainers

- diff --git a/account_financial_report/tests/test_trial_balance.py b/account_financial_report/tests/test_trial_balance.py index 5d3fd94d9cf..abfc9a738bc 100644 --- a/account_financial_report/tests/test_trial_balance.py +++ b/account_financial_report/tests/test_trial_balance.py @@ -1,9 +1,10 @@ # Author: Julien Coux # Copyright 2016 Camptocamp SA # Copyright 2020 ForgeFlow S.L. (https://www.forgeflow.com) +# Copyright 2025 Simone Rubino - PyTech # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from odoo.tests import tagged +from odoo.tests import Form, tagged from odoo.addons.account.tests.common import AccountTestInvoicingCommon @@ -714,3 +715,61 @@ def test_05_all_accounts_loaded(self): ] self.assertEqual(len(trial_balance_code_set), len(all_accounts_code_set)) self.assertTrue(trial_balance_code_set == all_accounts_code_set) + + def _move_amount(self, amount, from_account, to_account, move_date): + """Move `amount` from account `from_account` to account `to_account` on `move_date`.""" + entry_form = Form(self.env["account.move"]) + entry_form.date = move_date + with entry_form.line_ids.new() as line: + line.name = "Test" + line.account_id = from_account + line.credit = 100 + with entry_form.line_ids.new() as line: + line.name = "Test" + line.account_id = to_account + line.debit = 100 + entry = entry_form.save() + entry.action_post() + return entry + + def test_hide_account_at_end_0(self): + """When "Hide accounts with 0 end balance" is enabled, + accounts that have 0 end balance are hidden. + """ + # Arrange + trial_balance = self.env["trial.balance.report.wizard"].create( + { + "date_from": self.date_start, + "date_to": self.date_end, + "hide_account_at_end_0": True, + } + ) + start_date = trial_balance.date_from + end_date = trial_balance.date_to + report_interval = end_date - start_date + before_date = start_date - report_interval + in_date = start_date + report_interval / 2 + # One account has initial balance > 0 + # but end balance = 0 + only_initial_account = self.account100.copy() + self._move_amount(100, self.account100, only_initial_account, before_date) + self._move_amount(100, only_initial_account, self.account100, in_date) + # Another account has initial balance = 0 + # but end balance > 0 + only_end_account = self.account100.copy() + self._move_amount(100, self.account100, only_end_account, in_date) + + # Act + prepared_data = trial_balance._prepare_report_data() + report_values = self.env[ + "report.account_financial_report.trial_balance" + ]._get_report_values(trial_balance, prepared_data) + trial_balance = report_values["trial_balance"] + + # Assert + self.assertFalse( + self.check_account_in_report(only_initial_account.id, trial_balance) + ) + self.assertTrue( + self.check_account_in_report(only_end_account.id, trial_balance) + ) diff --git a/account_financial_report/wizard/trial_balance_wizard.py b/account_financial_report/wizard/trial_balance_wizard.py index ade7d0cb524..d8670b7c9e9 100644 --- a/account_financial_report/wizard/trial_balance_wizard.py +++ b/account_financial_report/wizard/trial_balance_wizard.py @@ -45,6 +45,11 @@ class TrialBalanceReportWizard(models.TransientModel): "not display accounts that have initial balance = " "debit = credit = end balance = 0", ) + hide_account_at_end_0 = fields.Boolean( + string="Hide accounts with 0 end balance", + help="When this option is enabled, the trial balance will " + "not display accounts that have end balance = 0", + ) receivable_accounts_only = fields.Boolean() payable_accounts_only = fields.Boolean() show_partner_details = fields.Boolean() @@ -255,6 +260,7 @@ def _prepare_report_data(self): "date_to": self.date_to, "only_posted_moves": self.target_move == "posted", "hide_account_at_0": self.hide_account_at_0, + "hide_account_at_end_0": self.hide_account_at_end_0, "foreign_currency": self.foreign_currency, "company_id": self.company_id.id, "account_ids": self.account_ids.ids or [], diff --git a/account_financial_report/wizard/trial_balance_wizard_view.xml b/account_financial_report/wizard/trial_balance_wizard_view.xml index 7b3293be64f..02f4bc2b429 100644 --- a/account_financial_report/wizard/trial_balance_wizard_view.xml +++ b/account_financial_report/wizard/trial_balance_wizard_view.xml @@ -39,6 +39,7 @@ groups="analytic.group_analytic_accounting" /> +