Skip to content

Commit ccc21a3

Browse files
[IMP] api_log_mail: add default mail template for exceptions
1 parent fa39936 commit ccc21a3

3 files changed

Lines changed: 51 additions & 0 deletions

File tree

api_log_mail/__manifest__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@
1616
"api_log",
1717
"mail",
1818
],
19+
"data": ["data/mail_template.xml"],
1920
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<!--
3+
~ Copyright 2025 Simone Rubino - PyTech
4+
~ License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
5+
-->
6+
<odoo noupdate="1">
7+
<record id="email_template_fastapi_error" model="mail.template">
8+
<field name="name">FastAPI: Error</field>
9+
<field name="model_id" ref="api_log.model_api_log" />
10+
<field
11+
name="email_from"
12+
>{{object.collection_ref.user_id.email or object.env.ref('base.partner_root').email}}</field>
13+
<field
14+
name="email_to"
15+
>{{object.collection_ref.company_id.scheduler_error_email_address}}</field>
16+
<field name="subject">Odoo FastAPI Error</field>
17+
<field name="auto_delete" eval="False" />
18+
<field name="body_html" type="html">
19+
<div>
20+
<t t-set="endpoint_name" t-value="object.collection_ref.name" />
21+
<t t-set="request_url" t-value="object.request_url" />
22+
<t t-set="request_method" t-value="object.request_method" />
23+
<t t-set="headers" t-value="object.request_headers" />
24+
<t t-set="exception" t-value="object.response_body" />
25+
<t t-set="exception_stack" t-value="object.stack_trace" />
26+
27+
<p>Error in FastAPI call</p>
28+
<p>FastAPI endpoint: <t t-out="endpoint_name" /></p>
29+
<p>Request: [<t t-out="request_method" />] <t t-out="request_url" /></p>
30+
<p>
31+
Headers:
32+
<ul>
33+
<li t-foreach="headers.items()" t-as="hd">
34+
<t t-out="hd[0]" />: <t t-out="hd[1]" />
35+
</li>
36+
</ul>
37+
</p>
38+
<p>
39+
Exception: <t t-out="exception" />
40+
</p>
41+
<p>
42+
Stack trace: <pre t-out="exception_stack" />
43+
</p>
44+
</div>
45+
</field>
46+
</record>
47+
</odoo>

api_log_mail/models/api_log_collection.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ class APILogCollection(models.AbstractModel):
1212
domain=[("model_id.model", "=", "api.log")],
1313
string="Error E-mail Template",
1414
help="An email based on this template will be sent when an error is logged.",
15+
default=lambda self: self.env.ref(
16+
"api_log_mail.email_template_fastapi_error", False
17+
),
1518
)
1619
api_log_mail_exception_activity_type_id = fields.Many2one(
1720
comodel_name="mail.activity.type",

0 commit comments

Comments
 (0)