Skip to content

Commit

Permalink
[UPD] tracking_manager: specific O2M fields notify
Browse files Browse the repository at this point in the history
In some case, we may have some unconventionals O2M like on ir.attachment. The O2M relation is done on res_id value.
This commit take them in consideration and avoid a traceback
  • Loading branch information
acsonefho committed Dec 10, 2024
1 parent 6e7e03d commit c3fe07a
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions tracking_manager/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,22 @@ def _tm_notify_owner(self, mode, changes=None):
)
for field_name, owner_field_name in self._tm_get_fields_to_notify():
owner = self[field_name]
data[owner._name][owner.id][owner_field_name].append(
{
"mode": mode,
"record": self.display_name,
"changes": changes,
}
)
model_name = target_id = False
if isinstance(owner, models.BaseModel):
model_name = owner._name
target_id = owner.id
# In case of specific O2M (ex: ir.attachment with res_id)
elif isinstance(owner, int) and hasattr(self, "res_model"):
model_name = self.res_model
target_id = owner

Check warning on line 59 in tracking_manager/models/models.py

View check run for this annotation

Codecov / codecov/patch

tracking_manager/models/models.py#L58-L59

Added lines #L58 - L59 were not covered by tests
if model_name and target_id:
data[model_name][target_id][owner_field_name].append(
{
"mode": mode,
"record": self.display_name,
"changes": changes,
}
)

def _tm_get_field_description(self, field_name):
return self._fields[field_name].get_description(self.env)["string"]
Expand Down

0 comments on commit c3fe07a

Please sign in to comment.