Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Converter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
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
Converter
Commits
463b620e40e7
Commit
463b620e40e7
authored
3 years ago
by
Houzefa Abbasbhay
Browse files
Options
Downloads
Patches
Plain Diff
MailTemplate converter: Allow multiple records
parent
4eba42946578
No related branches found
No related tags found
3 merge requests
!30
Merge 13.0 (13.0.3.0.2 ➔ 13.0.3.1.0)
,
!29
Code formatting, add license / docs / badges
,
!28
MailTemplate converter: Allow multiple records
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
NEWS.rst
+7
-0
7 additions, 0 deletions
NEWS.rst
__manifest__.py
+1
-1
1 addition, 1 deletion
__manifest__.py
mail_template.py
+14
-4
14 additions, 4 deletions
mail_template.py
tests/__init__.py
+1
-0
1 addition, 0 deletions
tests/__init__.py
tests/test_mail_template.py
+27
-0
27 additions, 0 deletions
tests/test_mail_template.py
with
50 additions
and
5 deletions
NEWS.rst
+
7
−
0
View file @
463b620e
...
@@ -2,6 +2,13 @@
...
@@ -2,6 +2,13 @@
History
History
*******
*******
13.0.3.1.0
==========
(port from 11.0.1.2.0)
* MailTemplate converter: Allow multiple records.
3.0.2
3.0.2
=====
=====
...
...
This diff is collapsed.
Click to expand it.
__manifest__.py
+
1
−
1
View file @
463b620e
...
@@ -21,7 +21,7 @@
...
@@ -21,7 +21,7 @@
"
name
"
:
"
Converter
"
,
"
name
"
:
"
Converter
"
,
"
license
"
:
"
AGPL-3
"
,
"
license
"
:
"
AGPL-3
"
,
"
summary
"
:
"
Convert odoo records to/from plain data structures.
"
,
"
summary
"
:
"
Convert odoo records to/from plain data structures.
"
,
"
version
"
:
"
13.0.3.
0.2
"
,
"
version
"
:
"
13.0.3.
1.0
"
,
"
category
"
:
"
Hidden
"
,
"
category
"
:
"
Hidden
"
,
"
author
"
:
"
XCG Consulting
"
,
"
author
"
:
"
XCG Consulting
"
,
"
website
"
:
"
https://odoo.consulting/
"
,
"
website
"
:
"
https://odoo.consulting/
"
,
...
...
This diff is collapsed.
Click to expand it.
mail_template.py
+
14
−
4
View file @
463b620e
...
@@ -7,8 +7,13 @@
...
@@ -7,8 +7,13 @@
class
MailTemplate
(
base
.
Converter
):
class
MailTemplate
(
base
.
Converter
):
"""
This converter wraps ``mail.template::_render_template``.
Multiple records are allowed but ``mail.template::render_template`` still
runs once per record; to accomodate, we provide ``ctx[
"
records
"
]``.
"""
def
__init__
(
self
,
template
:
str
,
post_eval
:
bool
=
False
):
def
__init__
(
self
,
template
:
str
,
post_eval
:
bool
=
False
):
self
.
template
=
template
self
.
template
=
template
self
.
post_eval
=
post_eval
self
.
post_eval
=
post_eval
def
odoo_to_message
(
def
odoo_to_message
(
...
@@ -10,7 +15,7 @@
...
@@ -10,7 +15,7 @@
def
__init__
(
self
,
template
:
str
,
post_eval
:
bool
=
False
):
def
__init__
(
self
,
template
:
str
,
post_eval
:
bool
=
False
):
self
.
template
=
template
self
.
template
=
template
self
.
post_eval
=
post_eval
self
.
post_eval
=
post_eval
def
odoo_to_message
(
def
odoo_to_message
(
self
,
instance
:
models
.
Model
,
ctx
:
Optional
[
Dict
]
=
None
self
,
records
:
models
.
Model
,
ctx
:
Optional
[
Dict
]
=
None
)
->
Any
:
)
->
Any
:
...
@@ -16,5 +21,8 @@
...
@@ -16,5 +21,8 @@
)
->
Any
:
)
->
Any
:
template
=
instance
.
env
[
"
mail.template
"
].
with_context
(
safe
=
True
)
multiple_records
=
len
(
records
)
>
1
value
=
template
.
_render_template
(
record_ids_or_id
=
records
.
ids
if
multiple_records
else
records
.
id
self
.
template
,
instance
.
_name
,
instance
.
id
value
=
(
records
.
env
[
"
mail.template
"
]
.
with_context
(
records
=
records
,
safe
=
True
)
.
_render_template
(
self
.
template
,
records
.
_name
,
record_ids_or_id
)
)
)
...
@@ -20,4 +28,6 @@
...
@@ -20,4 +28,6 @@
)
)
if
multiple_records
:
# render_template outputs indexed by record ID
value
=
value
[
records
[
0
].
id
]
if
self
.
post_eval
:
if
self
.
post_eval
:
value
=
ast
.
literal_eval
(
value
)
value
=
ast
.
literal_eval
(
value
)
return
value
return
value
This diff is collapsed.
Click to expand it.
tests/__init__.py
+
1
−
0
View file @
463b620e
...
@@ -2,5 +2,6 @@
...
@@ -2,5 +2,6 @@
from
.
import
test_converters
# noqa: F401
from
.
import
test_converters
# noqa: F401
from
.
import
test_field
# noqa: F401
from
.
import
test_field
# noqa: F401
from
.
import
test_ir_model
# noqa: F401
from
.
import
test_ir_model
# noqa: F401
from
.
import
test_mail_template
# noqa: F401
from
.
import
test_relation
# noqa: F401
from
.
import
test_relation
# noqa: F401
from
.
import
test_switch
# noqa: F401
from
.
import
test_switch
# noqa: F401
This diff is collapsed.
Click to expand it.
tests/test_mail_template.py
0 → 100644
+
27
−
0
View file @
463b620e
# TODO Copyright notice coming up in further commits.
from
odoo
import
tests
from
odoo.addons.converter
import
MailTemplate
class
Test
(
tests
.
TransactionCase
):
"""
Test converter that wraps ``mail.template::_render_template``.
"""
def
setUp
(
self
):
super
().
setUp
()
self
.
user_admin
=
self
.
env
.
ref
(
"
base.user_admin
"
)
self
.
user_demo
=
self
.
env
.
ref
(
"
base.user_demo
"
)
def
test_mail_template_odoo_to_message
(
self
):
converter
=
MailTemplate
(
"
hello ${ object.login }
"
)
converted
=
converter
.
odoo_to_message
(
self
.
user_demo
)
self
.
assertEqual
(
converted
,
"
hello demo
"
)
def
test_mail_template_odoo_to_message_multiple_records
(
self
):
converter
=
MailTemplate
(
"
hello
"
"
${
'
&
'
.join(ctx[
'
records
'
].sorted(
'
login
'
).mapped(
'
login
'
)) }
"
)
converted
=
converter
.
odoo_to_message
(
self
.
user_admin
|
self
.
user_demo
)
self
.
assertEqual
(
converted
,
"
hello admin & demo
"
)
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