diff --git a/tracking_manager_domain/README.rst b/tracking_manager_domain/README.rst new file mode 100644 index 000000000..47a3cb43c --- /dev/null +++ b/tracking_manager_domain/README.rst @@ -0,0 +1,119 @@ +================ +Tracking Manager +================ + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:b0730db6a25a61791c804b38d6ae18e8f6934cafe024c1121aa23e9967e0b532 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/licence-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/17.0/tracking_manager + :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-17-0/server-tools-17-0-tracking_manager + :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=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to track all fields on every model that has a +chatter, including one2many and many2many ones. This excludes the +computed, readonly, related fields by default. In addition, line changes +of a one2many field can be tracked (e.g. product_uom_qty of an +order_line in a sale order). + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +- In setting > models: select a model +- Check "Active" under Custom Tracking. +- You have two options - 1) manually configure tracked fields one by + one, or 2) determine tracked fields based on a specific domain. +- For 1) manually configure tracked fields one by one + + - Click on Tracked Fields smart button, and select/unselect Custom + Tracking. + +- For 2) determine tracked fields based on a specific domain + + - Select "Automatic configuration", and then set the domain + accordingly. + - Click "Update" for the domain to take effect. + +|image| + +- Then select the fields to track + +|image1| + +.. |image| image:: https://raw.githubusercontent.com/OCA/server-tools/17.0/tracking_manager/static/description/model_view.png +.. |image1| image:: https://raw.githubusercontent.com/OCA/server-tools/17.0/tracking_manager/static/description/fields.png + +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 +======= + +Authors +------- + +* Akretion + +Contributors +------------ + +- Kévin Roche +- Sébastien BEAU + +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. + +.. |maintainer-Kev-Roche| image:: https://github.com/Kev-Roche.png?size=40px + :target: https://github.com/Kev-Roche + :alt: Kev-Roche +.. |maintainer-sebastienbeau| image:: https://github.com/sebastienbeau.png?size=40px + :target: https://github.com/sebastienbeau + :alt: sebastienbeau + +Current `maintainers `__: + +|maintainer-Kev-Roche| |maintainer-sebastienbeau| + +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/tracking_manager_domain/__init__.py b/tracking_manager_domain/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/tracking_manager_domain/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/tracking_manager_domain/__manifest__.py b/tracking_manager_domain/__manifest__.py new file mode 100644 index 000000000..fae87e7f1 --- /dev/null +++ b/tracking_manager_domain/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright 2025 glueckkanja AG () - Christopher Rogos +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Tracking Manager Domain", + "summary": "This module extends the tracking manager to" + " allow to define a domain on fields to track changes " + "only when certain conditions apply.", + "version": "17.0.1.0.0", + "category": "Tools", + "website": "https://github.com/OCA/server-tools", + "author": "Akretion, Odoo Community Association (OCA)", + "maintainers": ["CRogos"], + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": ["tracking_manager"], + "data": [ + "views/ir_model_fields.xml", + ], +} diff --git a/tracking_manager_domain/models/__init__.py b/tracking_manager_domain/models/__init__.py new file mode 100644 index 000000000..c0f19c503 --- /dev/null +++ b/tracking_manager_domain/models/__init__.py @@ -0,0 +1,2 @@ +from . import ir_model_fields +from . import models diff --git a/tracking_manager_domain/models/ir_model_fields.py b/tracking_manager_domain/models/ir_model_fields.py new file mode 100644 index 000000000..158debbae --- /dev/null +++ b/tracking_manager_domain/models/ir_model_fields.py @@ -0,0 +1,22 @@ +# Copyright 2025 glueckkanja AG () - Christopher Rogos +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class IrModelFields(models.Model): + _inherit = "ir.model.fields" + + tracking_domain = fields.Char( + help="Add a domain filter to only track changes when" + " certain condition apply on the parent record." + ) + + def write(self, vals): + if "tracking_domain" in vals: + self.env.registry.clear_cache() + self.check_access_rights("write") + custom_tracking_domain = vals.pop("tracking_domain") + self._write({"tracking_domain": custom_tracking_domain}) + self.invalidate_model(fnames=["tracking_domain"]) + return super().write(vals) diff --git a/tracking_manager_domain/models/models.py b/tracking_manager_domain/models/models.py new file mode 100644 index 000000000..79948c032 --- /dev/null +++ b/tracking_manager_domain/models/models.py @@ -0,0 +1,61 @@ +# Copyright 2025 glueckkanja AG () - Christopher Rogos +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + + +from ast import literal_eval +from collections import defaultdict + +from odoo import models, tools + + +class Base(models.AbstractModel): + _inherit = "base" + + @tools.ormcache() + def _all_tracking_domain_fields(self): + cr = self._cr + cr.execute( + """ + SELECT id, model, name, tracking_domain + FROM ir_model_fields + WHERE tracking_domain is not null + and tracking_domain != '' + and tracking_domain != '[]' + """ + ) + result = defaultdict(dict) + for row in cr.dictfetchall(): + result[row["model"]][row["name"]] = row + return result + + def _mail_track(self, tracked_fields, initial_values): + changes, tracking_value_ids = super()._mail_track( + tracked_fields, initial_values + ) + tracking_value_field_ids = [ + tracking_value_id[2]["field_id"] for tracking_value_id in tracking_value_ids + ] + if tracking_value_field_ids: + all_tracking_domain_fields = self._all_tracking_domain_fields()[self._name] + + if all_tracking_domain_fields: + # remove entries that are not matching the tracking_domain of the field + fields_to_remove = [] + for field_name in tracked_fields: + field_data = all_tracking_domain_fields.get(field_name, False) + if field_data and not self.filtered_domain( + literal_eval(field_data["tracking_domain"]) + ): + fields_to_remove.append(field_data["id"]) + res_changes = [] + res_tracking_value_ids = [] + # remove values from tracking result + for change, tracking_value_id in zip( + changes, tracking_value_ids, strict=True + ): + if tracking_value_id[2]["field_id"] not in fields_to_remove: + res_changes.append(change) + res_tracking_value_ids.append(tracking_value_id) + changes = res_changes + tracking_value_ids = res_tracking_value_ids + return changes, tracking_value_ids diff --git a/tracking_manager_domain/pyproject.toml b/tracking_manager_domain/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/tracking_manager_domain/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/tracking_manager_domain/readme/CONTRIBUTORS.md b/tracking_manager_domain/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..7d854509d --- /dev/null +++ b/tracking_manager_domain/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Christopher Rogos \<\> \ No newline at end of file diff --git a/tracking_manager_domain/readme/USAGE.md b/tracking_manager_domain/readme/USAGE.md new file mode 100644 index 000000000..494b053e9 --- /dev/null +++ b/tracking_manager_domain/readme/USAGE.md @@ -0,0 +1,3 @@ +- Add an optional domain on the field to limit tracking on certain condition. + +![fields](./static/description/fields.drawio.png) \ No newline at end of file diff --git a/tracking_manager_domain/static/description/fields.drawio.png b/tracking_manager_domain/static/description/fields.drawio.png new file mode 100644 index 000000000..070c704a7 Binary files /dev/null and b/tracking_manager_domain/static/description/fields.drawio.png differ diff --git a/tracking_manager_domain/static/description/icon.png b/tracking_manager_domain/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/tracking_manager_domain/static/description/icon.png differ diff --git a/tracking_manager_domain/static/description/index.html b/tracking_manager_domain/static/description/index.html new file mode 100644 index 000000000..a74a569a5 --- /dev/null +++ b/tracking_manager_domain/static/description/index.html @@ -0,0 +1,456 @@ + + + + + +Tracking Manager + + + +
+

Tracking Manager

+ + +

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

+

This module allows to track all fields on every model that has a +chatter, including one2many and many2many ones. This excludes the +computed, readonly, related fields by default. In addition, line changes +of a one2many field can be tracked (e.g. product_uom_qty of an +order_line in a sale order).

+

Table of contents

+ +
+

Usage

+
    +
  • In setting > models: select a model
  • +
  • Check “Active” under Custom Tracking.
  • +
  • You have two options - 1) manually configure tracked fields one by +one, or 2) determine tracked fields based on a specific domain.
  • +
  • For 1) manually configure tracked fields one by one
      +
    • Click on Tracked Fields smart button, and select/unselect Custom +Tracking.
    • +
    +
  • +
  • For 2) determine tracked fields based on a specific domain
      +
    • Select “Automatic configuration”, and then set the domain +accordingly.
    • +
    • Click “Update” for the domain to take effect.
    • +
    +
  • +
+

image

+
    +
  • Then select the fields to track
  • +
+

image1

+
+
+

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

+
+

Authors

+
    +
  • Akretion
  • +
+
+
+

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.

+

Current maintainers:

+

Kev-Roche sebastienbeau

+

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/tracking_manager_domain/tests/__init__.py b/tracking_manager_domain/tests/__init__.py new file mode 100644 index 000000000..483288c9a --- /dev/null +++ b/tracking_manager_domain/tests/__init__.py @@ -0,0 +1 @@ +from . import test_models diff --git a/tracking_manager_domain/tests/test_models.py b/tracking_manager_domain/tests/test_models.py new file mode 100644 index 000000000..9290461bd --- /dev/null +++ b/tracking_manager_domain/tests/test_models.py @@ -0,0 +1,50 @@ +# Copyright 2025 glueckkanja AG () - Christopher Rogos +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase + + +class TestMailTrack(TransactionCase): + def setUp(self): + super().setUp() + + self.Field = self.env["ir.model.fields"] + self.field_mobile = self.Field.search( + [("model", "=", "res.partner"), ("name", "=", "mobile")], limit=1 + ) + self.field_mobile.write({"tracking_domain": "[('is_company', '=', True)]"}) + + def test_mail_track(self): + # arrange + company = self.env.ref("base.res_partner_12") + tracked_fields = {"mobile": {"string": "Mobile", "type": "char"}} + initial_values = {"mobile": "1234"} + + # act + changes, tracking_value_ids = company._mail_track( + tracked_fields, initial_values + ) + + # assert + # Check if changes and tracking_value_ids are returned correctly + self.assertEqual(len(changes), 1) + self.assertEqual(len(tracking_value_ids), 1) + + # Check if the field is tracked correctly + tracking_value = tracking_value_ids[0][2] + self.assertEqual(tracking_value["field_id"], self.field_mobile.id) + + def test_mail_track_with_non_matching_domain(self): + # arrange + person = self.env.ref("base.partner_admin") + + tracked_fields = {"mobile": {"string": "Mobile", "type": "char"}} + initial_values = {"mobile": "1234"} + + # act + changes, tracking_value_ids = person._mail_track(tracked_fields, initial_values) + + # assert + # Check if changes and tracking_value_ids are empty when domain does not match + self.assertEqual(len(changes), 0) + self.assertEqual(len(tracking_value_ids), 0) diff --git a/tracking_manager_domain/views/ir_model_fields.xml b/tracking_manager_domain/views/ir_model_fields.xml new file mode 100644 index 000000000..c3d256bc8 --- /dev/null +++ b/tracking_manager_domain/views/ir_model_fields.xml @@ -0,0 +1,22 @@ + + + + ir.model.fields + + + + + + + + + +