Skip to content

Commit 7c8f106

Browse files
committed
Merge PR #3291 into 18.0
Signed-off-by pedrobaeza
2 parents 323ffa6 + 7217ae7 commit 7c8f106

File tree

17 files changed

+871
-0
lines changed

17 files changed

+871
-0
lines changed

tracking_manager_domain/README.rst

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
================
2+
Tracking Manager
3+
================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:b0730db6a25a61791c804b38d6ae18e8f6934cafe024c1121aa23e9967e0b532
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github
20+
:target: https://github.com/OCA/server-tools/tree/17.0/tracking_manager
21+
:alt: OCA/server-tools
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/server-tools-17-0/server-tools-17-0-tracking_manager
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-tools&target_branch=17.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
This module allows to track all fields on every model that has a
32+
chatter, including one2many and many2many ones. This excludes the
33+
computed, readonly, related fields by default. In addition, line changes
34+
of a one2many field can be tracked (e.g. product_uom_qty of an
35+
order_line in a sale order).
36+
37+
**Table of contents**
38+
39+
.. contents::
40+
:local:
41+
42+
Usage
43+
=====
44+
45+
- In setting > models: select a model
46+
- Check "Active" under Custom Tracking.
47+
- You have two options - 1) manually configure tracked fields one by
48+
one, or 2) determine tracked fields based on a specific domain.
49+
- For 1) manually configure tracked fields one by one
50+
51+
- Click on Tracked Fields smart button, and select/unselect Custom
52+
Tracking.
53+
54+
- For 2) determine tracked fields based on a specific domain
55+
56+
- Select "Automatic configuration", and then set the domain
57+
accordingly.
58+
- Click "Update" for the domain to take effect.
59+
60+
|image|
61+
62+
- Then select the fields to track
63+
64+
|image1|
65+
66+
.. |image| image:: https://raw.githubusercontent.com/OCA/server-tools/17.0/tracking_manager/static/description/model_view.png
67+
.. |image1| image:: https://raw.githubusercontent.com/OCA/server-tools/17.0/tracking_manager/static/description/fields.png
68+
69+
Bug Tracker
70+
===========
71+
72+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_.
73+
In case of trouble, please check there if your issue has already been reported.
74+
If you spotted it first, help us to smash it by providing a detailed and welcomed
75+
`feedback <https://github.com/OCA/server-tools/issues/new?body=module:%20tracking_manager%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
76+
77+
Do not contact contributors directly about support or help with technical issues.
78+
79+
Credits
80+
=======
81+
82+
Authors
83+
-------
84+
85+
* Akretion
86+
87+
Contributors
88+
------------
89+
90+
- Kévin Roche <kevin.roche@akretion.com>
91+
- Sébastien BEAU <sebastien.beau@akretion.com>
92+
93+
Maintainers
94+
-----------
95+
96+
This module is maintained by the OCA.
97+
98+
.. image:: https://odoo-community.org/logo.png
99+
:alt: Odoo Community Association
100+
:target: https://odoo-community.org
101+
102+
OCA, or the Odoo Community Association, is a nonprofit organization whose
103+
mission is to support the collaborative development of Odoo features and
104+
promote its widespread use.
105+
106+
.. |maintainer-Kev-Roche| image:: https://github.com/Kev-Roche.png?size=40px
107+
:target: https://github.com/Kev-Roche
108+
:alt: Kev-Roche
109+
.. |maintainer-sebastienbeau| image:: https://github.com/sebastienbeau.png?size=40px
110+
:target: https://github.com/sebastienbeau
111+
:alt: sebastienbeau
112+
113+
Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:
114+
115+
|maintainer-Kev-Roche| |maintainer-sebastienbeau|
116+
117+
This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/17.0/tracking_manager>`_ project on GitHub.
118+
119+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2025 glueckkanja AG (<https://www.glueckkanja.com>) - Christopher Rogos
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
{
5+
"name": "Tracking Manager Domain",
6+
"summary": "This module extends the tracking manager to"
7+
" allow to define a domain on fields to track changes "
8+
"only when certain conditions apply.",
9+
"version": "18.0.1.0.0",
10+
"category": "Tools",
11+
"website": "https://github.com/OCA/server-tools",
12+
"author": "Akretion, Odoo Community Association (OCA)",
13+
"maintainers": ["CRogos"],
14+
"license": "AGPL-3",
15+
"application": False,
16+
"installable": True,
17+
"depends": ["tracking_manager"],
18+
"data": [
19+
"views/ir_model_fields.xml",
20+
],
21+
}

tracking_manager_domain/i18n/it.po

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Translation of Odoo Server.
2+
# This file contains the translation of the following modules:
3+
# * tracking_manager_domain
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version: Odoo Server 17.0\n"
8+
"Report-Msgid-Bugs-To: \n"
9+
"PO-Revision-Date: 2025-04-08 06:44+0000\n"
10+
"Last-Translator: mymage <stefano.consolaro@mymage.it>\n"
11+
"Language-Team: none\n"
12+
"Language: it\n"
13+
"MIME-Version: 1.0\n"
14+
"Content-Type: text/plain; charset=UTF-8\n"
15+
"Content-Transfer-Encoding: \n"
16+
"Plural-Forms: nplurals=2; plural=n != 1;\n"
17+
"X-Generator: Weblate 5.10.4\n"
18+
19+
#. module: tracking_manager_domain
20+
#: model:ir.model.fields,help:tracking_manager_domain.field_ir_model_fields__tracking_domain
21+
msgid ""
22+
"Add a domain filter to only track changes when certain condition apply on "
23+
"the parent record."
24+
msgstr ""
25+
"Aggiungere un filtro di dominio per tracciare le modifiche solo quando si "
26+
"applicano determinate condizioni al record padre."
27+
28+
#. module: tracking_manager_domain
29+
#: model:ir.model,name:tracking_manager_domain.model_base
30+
msgid "Base"
31+
msgstr "Base"
32+
33+
#. module: tracking_manager_domain
34+
#: model:ir.model,name:tracking_manager_domain.model_ir_model_fields
35+
msgid "Fields"
36+
msgstr "Campi"
37+
38+
#. module: tracking_manager_domain
39+
#: model:ir.model.fields,field_description:tracking_manager_domain.field_ir_model_fields__tracking_domain
40+
msgid "Tracking Domain"
41+
msgstr "Dominio tracciamento"
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Translation of Odoo Server.
2+
# This file contains the translation of the following modules:
3+
# * tracking_manager_domain
4+
#
5+
msgid ""
6+
msgstr ""
7+
"Project-Id-Version: Odoo Server 17.0\n"
8+
"Report-Msgid-Bugs-To: \n"
9+
"Last-Translator: \n"
10+
"Language-Team: \n"
11+
"MIME-Version: 1.0\n"
12+
"Content-Type: text/plain; charset=UTF-8\n"
13+
"Content-Transfer-Encoding: \n"
14+
"Plural-Forms: \n"
15+
16+
#. module: tracking_manager_domain
17+
#: model:ir.model.fields,help:tracking_manager_domain.field_ir_model_fields__tracking_domain
18+
msgid ""
19+
"Add a domain filter to only track changes when certain condition apply on "
20+
"the parent record."
21+
msgstr ""
22+
23+
#. module: tracking_manager_domain
24+
#: model:ir.model,name:tracking_manager_domain.model_base
25+
msgid "Base"
26+
msgstr ""
27+
28+
#. module: tracking_manager_domain
29+
#: model:ir.model,name:tracking_manager_domain.model_ir_model_fields
30+
msgid "Fields"
31+
msgstr ""
32+
33+
#. module: tracking_manager_domain
34+
#: model:ir.model.fields,field_description:tracking_manager_domain.field_ir_model_fields__tracking_domain
35+
msgid "Tracking Domain"
36+
msgstr ""
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import ir_model_fields
2+
from . import models
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright 2025 glueckkanja AG (<https://www.glueckkanja.com>) - Christopher Rogos
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
from odoo import fields, models
5+
6+
7+
class IrModelFields(models.Model):
8+
_inherit = "ir.model.fields"
9+
10+
tracking_domain = fields.Char(
11+
help="Add a domain filter to only track changes when"
12+
" certain condition apply on the parent record."
13+
)
14+
15+
def write(self, vals):
16+
if "tracking_domain" in vals:
17+
self.env.registry.clear_cache()
18+
self.check_access("write")
19+
custom_tracking_domain = vals.pop("tracking_domain")
20+
self._write({"tracking_domain": custom_tracking_domain})
21+
self.invalidate_model(fnames=["tracking_domain"])
22+
return super().write(vals)
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Copyright 2025 glueckkanja AG (<https://www.glueckkanja.com>) - Christopher Rogos
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
5+
from ast import literal_eval
6+
from collections import defaultdict
7+
8+
from odoo import models, tools
9+
10+
11+
class Base(models.AbstractModel):
12+
_inherit = "base"
13+
14+
@tools.ormcache()
15+
def _tm_all_tracking_domain_fields(self):
16+
cr = self._cr
17+
cr.execute(
18+
"""
19+
SELECT id, model, name, tracking_domain
20+
FROM ir_model_fields
21+
WHERE tracking_domain is not null
22+
and tracking_domain != ''
23+
and tracking_domain != '[]'
24+
"""
25+
)
26+
result = defaultdict(dict)
27+
for row in cr.dictfetchall():
28+
result[row["model"]][row["name"]] = row
29+
return result
30+
31+
def _tm_post_message(self, data):
32+
for model_name, model_data in data.items():
33+
all_tracking_domain_fields = self._tm_all_tracking_domain_fields()[
34+
model_name
35+
]
36+
# check if any fields with tracking_domain
37+
if not all_tracking_domain_fields:
38+
continue
39+
record_to_remove = []
40+
for record_id, messages_by_field in model_data.items():
41+
fields_to_remove = []
42+
record = self.env[model_name].browse(record_id)
43+
if not record.exists():
44+
# if a record have been modify and then deleted
45+
# it's not need to track the change so skip it
46+
continue
47+
for field_name, _messages in messages_by_field.items():
48+
field_data = all_tracking_domain_fields.get(field_name, False)
49+
if field_data and not record.filtered_domain(
50+
literal_eval(field_data["tracking_domain"])
51+
):
52+
fields_to_remove.append(field_name)
53+
for field_name in fields_to_remove:
54+
del model_data[record_id][field_name]
55+
if not model_data[record_id]:
56+
record_to_remove.append(record_id)
57+
58+
for record_id in record_to_remove:
59+
del model_data[record_id]
60+
return super()._tm_post_message(data)
61+
62+
def _mail_track(self, tracked_fields, initial_values):
63+
changes, tracking_value_ids = super()._mail_track(
64+
tracked_fields, initial_values
65+
)
66+
tracking_value_field_ids = [
67+
tracking_value_id[2]["field_id"] for tracking_value_id in tracking_value_ids
68+
]
69+
if tracking_value_field_ids:
70+
all_tracking_domain_fields = self._tm_all_tracking_domain_fields()[
71+
self._name
72+
]
73+
74+
if all_tracking_domain_fields:
75+
# remove entries that are not matching the tracking_domain of the field
76+
fields_to_remove = []
77+
for field_name in tracked_fields:
78+
field_data = all_tracking_domain_fields.get(field_name, False)
79+
if field_data and not self.filtered_domain(
80+
literal_eval(field_data["tracking_domain"])
81+
):
82+
fields_to_remove.append(field_data["id"])
83+
res_changes = []
84+
res_tracking_value_ids = []
85+
# remove values from tracking result
86+
for change, tracking_value_id in zip(
87+
changes, tracking_value_ids, strict=True
88+
):
89+
if tracking_value_id[2]["field_id"] not in fields_to_remove:
90+
res_changes.append(change)
91+
res_tracking_value_ids.append(tracking_value_id)
92+
changes = res_changes
93+
tracking_value_ids = res_tracking_value_ids
94+
return changes, tracking_value_ids
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["whool"]
3+
build-backend = "whool.buildapi"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Christopher Rogos \<<crogos@gmail.com>\>

0 commit comments

Comments
 (0)