Skip to content
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

[17.0][IMP] tracking_manager: add field type html support #3175

Open
wants to merge 1 commit into
base: 17.0
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions tracking_manager/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
from . import ir_model
from . import ir_model_fields
from . import models
from . import mail_tracking_value
27 changes: 27 additions & 0 deletions tracking_manager/models/mail_tracking_value.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from odoo import api, models
from odoo.tools import html2plaintext


class MailTracking(models.Model):
_inherit = "mail.tracking.value"

@api.model
def _create_tracking_values(
self, initial_value, new_value, col_name, col_info, record
):
try:
return super()._create_tracking_values(
initial_value, new_value, col_name, col_info, record
)
except NotImplementedError:
if col_info["type"] == "html":
field = self.env["ir.model.fields"]._get(record._name, col_name)
values = {"field_id": field.id}
values.update(
{
"old_value_char": html2plaintext(initial_value) or "",
"new_value_char": html2plaintext(new_value) or "",
}
)
return values
raise

Check warning on line 27 in tracking_manager/models/mail_tracking_value.py

View check run for this annotation

Codecov / codecov/patch

tracking_manager/models/mail_tracking_value.py#L27

Added line #L27 was not covered by tests
1 change: 1 addition & 0 deletions tracking_manager/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import test_tracking_manager
from . import test_mail_tracking_value
22 changes: 22 additions & 0 deletions tracking_manager/tests/test_mail_tracking_value.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from odoo.tests.common import TransactionCase


class TestMailTracking(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.MailTracking = cls.env["mail.tracking.value"]

def test_create_tracking_values_html(self):
initial_value = "<p>Initial Value</p>"
new_value = "<p>New Value</p>"
col_name = "comment"
col_info = {"type": "html"}
record = self.env["res.partner"].create({"name": "Test Partner"})

values = self.MailTracking._create_tracking_values(
initial_value, new_value, col_name, col_info, record
)

self.assertEqual(values["old_value_char"], "Initial Value")
self.assertEqual(values["new_value_char"], "New Value")
Loading