Maintainers
This module is maintained by the OCA.
- + + +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.