Skip to content

Commit

Permalink
Merge pull request #1287 from OCA/15.0
Browse files Browse the repository at this point in the history
Syncing from upstream OCA/server-tools (15.0)
  • Loading branch information
bt-admin authored Sep 12, 2023
2 parents d1fc399 + 6505692 commit 922dc7e
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 30 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Available addons
addon | version | maintainers | summary
--- | --- | --- | ---
[attachment_unindex_content](attachment_unindex_content/) | 15.0.1.0.0 | [![moylop260](https://github.com/moylop260.png?size=30px)](https://github.com/moylop260) [![ebirbe](https://github.com/ebirbe.png?size=30px)](https://github.com/ebirbe) [![luisg123v](https://github.com/luisg123v.png?size=30px)](https://github.com/luisg123v) | Disable indexing of attachments
[auditlog](auditlog/) | 15.0.2.0.1 | | Audit Log
[auditlog](auditlog/) | 15.0.2.0.2 | | Audit Log
[auto_backup](auto_backup/) | 15.0.1.0.1 | | Backups database
[base_changeset](base_changeset/) | 15.0.1.0.1 | [![astirpe](https://github.com/astirpe.png?size=30px)](https://github.com/astirpe) | Track record changesets
[base_conditional_image](base_conditional_image/) | 15.0.1.0.0 | | This module extends the functionality to support conditional images
Expand Down
2 changes: 1 addition & 1 deletion auditlog/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Audit Log
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:c8d47cafe3b6eb77ccf7a6aa1a8414edff584a1d84fd8ed2922ba399d1eae0ee
!! source digest: sha256:0f44f8b1816ceb724c8ee7e4c19496e340734ca80c641bb0b1cadd874fad7195
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down
2 changes: 1 addition & 1 deletion auditlog/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{
"name": "Audit Log",
"version": "15.0.2.0.1",
"version": "15.0.2.0.2",
"author": "ABF OSIELL, Odoo Community Association (OCA)",
"license": "AGPL-3",
"website": "https://github.com/OCA/server-tools",
Expand Down
13 changes: 13 additions & 0 deletions auditlog/models/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ def create_full(self, vals_list, **kwargs):
def create_fast(self, vals_list, **kwargs):
self = self.with_context(auditlog_disabled=True)
rule_model = self.env["auditlog.rule"]
vals_list = rule_model._update_vals_list(vals_list)
vals_list2 = copy.deepcopy(vals_list)
new_records = create_fast.origin(self, vals_list, **kwargs)
new_values = {}
Expand Down Expand Up @@ -713,3 +714,15 @@ def unsubscribe(self):
if act_window:
act_window.unlink()
return self.write({"state": "draft"})

@api.model
def _update_vals_list(self, vals_list):
# Odoo supports empty recordset assignment (while it doesn't handle
# non-empty recordset ¯\_(ツ)_/¯ ), it could be an Odoo issue, but in
# the meanwhile we have to handle this case to avoid errors when using
# ``deepcopy`` to log data.
for vals in vals_list:
for fieldname, fieldvalue in vals.items():
if isinstance(fieldvalue, models.BaseModel) and not fieldvalue:
vals[fieldname] = False
return vals_list
2 changes: 1 addition & 1 deletion auditlog/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Audit Log</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:c8d47cafe3b6eb77ccf7a6aa1a8414edff584a1d84fd8ed2922ba399d1eae0ee
!! source digest: sha256:0f44f8b1816ceb724c8ee7e4c19496e340734ca80c641bb0b1cadd874fad7195
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-tools/tree/15.0/auditlog"><img alt="OCA/server-tools" src="https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-tools-15-0/server-tools-15-0-auditlog"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/server-tools&amp;target_branch=15.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows the administrator to log user operations performed on data
Expand Down
117 changes: 91 additions & 26 deletions auditlog/tests/test_auditlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,17 @@
class AuditlogCommon(object):
def test_LogCreation(self):
"""First test, caching some data."""

self.groups_rule.subscribe()

auditlog_log = self.env["auditlog.log"]
group = self.env["res.groups"].create({"name": "testgroup1"})
self.assertTrue(
auditlog_log.search(
self.assertEqual(
self.env["auditlog.log"].search_count(
[
("model_id", "=", self.groups_model_id),
("method", "=", "create"),
("res_id", "=", group.id),
]
).ensure_one()
)
group.write({"name": "Testgroup1"})
self.assertTrue(
auditlog_log.search(
[
("model_id", "=", self.groups_model_id),
("method", "=", "write"),
("res_id", "=", group.id),
]
).ensure_one()
)
group.unlink()
self.assertTrue(
auditlog_log.search(
[
("model_id", "=", self.groups_model_id),
("method", "=", "unlink"),
("res_id", "=", group.id),
]
).ensure_one()
),
1,
)

def test_LogCreation2(self):
Expand Down Expand Up @@ -193,6 +171,93 @@ def test_LogCreation6(self):
if self.groups_rule.capture_record:
self.assertTrue(len(log_record.line_ids) > 0)

def test_LogCreation7(self):
"""Seventh test: multi-create with different M2O values.
Check that creation goes as planned (no error coming from ``deepcopy``)
"""
self.groups_rule.subscribe()

auditlog_log = self.env["auditlog.log"]
cat = self.env["ir.module.category"].create({"name": "Test Category"})
groups_vals = [
{"name": "testgroup1"},
{"name": "testgroup3", "category_id": cat.browse()},
{"name": "testgroup2", "category_id": False},
{"name": "testgroup4", "category_id": cat.id},
]
groups = self.env["res.groups"].create(groups_vals)

# Ensure ``category_id`` field has the correct values
expected_ids = [False, False, False, cat.id]
self.assertEqual([g.category_id.id for g in groups], expected_ids)

# Ensure the correct number of logs have been created
logs = auditlog_log.search(
[
("model_id", "=", self.groups_model_id),
("method", "=", "create"),
("res_id", "in", groups.ids),
]
)
self.assertEqual(len(logs), len(groups))

def test_LogUpdate(self):
"""Tests write results with different M2O values."""
self.groups_rule.subscribe()
group = self.env["res.groups"].create({"name": "testgroup1"})
cat = self.env["ir.module.category"].create({"name": "Test Category"})
group.write(
{
"name": "Testgroup1",
"category_id": cat.browse(),
}
)
log1 = self.env["auditlog.log"].search(
[
("model_id", "=", self.groups_model_id),
("method", "=", "write"),
("res_id", "=", group.id),
]
)
self.assertEqual(len(log1), 1)
group.write({"name": "Testgroup2", "category_id": cat.id})
log2 = self.env["auditlog.log"].search(
[
("model_id", "=", self.groups_model_id),
("method", "=", "write"),
("res_id", "=", group.id),
("id", "not in", log1.ids),
]
)
self.assertEqual(len(log2), 1)
group.write({"name": "Testgroup3", "category_id": False})
log3 = self.env["auditlog.log"].search(
[
("model_id", "=", self.groups_model_id),
("method", "=", "write"),
("res_id", "=", group.id),
("id", "not in", (log1 + log2).ids),
]
)
self.assertEqual(len(log3), 1)

def test_LogDelete(self):
"""Tests unlink results"""
self.groups_rule.subscribe()
group = self.env["res.groups"].create({"name": "testgroup1"})
group.unlink()
self.assertEqual(
self.env["auditlog.log"].search_count(
[
("model_id", "=", self.groups_model_id),
("method", "=", "unlink"),
("res_id", "=", group.id),
]
),
1,
)


class TestAuditlogFull(TransactionCase, AuditlogCommon):
def setUp(self):
Expand Down

0 comments on commit 922dc7e

Please sign in to comment.