Skip to content

[17.0][PATCH] tracking_manager_domain: support domains on one2many messages #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 17.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions tracking_manager_domain/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Base(models.AbstractModel):
_inherit = "base"

@tools.ormcache()
def _all_tracking_domain_fields(self):
def _tm_all_tracking_domain_fields(self):
cr = self._cr
cr.execute(
"""
Expand All @@ -28,6 +28,37 @@ def _all_tracking_domain_fields(self):
result[row["model"]][row["name"]] = row
return result

def _tm_post_message(self, data):
for model_name, model_data in data.items():
all_tracking_domain_fields = self._tm_all_tracking_domain_fields()[
model_name
]
# check if any fields with tracking_domain
if not all_tracking_domain_fields:
continue
record_to_remove = []
for record_id, messages_by_field in model_data.items():
fields_to_remove = []
record = self.env[model_name].browse(record_id)
if not record.exists():
# if a record have been modify and then deleted
# it's not need to track the change so skip it
continue
for field_name, _messages in messages_by_field.items():
field_data = all_tracking_domain_fields.get(field_name, False)
if field_data and not record.filtered_domain(
literal_eval(field_data["tracking_domain"])
):
fields_to_remove.append(field_name)
for field_name in fields_to_remove:
del model_data[record_id][field_name]
if not model_data[record_id]:
record_to_remove.append(record_id)

for record_id in record_to_remove:
del model_data[record_id]
return super()._tm_post_message(data)

def _mail_track(self, tracked_fields, initial_values):
changes, tracking_value_ids = super()._mail_track(
tracked_fields, initial_values
Expand All @@ -36,7 +67,9 @@ def _mail_track(self, tracked_fields, initial_values):
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]
all_tracking_domain_fields = self._tm_all_tracking_domain_fields()[
self._name
]

if all_tracking_domain_fields:
# remove entries that are not matching the tracking_domain of the field
Expand Down