diff --git a/auditlog/README.rst b/auditlog/README.rst index 474e227..90cd624 100644 --- a/auditlog/README.rst +++ b/auditlog/README.rst @@ -7,7 +7,7 @@ Audit Log !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:0385a1c291a9a1ec310581bad8ffc88b9e349dd77279970782c84a79d199b268 + !! source digest: sha256:f28a63269e62794edbb3bcf4f78727dd623d0a973a1ac6055d88c7078668d842 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png diff --git a/auditlog/__manifest__.py b/auditlog/__manifest__.py index d3c12d6..923f1ae 100644 --- a/auditlog/__manifest__.py +++ b/auditlog/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Audit Log", - "version": "16.0.2.2.0", + "version": "16.0.2.2.2", "author": "ABF OSIELL, Odoo Community Association (OCA)", "license": "AGPL-3", "website": "https://github.com/OCA/server-tools", diff --git a/auditlog/models/rule.py b/auditlog/models/rule.py index 5ed7f42..fe8a490 100644 --- a/auditlog/models/rule.py +++ b/auditlog/models/rule.py @@ -264,7 +264,7 @@ def get_auditlog_fields(self, model): return list( n for n, f in model._fields.items() - if (not f.compute and not f.related) or f.store + if (not f.compute and not f.related) or f.store or f.company_dependent ) def _make_create(self): diff --git a/auditlog/static/description/index.html b/auditlog/static/description/index.html index 3211b77..d12f4b4 100644 --- a/auditlog/static/description/index.html +++ b/auditlog/static/description/index.html @@ -8,10 +8,11 @@ /* :Author: David Goodger (goodger@python.org) -:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $ +:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $ :Copyright: This stylesheet has been placed in the public domain. Default cascading style sheet for the HTML output of Docutils. +Despite the name, some widely supported CSS2 features are used. See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to customize this style sheet. @@ -274,7 +275,7 @@ margin-left: 2em ; margin-right: 2em } -pre.code .ln { color: grey; } /* line numbers */ +pre.code .ln { color: gray; } /* line numbers */ pre.code, code { background-color: #eeeeee } pre.code .comment, code .comment { color: #5C6576 } pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } @@ -300,7 +301,7 @@ span.pre { white-space: pre } -span.problematic { +span.problematic, pre.problematic { color: red } span.section-subtitle { @@ -366,7 +367,7 @@

Audit Log

!! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:0385a1c291a9a1ec310581bad8ffc88b9e349dd77279970782c84a79d199b268 +!! source digest: sha256:f28a63269e62794edbb3bcf4f78727dd623d0a973a1ac6055d88c7078668d842 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

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

This module allows the administrator to log user operations performed on data @@ -461,7 +462,9 @@

Other credits

Maintainers

This module is maintained by the OCA.

-Odoo Community Association + +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.

diff --git a/auditlog/tests/test_auditlog.py b/auditlog/tests/test_auditlog.py index 9ae1591..1ec143a 100644 --- a/auditlog/tests/test_auditlog.py +++ b/auditlog/tests/test_auditlog.py @@ -691,3 +691,87 @@ def test_02_AuditlogFull_field_group_write_log(self): ] ).ensure_one() self.assertTrue(write_log_record) + + +class AuditLogRuleTestPartnerCompanyDependentFields(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + # get Contact model id + cls.contact_model_id = ( + cls.env["ir.model"].search([("model", "=", "res.partner")]).id + ) + + # creating auditlog.rule + cls.auditlog_rule = ( + cls.env["auditlog.rule"] + .with_context(tracking_disable=True) + .create( + { + "name": "testrule 01", + "model_id": cls.contact_model_id, + "log_read": True, + "log_create": True, + "log_write": True, + "log_unlink": True, + "log_type": "full", + "capture_record": True, + } + ) + ) + + # Subscribe auditlog.rule + cls.auditlog_rule.subscribe() + + cls.auditlog_log = cls.env["auditlog.log"] + + # Creating new res.partner + cls.testpartner = ( + cls.env["res.partner"] + .with_context(tracking_disable=True) + .create( + { + "name": "testpartner", + "barcode": "0000", + } + ) + ) + + def test_01_AuditlogFull_company_dependent_field_create_log(self): + """Checks that the changes in a company dependent field are tracked""" + create_log_record = self.auditlog_log.search( + [ + ("model_id", "=", self.auditlog_rule.model_id.id), + ("method", "=", "create"), + ("res_id", "=", self.testpartner.id), + ] + ).ensure_one() + self.assertTrue(create_log_record) + field_names = create_log_record.line_ids.mapped("field_name") + + # Checking log lines created for barcode + self.assertTrue("barcode" in field_names) + + # Removing created log record + create_log_record.unlink() + + def test_02_AuditlogFull_company_dependent_field_write_log(self): + """Checks that the changes in a company dependent field are tracked""" + self.testpartner.with_context(tracking_disable=True).write( + { + "barcode": "0001", + } + ) + # Checking log is created for testpartner1 + write_log_record = self.auditlog_log.search( + [ + ("model_id", "=", self.auditlog_rule.model_id.id), + ("method", "=", "write"), + ("res_id", "=", self.testpartner.id), + ] + ).ensure_one() + self.assertTrue(write_log_record) + field_names = write_log_record.line_ids.mapped("field_name") + + # Checking log lines not created for phone + self.assertTrue("barcode" in field_names) diff --git a/auditlog/tests/test_multi_company.py b/auditlog/tests/test_multi_company.py index 404f395..1890259 100644 --- a/auditlog/tests/test_multi_company.py +++ b/auditlog/tests/test_multi_company.py @@ -1,10 +1,9 @@ from unittest.mock import patch from odoo.fields import Command +from odoo.models import BaseModel from odoo.tests.common import TransactionCase -from odoo.addons.base.models.res_users import Groups - class TestMultiCompany(TransactionCase): @classmethod @@ -78,10 +77,12 @@ def write(self, vals): present in the cache at this point, leading to the deletion of the value from the company that is inaccessible to the current user. """ - return super(Groups, self).write(vals) + return BaseModel.write(self, vals) # Do the write. - with patch.object(Groups, "write", side_effect=write, autospec=True): + with patch.object( + self.env["res.groups"].__class__, "write", side_effect=write, autospec=True + ): group_with_user.write({"users": [Command.set(self.user2.ids)]}) self.assertEqual(group_with_user.users, self.user2) # Ensure that the users of the other companies are still there.