Skip to content
Snippets Groups Projects

migrate to v17

Merged Axel Prel requested to merge topic/17.0/RED-318 into branch/17.0
Files
5
+ 14
11
@@ -25,6 +25,7 @@
from odoo.exceptions import ValidationError
from ..redner import REDNER_API_PATH, Redner
from ..utils.mimetype import b64_to_extension
logger = logging.getLogger(__name__)
@@ -163,6 +164,11 @@
compute="_compute_template_data",
)
template_data_filename = fields.Char(
string="Libreoffice Template Filename",
readonly=True,
)
def import_from_redner(self):
tl_wizard = self.env["template.list.wizard"]
templates = self.list_external_templates()
@@ -210,7 +216,6 @@
if f in cached_template:
new_val = cached_template[f]
setattr(record, f, new_val)
print(f"f {f}, newvalue {new_val}")
except Exception as e:
logger.error("Failed to read redner template :%s", e)
return
@@ -223,8 +228,6 @@
attr = getattr(record, f)
if not attr:
new_val = cached_template[f]
if f == "template_data":
new_val = base64.b64encode(new_val)
setattr(record, f, new_val)
@api.depends("template_data")
@@ -240,7 +243,11 @@
cached_template = self.to_cache(record.id, template)
if "template_data" in cached_template:
new_val = cached_template["template_data"]
print(f"new val before encoding {new_val[:100]}")
encoded = base64.b64encode(new_val).decode('utf-8')
print(f"Setting template_data with: {encoded[:100]}...")
encoded = base64.b64encode(new_val).decode("utf-8")
ext = ".odt" # default extension
try:
ext = b64_to_extension(encoded)
except Exception as e:
logger.error("Failed to read extension from file:%s", e)
return
record.template_data = encoded
@@ -246,6 +253,5 @@
record.template_data = encoded
print(f"After assignment, template_data is: {record.template_data}")
print(f"template_data type: {type(record.template_data)}")
record.template_data_filename = "template" + ext
except Exception as e:
logger.error("Failed to read redner template :%s", e)
return
@@ -268,5 +274,4 @@
return new_templates
def to_cache(self, record_id, template):
print(f"template {template}")
cached_template = self.to_odoo_template(template)
@@ -272,5 +277,4 @@
cached_template = self.to_odoo_template(template)
print(f"cached template {cached_template}")
self.cache[record_id] = cached_template
return cached_template
@@ -359,7 +363,6 @@
return super().create(vals_list)
def write(self, vals):
print(f"writing with vals .. {vals}")
"""Overwrite write to update redner template"""
# We depend on the API for consistency here
# So raised error should not result with an updated template
Loading