Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Redner Odoo Module
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package Registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
XCG
Odoo modules
Redner Odoo Module
Commits
98cccb0803de
Commit
98cccb0803de
authored
3 weeks ago
by
Axel Prel
Browse files
Options
Downloads
Patches
Plain Diff
remove converter.py and use converter module image converters
parent
c3797452927d
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
converter.py
+0
-67
0 additions, 67 deletions
converter.py
models/mail_template.py
+2
-3
2 additions, 3 deletions
models/mail_template.py
models/redner_substitution.py
+2
-3
2 additions, 3 deletions
models/redner_substitution.py
with
4 additions
and
73 deletions
converter.py
deleted
100644 → 0
+
0
−
67
View file @
c3797452
##############################################################################
#
# Redner Odoo module
# Copyright © 2016, 2025 XCG Consulting <https://xcg-consulting.fr>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import
base64
from
collections.abc
import
Mapping
from
typing
import
Any
from
odoo
import
models
# type: ignore[import-untyped]
from
odoo.addons.converter
import
Converter
from
odoo.tools.mimetypes
import
guess_mimetype
# type: ignore[import-untyped]
def
image
(
value
:
bytes
):
# get MIME type associated with the decoded_data.
image_base64
=
base64
.
b64decode
(
value
)
mimetype
=
guess_mimetype
(
image_base64
)
return
{
"
body
"
:
value
.
decode
(
"
ascii
"
),
"
mime-type
"
:
mimetype
}
class
ImageFile
(
Converter
):
def
__init__
(
self
,
fieldname
):
self
.
fieldname
=
fieldname
def
odoo_to_message
(
self
,
instance
:
models
.
Model
,
ctx
:
Mapping
|
None
=
None
)
->
Any
:
value
=
getattr
(
instance
,
self
.
fieldname
)
if
not
value
:
return
{}
return
image
(
value
)
class
ImageDataURL
(
Converter
):
def
__init__
(
self
,
fieldname
):
self
.
fieldname
=
fieldname
def
odoo_to_message
(
self
,
instance
:
models
.
Model
,
ctx
:
Mapping
|
None
=
None
)
->
Any
:
value
=
getattr
(
instance
,
self
.
fieldname
)
if
not
value
:
return
""
content
=
base64
.
b64decode
(
value
)
mimetype
=
guess_mimetype
(
content
)
return
"
data:{};base64,{}
"
.
format
(
mimetype
,
value
.
decode
(
"
ascii
"
))
This diff is collapsed.
Click to expand it.
models/mail_template.py
+
2
−
3
View file @
98cccb08
...
...
@@ -22,5 +22,6 @@
import
logging
from
odoo
import
_
,
fields
,
models
# type: ignore[import-untyped]
from
odoo.addons
import
converter
from
odoo.exceptions
import
ValidationError
# type: ignore[import-untyped]
...
...
@@ -25,7 +26,5 @@
from
odoo.exceptions
import
ValidationError
# type: ignore[import-untyped]
from
..converter
import
image
_logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -124,5 +123,5 @@
def
render_variable_hook
(
self
,
variables
):
"""
Override to add additional variables in mail
"
render template
"
func
"""
variables
.
update
({
"
image
"
:
lambda
value
:
image
(
value
)})
variables
.
update
({
"
image
"
:
lambda
value
:
converter
.
image
(
value
)})
return
super
().
render_variable_hook
(
variables
)
This diff is collapsed.
Click to expand it.
models/redner_substitution.py
+
2
−
3
View file @
98cccb08
...
...
@@ -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
"
...
...
@@ -161,7 +160,7 @@
path
,
name
=
sub
.
value
.
rsplit
(
"
.
"
,
1
)
else
:
path
,
name
=
None
,
sub
.
value
conv
=
ImageFile
(
name
)
conv
=
converter
.
ImageFile
(
name
)
if
path
:
conv
=
converter
.
relation
(
path
.
replace
(
"
.
"
,
"
/
"
),
conv
)
elif
sub
.
converter
==
"
image-data-url
"
:
...
...
@@ -165,7 +164,7 @@
if
path
:
conv
=
converter
.
relation
(
path
.
replace
(
"
.
"
,
"
/
"
),
conv
)
elif
sub
.
converter
==
"
image-data-url
"
:
conv
=
ImageDataURL
(
sub
.
value
)
conv
=
converter
.
ImageDataURL
(
sub
.
value
)
elif
sub
.
converter
==
"
relation-to-many
"
:
# Unpack the result of finding a field with its sort order into
# variable names.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment