Skip to content
Snippets Groups Projects

redner: sprint 2

Open Axel Prel requested to merge topic/18.0/RED-549 into branch/18.0
1 unresolved thread
1 file
+ 36
23
Compare changes
  • Side-by-side
  • Inline
@@ -22,7 +22,6 @@
from odoo.addons import converter
from odoo.exceptions import ValidationError # type: ignore[import-untyped]
from ..converter import ImageDataURL, ImageFile
from ..utils.sorting import parse_sorted_field, sortkey
FIELD = "field"
@@ -31,6 +30,8 @@
MAIL_TEMPLATE_DESERIALIZE = "mail_template+deserialize"
IMAGE_FILE = "image-file"
IMAGE_DATAURL = "image-data-url"
QR_CODE_FILE = "qr-code-file"
QR_CODE_DATAURL = "qr-code-data-url"
RELATION_2MANY = "relation-to-many"
RELATION_PATH = "relation-path"
@@ -40,8 +41,10 @@
(FIELD, "Field"),
(IMAGE_FILE, "Image file"),
(IMAGE_DATAURL, "Image data url"),
(QR_CODE_FILE, "QR Code file"),
(QR_CODE_DATAURL, "QR Code data url"),
(RELATION_2MANY, "Relation to many"),
(RELATION_PATH, "Relation Path"),
(CONSTANT, "Constant value"),
]
@@ -43,8 +46,9 @@
(RELATION_2MANY, "Relation to many"),
(RELATION_PATH, "Relation Path"),
(CONSTANT, "Constant value"),
]
DYNAMIC_PLACEHOLDER_ALLOWED_CONVERTERS = (
FIELD,
MAIL_TEMPLATE,
@@ -173,7 +177,7 @@
def _create_converter_by_type(self, sub):
"""Create appropriate converter based on type."""
converter_map = {
"mail_template": lambda: converter.MailTemplate(sub.value, False),
"mail_template+deserialize": lambda: converter.MailTemplate(
MAIL_TEMPLATE: lambda: converter.MailTemplate(sub.value, False),
MAIL_TEMPLATE_DESERIALIZE: lambda: converter.MailTemplate(
sub.value, True
),
@@ -178,7 +182,7 @@
sub.value, True
),
"constant": lambda: converter.Constant(sub.value),
"field": lambda: self._create_field_or_image_converter(sub, is_image=False),
"image-file": lambda: self._create_field_or_image_converter(
CONSTANT: lambda: converter.Constant(sub.value),
FIELD: lambda: self._create_field_or_image_converter(sub, is_image=False),
IMAGE_FILE: lambda: self._create_field_or_image_converter(
sub, is_image=True
),
@@ -183,8 +187,10 @@
sub, is_image=True
),
"image-data-url": lambda: ImageDataURL(sub.value),
"relation-to-many": lambda: self._create_relation_to_many_converter(sub),
"relation-path": lambda: converter.relation(
IMAGE_DATAURL: lambda: converter.ImageDataURL(sub.value),
QR_CODE_FILE: lambda: converter.QRCodeFile(sub.value),
QR_CODE_DATAURL: lambda: converter.QRCodeDataURL(sub.value),
RELATION_2MANY: lambda: self._create_relation_to_many_converter(sub),
RELATION_PATH: lambda: converter.relation(
sub.value, sub.get_children().build_converter()
),
}
@@ -193,7 +199,7 @@
def _create_field_or_image_converter(self, sub, is_image):
"""Create a converter for 'field' or 'image-file' types."""
path, name = sub.value.rsplit(".", 1) if "." in sub.value else (None, sub.value)
conv = ImageFile(name) if is_image else converter.Field(name)
conv = converter.ImageFile(name) if is_image else converter.Field(name)
return converter.relation(path.replace(".", "/"), conv) if path else conv
def _create_relation_to_many_converter(self, sub):
Loading