[FIX] base: traceback after enabling profiling

before this commit, if profiling is enabled in the db,
and on trying to validate a sale order, a traceback is
shown

* enable profiling
* confirm a quotation

traceback:
Failed to render QWeb template : <div style="margin: 0px;
padding: 0px;">
    <p style="margin: 0px; padding: 0px; font-size: 13px;">

introduced in: https://github.com/odoo/odoo/commit/016f26a9315c693bdeb894725898c2cf725d8989

here the options['ref'] is coming as the email template
body and it is failing on try to do int of options['ref']

after this commit, no traceback wont be shown on
confirming sale order, when profiling is enabled

closes odoo/odoo#138357

X-original-commit: 01548aff72b031389a7563948bb12bc3abb07bfc
Signed-off-by: Rémy Voet (ryv) <ryv@odoo.com>
This commit is contained in:
niyasraphy
2023-10-11 18:03:25 +00:00
committed by Rémy Voet (ryv)
parent 37381a5cf0
commit dd6cd1a82f
+11 -4
View File
@@ -366,6 +366,7 @@ structure.
"""
import base64
import contextlib
import fnmatch
import io
import logging
@@ -623,10 +624,16 @@ class IrQWeb(models.AbstractModel):
# generate the template functions and the root function name
def generate_functions():
code, options, def_name = self._generate_code(template)
profile_options = {
'ref': options.get('ref') and int(options['ref']) or None,
'ref_xml': options.get('ref_xml') and str(options['ref_xml']) or None,
} if self.env.context.get('profile') else None
if self.env.context.get('profile'):
ref_value = None
with contextlib.suppress(ValueError, TypeError):
ref_value = int(options.get('ref'))
profile_options = {
'ref': ref_value,
'ref_xml': options.get('ref_xml') and str(options['ref_xml']) or None,
}
else:
profile_options = None
code = '\n'.join([
"def generate_functions():",
" template_functions = {}",