diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 00000000000..09828639ff5 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1 @@ +git+https://github.com/stefanrijnhart/server-tools@19.0-mig-auditlog#subdirectory=auditlog diff --git a/test_auditlog/README.rst b/test_auditlog/README.rst new file mode 100644 index 00000000000..b1153530c2b --- /dev/null +++ b/test_auditlog/README.rst @@ -0,0 +1,78 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +=============== +Audit Log Tests +=============== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:ae0a5ae9d572925bd0b2083f4d0a20734e00d384183a843b0c04ccc202deb904 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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 + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github + :target: https://github.com/OCA/server-tools/tree/19.0/test_auditlog + :alt: OCA/server-tools +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/server-tools-19-0/server-tools-19-0-test_auditlog + :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/server-tools&target_branch=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module does not add any business or technical functionality. It +only contains tests for the ``auditlog`` module that depend on models +from modules that are not a dependency of ``auditlog`` itself. Don't +install this module on your database unless you want to run its tests. + +**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 +======= + +Contributors +------------ + +- Stefan Rijnhart stefan@opener.amsterdam + +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/server-tools `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/test_auditlog/__init__.py b/test_auditlog/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test_auditlog/__manifest__.py b/test_auditlog/__manifest__.py new file mode 100644 index 00000000000..900cb9b13c5 --- /dev/null +++ b/test_auditlog/__manifest__.py @@ -0,0 +1,16 @@ +# Copyright 2025 Opener B.V. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Audit Log Tests", + "summary": "Additional unit tests for Audit Log based on accounting models", + "version": "19.0.1.0.0", + "author": "Odoo Community Association (OCA)", + "license": "AGPL-3", + "website": "https://github.com/OCA/server-tools", + "category": "Tools", + "depends": ["account", "auditlog"], + "data": [], + "application": False, + "installable": True, +} diff --git a/test_auditlog/i18n/it.po b/test_auditlog/i18n/it.po new file mode 100644 index 00000000000..c0d5085374b --- /dev/null +++ b/test_auditlog/i18n/it.po @@ -0,0 +1,14 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" diff --git a/test_auditlog/i18n/test_auditlog.pot b/test_auditlog/i18n/test_auditlog.pot new file mode 100644 index 00000000000..aadee09bfed --- /dev/null +++ b/test_auditlog/i18n/test_auditlog.pot @@ -0,0 +1,13 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" diff --git a/test_auditlog/pyproject.toml b/test_auditlog/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/test_auditlog/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/test_auditlog/readme/CONTRIBUTORS.md b/test_auditlog/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..3a29acd033f --- /dev/null +++ b/test_auditlog/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +* Stefan Rijnhart diff --git a/test_auditlog/readme/DESCRIPTION.md b/test_auditlog/readme/DESCRIPTION.md new file mode 100644 index 00000000000..cfd2ee960d6 --- /dev/null +++ b/test_auditlog/readme/DESCRIPTION.md @@ -0,0 +1,4 @@ +This module does not add any business or technical functionality. It only +contains tests for the `auditlog` module that depend on models from modules +that are not a dependency of `auditlog` itself. Don't install this module on +your database unless you want to run its tests. diff --git a/test_auditlog/static/description/icon.png b/test_auditlog/static/description/icon.png new file mode 100644 index 00000000000..1dcc49c24f3 Binary files /dev/null and b/test_auditlog/static/description/icon.png differ diff --git a/test_auditlog/static/description/index.html b/test_auditlog/static/description/index.html new file mode 100644 index 00000000000..269eaf171ad --- /dev/null +++ b/test_auditlog/static/description/index.html @@ -0,0 +1,425 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Audit Log Tests

+ +

Beta License: AGPL-3 OCA/server-tools Translate me on Weblate Try me on Runboat

+

This module does not add any business or technical functionality. It +only contains tests for the auditlog module that depend on models +from modules that are not a dependency of auditlog itself. Don’t +install this module on your database unless you want to run its tests.

+

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

+
+

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/server-tools project on GitHub.

+

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

+
+
+
+
+ + diff --git a/test_auditlog/tests/__init__.py b/test_auditlog/tests/__init__.py new file mode 100644 index 00000000000..9678814e1ad --- /dev/null +++ b/test_auditlog/tests/__init__.py @@ -0,0 +1,3 @@ +from . import test_account_bank_statement_line +from . import test_account_move_reverse +from . import test_product_tax_multicompany diff --git a/test_auditlog/tests/test_account_bank_statement_line.py b/test_auditlog/tests/test_account_bank_statement_line.py new file mode 100644 index 00000000000..ecbccbef37d --- /dev/null +++ b/test_auditlog/tests/test_account_bank_statement_line.py @@ -0,0 +1,52 @@ +from odoo.tests import tagged + +from odoo.addons.account.tests.common import AccountTestInvoicingCommon +from odoo.addons.auditlog.tests.common import AuditLogRuleCommon + + +@tagged("post_install", "-at_install") +class TestAccountBankStatementLine(AccountTestInvoicingCommon, AuditLogRuleCommon): + def setUp(self): + super().setUp() + self.rule = self.env["auditlog.rule"].create( + { + "name": __name__, + "model_id": self.env.ref("account.model_account_move").id, + "log_read": True, + "log_create": True, + "log_write": True, + "log_unlink": True, + "log_type": "full", + } + ) + self.rule.set_to_confirmed() + + def test_create_statement_line(self): + """Statement line can be created with logging on journal entries enabled. + + Because we swap out the cache when fetching previous values during full + logging using the ThrowAwayCache, some values that are assumed by + compute methods (c.q. 'date' in account.bank.statement.line's + _compute_internal_index) might be missing. If a recompute of those fields + is inadvertently triggered when using the ThrowAwayCache, the missing + values will raise an exception (in this case: `AttributeError: 'bool' + object has no attribute 'strftime'`). This test verifies that the queued + recomputes are consistent with the values in the cache such that this + exception does not occur. + """ + partner = self.env["res.partner"].create({"name": "test"}) + stmt = self.env["account.bank.statement"].create( + {"journal_id": self.company_data["default_journal_bank"].id} + ) + line = self.env["account.bank.statement.line"].create( + { + "date": "2023-04-01", + "account_number": "NL45 TRIO 0198100000", + "amount": 5.75, + "journal_id": self.company_data["default_journal_bank"].id, + "payment_ref": "1234", + "partner_id": partner.id, + "statement_id": stmt.id, + }, + ) + line.flush_recordset() diff --git a/test_auditlog/tests/test_account_move_reverse.py b/test_auditlog/tests/test_account_move_reverse.py new file mode 100644 index 00000000000..bf9a8bef824 --- /dev/null +++ b/test_auditlog/tests/test_account_move_reverse.py @@ -0,0 +1,183 @@ +from odoo import fields +from odoo.tests import tagged + +from odoo.addons.account.tests.common import AccountTestInvoicingCommon +from odoo.addons.auditlog.tests.common import AuditLogRuleCommon + + +@tagged("post_install", "-at_install") +class TestAccountMoveReverse(AccountTestInvoicingCommon, AuditLogRuleCommon): + @classmethod + def setUpClass(cls): + # Class setup taken from account/tests/test_account_move_in_invoice.py + super().setUpClass() + + cls.other_currency = cls.setup_other_currency("EUR") + + cls.invoice = cls.init_invoice( + "in_invoice", products=cls.product_a + cls.product_b + ) + + cls.product_line_vals_1 = { + "name": "product_a", + "product_id": cls.product_a.id, + "account_id": cls.product_a.property_account_expense_id.id, + "partner_id": cls.partner_a.id, + "product_uom_id": cls.product_a.uom_id.id, + "quantity": 1.0, + "discount": 0.0, + "price_unit": 800.0, + "price_subtotal": 800.0, + "price_total": 920.0, + "tax_ids": cls.product_a.supplier_taxes_id.ids, + "tax_line_id": False, + "currency_id": cls.company_data["currency"].id, + "amount_currency": 800.0, + "debit": 800.0, + "credit": 0.0, + "date_maturity": False, + } + cls.product_line_vals_2 = { + "name": "product_b", + "product_id": cls.product_b.id, + "account_id": cls.product_b.property_account_expense_id.id, + "partner_id": cls.partner_a.id, + "product_uom_id": cls.product_b.uom_id.id, + "quantity": 1.0, + "discount": 0.0, + "price_unit": 160.0, + "price_subtotal": 160.0, + "price_total": 208.0, + "tax_ids": cls.product_b.supplier_taxes_id.ids, + "tax_line_id": False, + "currency_id": cls.company_data["currency"].id, + "amount_currency": 160.0, + "debit": 160.0, + "credit": 0.0, + "date_maturity": False, + } + cls.tax_line_vals_1 = { + "name": cls.tax_purchase_a.name, + "product_id": False, + "account_id": cls.company_data["default_account_tax_purchase"].id, + "partner_id": cls.partner_a.id, + "product_uom_id": False, + "quantity": False, + "discount": 0.0, + "price_unit": 0.0, + "price_subtotal": 0.0, + "price_total": 0.0, + "tax_ids": [], + "tax_line_id": cls.tax_purchase_a.id, + "currency_id": cls.company_data["currency"].id, + "amount_currency": 144.0, + "debit": 144.0, + "credit": 0.0, + "date_maturity": False, + } + cls.tax_line_vals_2 = { + "name": cls.tax_purchase_b.name, + "product_id": False, + "account_id": cls.company_data["default_account_tax_purchase"].id, + "partner_id": cls.partner_a.id, + "product_uom_id": False, + "quantity": False, + "discount": 0.0, + "price_unit": 0.0, + "price_subtotal": 0.0, + "price_total": 0.0, + "tax_ids": [], + "tax_line_id": cls.tax_purchase_b.id, + "currency_id": cls.company_data["currency"].id, + "amount_currency": 24.0, + "debit": 24.0, + "credit": 0.0, + "date_maturity": False, + } + cls.term_line_vals_1 = { + "name": False, + "product_id": False, + "account_id": cls.company_data["default_account_payable"].id, + "partner_id": cls.partner_a.id, + "product_uom_id": False, + "quantity": False, + "discount": 0.0, + "price_unit": 0.0, + "price_subtotal": 0.0, + "price_total": 0.0, + "tax_ids": [], + "tax_line_id": False, + "currency_id": cls.company_data["currency"].id, + "amount_currency": -1128.0, + "debit": 0.0, + "credit": 1128.0, + "date_maturity": fields.Date.from_string("2019-01-01"), + } + cls.move_vals = { + "partner_id": cls.partner_a.id, + "currency_id": cls.company_data["currency"].id, + "journal_id": cls.company_data["default_journal_purchase"].id, + "date": fields.Date.from_string("2019-01-01"), + "fiscal_position_id": False, + "payment_reference": False, + "invoice_payment_term_id": cls.pay_terms_a.id, + "amount_untaxed": 960.0, + "amount_tax": 168.0, + "amount_total": 1128.0, + } + cls.env.user.group_ids += cls.env.ref("uom.group_uom") + + def setUp(self): + super().setUp() + rules = self.env["auditlog.rule"].search([]) + rules.set_to_confirmed() + rules.unlink() + self.rule = self.env["auditlog.rule"].create( + { + "name": __name__, + "model_id": self.env.ref("account.model_account_move_line").id, + "log_read": True, + "log_create": True, + "log_write": True, + "log_unlink": True, + "log_type": "full", + } + ) + self.rule.set_to_confirmed() + + def test_in_invoice_stored_related_field(self): + """Stored related fields are computed properly""" + self.invoice.name = "TEST" + line = self.env["account.move.line"].create( + { + "display_type": "line_note", + "name": __name__, + "move_id": self.invoice.id, + } + ) + self.assertEqual(line.move_name, "TEST") + self.invoice.name = "TEST2" + self.assertEqual(line.move_name, "TEST2") + + def test_in_invoice_create_refund(self): + """Test creating a refund from a vendor bill. + + If auditlog does not carefully separate the main transaction cache from + the cache that it uses to fetch the logged values, this test would fail + on the loss of values related to the dynamic syncing of invoice and + journal entry lines. + """ + self.invoice.action_post() + + move_reversal = ( + self.env["account.move.reversal"] + .with_context(active_model="account.move", active_ids=self.invoice.ids) + .create( + { + "date": fields.Date.from_string("2019-02-01"), + "reason": "no reason", + "journal_id": self.invoice.journal_id.id, + } + ) + ) + move_reversal.refund_moves() diff --git a/test_auditlog/tests/test_product_tax_multicompany.py b/test_auditlog/tests/test_product_tax_multicompany.py new file mode 100644 index 00000000000..83ef204d4cd --- /dev/null +++ b/test_auditlog/tests/test_product_tax_multicompany.py @@ -0,0 +1,72 @@ +from odoo import fields +from odoo.tests import tagged + +from odoo.addons.account.tests.common import AccountTestInvoicingCommon +from odoo.addons.auditlog.tests.common import AuditLogRuleCommon + + +@tagged("post_install", "-at_install") +class TestProductTaxMulticompany(AccountTestInvoicingCommon, AuditLogRuleCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.company1 = cls.company_data["company"] + cls.tax1 = cls.company_data["default_tax_sale"] + cls.company_data_2 = cls.setup_other_company() + cls.company2 = cls.company_data_2["company"] + cls.tax2 = cls.company_data_2["default_tax_sale"] + cls.product_a.sudo().taxes_id = cls.tax1 + cls.tax2 + cls.env.user.company_ids = cls.company1 + + def setUp(self): + super().setUp() + rules = self.env["auditlog.rule"].search([]) + rules.set_to_draft() + rules.unlink() + self.rule = self.env["auditlog.rule"].create( + { + "name": __name__, + "model_id": self.env.ref("product.model_product_template").id, + "log_read": True, + "log_create": True, + "log_write": True, + "log_unlink": True, + "log_type": "full", + } + ) + self.rule.set_to_confirmed() + + def test_cache_accesserror(self): + """No AccessError occurs reading the product after writing taxes. + + The current user only has access to one of the taxes assigned to the + product. If auditlog does sanitize the cache after fetching old and + new values for the log lines, the other company's tax may remain in the + product's cache which will raise an AccessError when it is read. + """ + product = self.product_a.product_tmpl_id + product.write( + {"taxes_id": [fields.Command.unlink(self.tax1.id)]}, + ) + self.tax1.invalidate_model() + product.read(["taxes_id"]) + + def test_product_tax_multicompany_result(self): + """The value from the other company is preserved""" + product = self.product_a.product_tmpl_id + product.write( + {"taxes_id": [fields.Command.unlink(self.tax1.id)]}, + ) + self.assertFalse(product.taxes_id) + product.invalidate_recordset() + self.assertEqual(product.sudo().taxes_id, self.tax2) + + def test_product_tax_multicompany_log(self): + """The log covers the taxes across all companies.""" + product = self.product_a.product_tmpl_id + product.write( + {"taxes_id": [fields.Command.unlink(self.tax1.id)]}, + ) + log = self.env["auditlog.log"].search([], order="id desc", limit=1) + self.assertEqual(log.line_ids.old_value, f"[{self.tax1.id}, {self.tax2.id}]") + self.assertEqual(log.line_ids.new_value, f"[{self.tax2.id}]")