Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
4 Trả lời
13038 Lượt xem

I'm looking to change the following code, but I'm struggling to understand the "then" aspect of this "if" statement

${('' if object.partner_id and object.partner_id.email and object.partner_id.email==object.email else object.email|safe)}


What I want is:

If partner_id exists and partner_id.email exists

Use partner_id.email field (how do I do this??)

Else

Use object.email


Thanks

Ảnh đại diện
Huỷ bỏ

Try this,

${('' if object.partner_id and object.partner_id.email and object.partner_id.email==object.partner_id.email else object.email)}

Tác giả

Did not work @Niyas.

Error without exception. Probably due do sending an email without computed recipients.

then just try this also,

${('' if object.partner_id and object.partner_id.email and object.partner_id.email==object.partner_id.email else object.email|safe)}

Tác giả Câu trả lời hay nhất

I figured it out. These fields use jinga. It is an inline if statement:

The general syntax is <do something> if <something is true> else <do somethingelse>.

http://jinja.pocoo.org/docs/2.9/templates/#if-expression


My final code

${(object.partner_id.email if object.partner_id and object.partner_id.email else object.email|safe)}

 

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 10 24
1121
0
thg 8 23
2491
1
thg 12 22
2212
0
thg 7 21
2565
1
thg 4 25
1054