Skip to content

Commit

Permalink
[FIX] base_import_pdf_by_template: Add message_log in the correct for…
Browse files Browse the repository at this point in the history
…mat (html)

TT50003
  • Loading branch information
victoralmau committed Oct 8, 2024
1 parent 7b5b02c commit 9e0478c
Showing 1 changed file with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import logging

from markupsafe import Markup

from odoo import _, api, fields, models
from odoo.exceptions import UserError
from odoo.tests import Form
Expand Down Expand Up @@ -99,7 +101,7 @@ class WizardBaseImportPdfUploadLine(models.TransientModel):
store=True,
)
extraction_mode = fields.Selection(related="template_id.extraction_mode")
log_text = fields.Text()
log_text = fields.Html()

@api.depends("attachment_id")
def _compute_template_id(self):
Expand Down Expand Up @@ -143,28 +145,30 @@ def _process_set_value_form(self, _form, field_name, value):
new_value_data = (
value.display_name if isinstance(value, models.Model) else value
)
if not self.log_text:
self.log_text = ""
self.log_text += _(
"""<p>%(item_name)s has been set with %(new_value)s instead of
%(old_value)s</p>"""
text = _(
"""%(item_name)s has been set with %(new_value)s instead of
%(old_value)s"""
) % {
"item_name": getattr(_form, "name"), # noqa: B009
"old_value": old_value_data,
"new_value": new_value_data,
}
if not self.log_text:
self.log_text = Markup("<p>{text}</p>").format(text=text)
else:
self.log_text += Markup("<p>{text}</p>").format(text=text)
else:
try:
setattr(_form, field_name, value)
except Exception:
if not self.log_text:
self.log_text = ""
self.log_text += _(
"Error to set %(field_name)s with value %(value)s"
) % {
text = _("Error to set %(field_name)s with value %(value)s") % {

Check warning on line 164 in base_import_pdf_by_template/wizards/wizard_base_import_pdf_upload.py

View check run for this annotation

Codecov / codecov/patch

base_import_pdf_by_template/wizards/wizard_base_import_pdf_upload.py#L164

Added line #L164 was not covered by tests
"field_name": field_name,
"value": value,
}
if not self.log_text:
self.log_text = Markup("<p>{text}</p>").format(text=text)

Check warning on line 169 in base_import_pdf_by_template/wizards/wizard_base_import_pdf_upload.py

View check run for this annotation

Codecov / codecov/patch

base_import_pdf_by_template/wizards/wizard_base_import_pdf_upload.py#L169

Added line #L169 was not covered by tests
else:
self.log_text += Markup("<p>{text}</p>").format(text=text)

Check warning on line 171 in base_import_pdf_by_template/wizards/wizard_base_import_pdf_upload.py

View check run for this annotation

Codecov / codecov/patch

base_import_pdf_by_template/wizards/wizard_base_import_pdf_upload.py#L171

Added line #L171 was not covered by tests

def _process_form(self):
"""Create record with Form() according to text."""
Expand Down Expand Up @@ -194,14 +198,14 @@ def _process_form(self):
try:
setattr(line_form, field_name, child_fixed_values[field_name])
except Exception:
if not self.log_text:
self.log_text = ""
self.log_text += _(
"Error to set %(field_name)s with value %(value)s"
) % {
text = _("Error to set %(field_name)s with value %(value)s") % {
"field_name": field_name,
"value": child_fixed_values[field_name],
}
if not self.log_text:
self.log_text = Markup("<p>{text}</p>").format(text=text)
else:
self.log_text += Markup("<p>{text}</p>").format(text=text)
# et the values of any line
for field_name in list(line.keys()):
self.with_context(
Expand Down

0 comments on commit 9e0478c

Please sign in to comment.