diff --git a/account_financial_report_partner_name_history/README.rst b/account_financial_report_partner_name_history/README.rst new file mode 100644 index 000000000000..7f8bcd345c7f --- /dev/null +++ b/account_financial_report_partner_name_history/README.rst @@ -0,0 +1,79 @@ +=================================================== +Account Financial Reports with partner name history +=================================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:20a5677f41831297fb88dd7b6c9d061f5c6f747d015c8a8eb064c0ab0ae807eb + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/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 + :target: https://github.com/OCA/account-financial-reporting/tree/16.0/account_financial_report_partner_name_history + :alt: OCA/account-financial-reporting +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/account-financial-reporting-16-0/account-financial-reporting-16-0-account_financial_report_partner_name_history + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/account-financial-reporting&target_branch=16.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Show name of partners at the date of the invoice in General ledger +report. + +**Table of contents** + +.. contents:: + :local: + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Aion Tech + +Contributors +------------ + +- `Aion Tech `__: + + - Simone Rubino \\ + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/account-financial-reporting `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_financial_report_partner_name_history/__init__.py b/account_financial_report_partner_name_history/__init__.py new file mode 100644 index 000000000000..026c61c6c8aa --- /dev/null +++ b/account_financial_report_partner_name_history/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import reports diff --git a/account_financial_report_partner_name_history/__manifest__.py b/account_financial_report_partner_name_history/__manifest__.py new file mode 100644 index 000000000000..c8f94d108e80 --- /dev/null +++ b/account_financial_report_partner_name_history/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2024 Simone Rubino - Aion Tech +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Account Financial Reports with partner name history", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "category": "Reporting", + "summary": "OCA Financial Reports with partner name history", + "author": "Aion Tech, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/account-financial-reporting", + "depends": [ + "account_financial_report", + "account_move_partner_name_history", + ], +} diff --git a/account_financial_report_partner_name_history/readme/CONTRIBUTORS.md b/account_financial_report_partner_name_history/readme/CONTRIBUTORS.md new file mode 100644 index 000000000000..8ba08c6d187d --- /dev/null +++ b/account_financial_report_partner_name_history/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- [Aion Tech](https://aiontech.company/): + - Simone Rubino \\<\\> diff --git a/account_financial_report_partner_name_history/readme/DESCRIPTION.md b/account_financial_report_partner_name_history/readme/DESCRIPTION.md new file mode 100644 index 000000000000..179b92758be1 --- /dev/null +++ b/account_financial_report_partner_name_history/readme/DESCRIPTION.md @@ -0,0 +1 @@ +Show name of partners at the date of the invoice in General ledger report. diff --git a/account_financial_report_partner_name_history/reports/__init__.py b/account_financial_report_partner_name_history/reports/__init__.py new file mode 100644 index 000000000000..762d09a4dcc7 --- /dev/null +++ b/account_financial_report_partner_name_history/reports/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import general_ledger diff --git a/account_financial_report_partner_name_history/reports/general_ledger.py b/account_financial_report_partner_name_history/reports/general_ledger.py new file mode 100644 index 000000000000..92dcd69f8a54 --- /dev/null +++ b/account_financial_report_partner_name_history/reports/general_ledger.py @@ -0,0 +1,30 @@ +# Copyright 2024 Simone Rubino - Aion Tech +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class GeneralLedgerReport(models.AbstractModel): + _inherit = "report.account_financial_report.general_ledger" + + def _get_report_values(self, docids, data): + return super( + GeneralLedgerReport, + self.with_context( + use_partner_name_history=True, + ), + )._get_report_values(docids, data) + + @api.model + def _get_move_line_data(self, move_line): + move_line_data = super()._get_move_line_data(move_line) + # `partner_name` comes from the `display_name` used by `search_read`, + # it is rightfully not affected by history name + # because it is a stored field: + # a value stored in database should not depend on + # context or user that is seeing it. + # That is why it has to be overwritten + # with the move line's partner `name`. + move_line = self.env["account.move.line"].browse(move_line_data["id"]) + move_line_data["partner_name"] = move_line.partner_id.name + return move_line_data diff --git a/account_financial_report_partner_name_history/static/description/index.html b/account_financial_report_partner_name_history/static/description/index.html new file mode 100644 index 000000000000..096232c0bbb3 --- /dev/null +++ b/account_financial_report_partner_name_history/static/description/index.html @@ -0,0 +1,425 @@ + + + + + + +Account Financial Reports with partner name history + + + +
+

Account Financial Reports with partner name history

+ + +

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

+

Show name of partners at the date of the invoice in General ledger +report.

+

Table of contents

+ +
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Aion Tech
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/account-financial-reporting project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/account_financial_report_partner_name_history/tests/__init__.py b/account_financial_report_partner_name_history/tests/__init__.py new file mode 100644 index 000000000000..7dbb590ffebf --- /dev/null +++ b/account_financial_report_partner_name_history/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import test_general_ledger diff --git a/account_financial_report_partner_name_history/tests/test_general_ledger.py b/account_financial_report_partner_name_history/tests/test_general_ledger.py new file mode 100644 index 000000000000..68d949806062 --- /dev/null +++ b/account_financial_report_partner_name_history/tests/test_general_ledger.py @@ -0,0 +1,90 @@ +# Copyright 2024 Simone Rubino - Aion Tech +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +import datetime +import operator +from functools import reduce + +from dateutil.relativedelta import relativedelta + +from odoo.tests import Form, tagged + +from odoo.addons.account.tests.common import AccountTestInvoicingCommon +from odoo.addons.partner_name_history.tests.common import ( + _get_name_from_date, + _set_partner_name, +) + + +@tagged("post_install", "-at_install") +class TestGeneralLedger(AccountTestInvoicingCommon): + def _get_report_content(self, from_date, to_date): + wizard_form = Form(self.env["general.ledger.report.wizard"]) + wizard_form.date_from = from_date + wizard_form.date_to = to_date + wizard = wizard_form.save() + res = wizard.with_context( + discard_logo_check=True, + ).button_export_html() + + report_name = res["report_name"] + report_action = self.env["ir.actions.report"].search( + [ + ("report_type", "=", res["report_type"]), + ("report_name", "=", report_name), + ] + ) + content, _type = report_action._render_qweb_html(report_name, [], res["data"]) + return content + + def test_report(self): + """The report shows the old name for old invoices.""" + # Arrange + one_day = relativedelta(days=1) + partner = self.partner_a + original_partner_name = partner.name + change_dates = [ + datetime.date(2019, 1, 1), + datetime.date(2020, 1, 1), + ] + date_to_names = {date: _get_name_from_date(date) for date in change_dates} + for change_date, name in date_to_names.items(): + _set_partner_name( + partner, + name, + date=change_date, + ) + moves = reduce( + operator.ior, + [ + self.init_invoice( + "out_invoice", + partner=partner, + invoice_date=date, + amounts=[ + 100, + ], + post=True, + ) + for date in [ + change_dates[0] - one_day, + change_dates[0] + one_day, + change_dates[1] - one_day, + change_dates[1] + one_day, + ] + ], + ) + invoice_dates = moves.mapped("invoice_date") + + # Act + content = self._get_report_content( + min(invoice_dates), + max(invoice_dates), + ) + + # Assert + content = content.decode() + last_partner_name = partner.name + self.assertIn(original_partner_name, content) + self.assertIn(_get_name_from_date(change_dates[0]), content) + self.assertIn(last_partner_name, content) diff --git a/setup/account_financial_report_partner_name_history/odoo/addons/account_financial_report_partner_name_history b/setup/account_financial_report_partner_name_history/odoo/addons/account_financial_report_partner_name_history new file mode 120000 index 000000000000..ede78478d5ec --- /dev/null +++ b/setup/account_financial_report_partner_name_history/odoo/addons/account_financial_report_partner_name_history @@ -0,0 +1 @@ +../../../../account_financial_report_partner_name_history \ No newline at end of file diff --git a/setup/account_financial_report_partner_name_history/setup.py b/setup/account_financial_report_partner_name_history/setup.py new file mode 100644 index 000000000000..28c57bb64031 --- /dev/null +++ b/setup/account_financial_report_partner_name_history/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 000000000000..4ad8e0eceaa8 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1 @@ +odoo-test-helper