تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
1005 أدوات العرض

auth_num = response_json["uuid"]

invoice_link =  f"https://report.feel.com.gt/ingfacereport/ingfacereport_documento?uuid={auth_num}"

message =  f"Watch invoice"


invoice.message_post(

​body=message,

​author_id=self.env.ref("base.partner_root").id,

​subject="Certified Invoice",

​message_type="comment",

​subtype_xmlid="mail.mt_comment"

)


My code is not interpreted correctly, as my message does post to the chatter, but the link is seen as plain text and not as a link.

 

الصورة الرمزية
إهمال

Did you solve this? I got the same problem.

أفضل إجابة

Hi,

Please Update Your code like this,


from markupsafe import Markup


auth_num = response_json["uuid"]

invoice_link = Markup('https://report.feel.com.gt/ingfacereport/ingfacereport_documento?uuid= %s') % (auth_num)

message = Markup('Watch invoice: <a href="{invoice_link}" target="_blank">%s</a>') % (invoice_link)


invoice.message_post(

    body=message,

    author_id=self.env.ref("base.partner_root").id,

    subject="Certified Invoice",

    message_type="comment",

    subtype_xmlid="mail.mt_comment"

)


Hope it helps.

الصورة الرمزية
إهمال
أفضل إجابة

For Odoo 18 at least, you could define a template and use it with message_post_with_source(). Pass on any values you want to render within that template in the render_values dict.

self.with_user(sender_user_id).message_post_with_source(
'your_module.your_message_template',
render_values={'self': self, 'message': message, 'title': title, 'message_type': message_type,
'message_tag': message_tag, 'data': json.dumps(data), 'url': url,
'some_result': some_result},
subtype_xmlid='mail.mt_note',
)


<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<template id="your_message_template">
<p>
<span t-attf-class="badge text-#{message_type}"
style="border: 1px solid; border-radius: 10px;"
t-esc="message_tag"/> <t t-if="title"><t t-esc="title"/></t><br t-if="message"/>
<t t-esc="message"/>
</p>
<blockquote>
<span class="fst-normal"><b>URL:</b> <t t-esc="url"/></span><br/>
<span class="fst-normal"><b>Request:</b> <br/><code t-esc="data"/></span><br/>
<b class="fst-normal">Response:</b> <br/><t t-esc="some_result"/>
</blockquote>
</template>
</odoo>


Results in:

Since it's a template, go wild

الصورة الرمزية
إهمال

Hey all, trying to do this directly in Studio Python...

snippet from my code
--------------------------

elif eachdoc.x_studio_action=="Create New":
_logger.info("Create needed on documents:")
_logger.info(eachdoc.name)

# Create Doc Link record
vals = {
'x_studio_related_part': record.product_tmpl_id.id,
'x_name': eachdoc.name,
}
new_doc_link = env['x_document_links'].create(vals)

record.message_post_with_source(
'mail.message_origin_link',
render_values={'self': record, 'origin': new_doc_link},
subtype_xmlid='mail.mt_note',
)

--------------------------

This creates the message just fine but of course uses the template language.

Can I define a template locally inside the code to override (mail.message_origin_link)?

Perhaps something like

mail.message_origin_link_custom = """
<p>
<span t-attf-class="badge text-#{message_type}"
style="border: 1px solid; border-radius: 10px;"
t-esc="message_tag"/> <t t-if="title"><t t-esc="title"/></t><br t-if="message"/>
<t t-esc="message"/>
</p>
<blockquote>
<span class="fst-normal"><b>URL:</b> <t t-esc="url"/></span><br/>
<span class="fst-normal"><b>Request:</b> <br/><code t-esc="data"/></span><br/>
<b class="fst-normal">Response:</b> <br/><t t-esc="some_result"/>
</blockquote>
"""