Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][IMP]helpdesk_mgmt: simplify email templates #644

Open
wants to merge 3 commits into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions helpdesk_mgmt/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ Contributors
* Marcel Savegnago
* Eduardo Aparício

* `TAKOBI <https://takobi.online>`_:

* Lorenzo Battistini

* `Obertix <https://www.obertix.net>`_:

* Vicent Cubells
Expand Down
216 changes: 29 additions & 187 deletions helpdesk_mgmt/data/helpdesk_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,105 +32,33 @@
<field name="model_id" ref="helpdesk_mgmt.model_helpdesk_ticket" />
<field name="email_from">{{object.company_id.partner_id.email}}</field>
<field
name="email_cc"
name="email_to"
>{{not object.partner_id and object.partner_email or ''}},</field>
<field name="subject">The ticket {{object.number}} has been closed.</field>
<field name="partner_to">{{object.partner_id.id}}</field>
<field name="auto_delete" eval="False" />
<field name="lang">{{object.partner_id.lang}}</field>
<field name="body_html" type="html">
<table
border="0"
width="100%"
cellpadding="0"
bgcolor="#ededed"
style="padding: 20px; background-color: #ededed; border-collapse:separate;"
>
<tbody>
<!-- HEADER -->
<tr>
<td align="center" style="min-width: 590px;">
<table
width="590"
border="0"
cellpadding="0"
bgcolor="#875A7B"
style="min-width: 590px; background-color: rgb(135,90,123); padding: 20px; border-collapse:separate;"
>
<tr>
<td valign="middle" align="right">
<img
t-att-src="'/logo.png?company=%s' % object.company_id.id"
style="padding: 0px; margin: 0px; height: auto; width: 80px;"
t-att-alt="'%s' % object.company_id.name"
/>
</td>
</tr>
</table>
</td>
</tr>
<!-- CONTENT -->
<tr>
<td align="center" style="min-width: 590px;">
<table
width="590"
border="0"
cellpadding="0"
bgcolor="#ffffff"
style="min-width: 590px; background-color: rgb(255, 255, 255); padding: 20px; border-collapse:separate;"
>
<tbody>
<td
valign="top"
style="font-family:Arial,Helvetica,sans-serif; color: #555; font-size: 14px;"
>
<p>Hello <t t-out="object.user_id.name" />,</p>
<p>The ticket "<t
t-out="object.display_name"
/>" has been closed.</p>
</td>
</tbody>
</table>
</td>
</tr>
<!-- FOOTER -->
<tr>
<td align="center" style="min-width: 590px;">
<table
width="590"
border="0"
cellpadding="0"
bgcolor="#875A7B"
style="min-width: 590px; background-color: rgb(135,90,123); padding: 20px; border-collapse:separate;"
>
<tr>
<td
valign="middle"
align="left"
style="color: #fff; padding-top: 10px; padding-bottom: 10px; font-size: 12px;"
>
<t t-out="object.company_id.phone" />
</td>
<td
valign="middle"
align="left"
style="color: #fff; padding-top: 10px; padding-bottom: 10px; font-size: 12px;"
>
<t t-out="object.company_id.email" />
</td>
<td
valign="middle"
align="left"
style="color: #fff; padding-top: 10px; padding-bottom: 10px; font-size: 12px;"
>
<t t-out="object.company_id.website" />
</td>
</tr>
</table>
</td>
</tr>
</tbody>
</table>
<div>
<p>Hello <t
t-out="object.partner_id.name or object.partner_name or ''"
/>,</p>
<p>The ticket "<t
t-out="object.display_name or 'n/a'"
/>" has been closed.</p>
<t t-if="object.partner_can_access()">
<div style="margin: 16px 0px 16px 0px;">
<a
t-attf-href="{{object.get_access_link()}}"
style="background-color: #875A7B; padding: 8px 16px 8px 16px; text-decoration: none; color: #fff; border-radius: 5px; font-size:13px;"
>
View Ticket
</a>
</div>
</t>
Thank you,<br /><br />
<t t-out="user.signature or ''" /><br />
</div>
</field>
</record>
<record id="changed_stage_template" model="mail.template">
Expand All @@ -147,100 +75,14 @@
<field name="auto_delete" eval="False" />
<field name="lang">{{object.partner_id.lang}}</field>
<field name="body_html" type="html">
<table
border="0"
width="100%"
cellpadding="0"
bgcolor="#ededed"
style="padding: 20px; background-color: #ededed; border-collapse:separate;"
>
<tbody>
<!-- HEADER -->
<tr>
<td align="center" style="min-width: 590px;">
<table
width="590"
border="0"
cellpadding="0"
bgcolor="#875A7B"
style="min-width: 590px; background-color: rgb(135,90,123); padding: 20px; border-collapse:separate;"
>
<tr>
<td valign="middle" align="right">
<img
t-att-src="'/logo.png?company=%s' % object.company_id.id"
style="padding: 0px; margin: 0px; height: auto; width: 80px;"
t-att-alt="'%s' % object.company_id.name"
/>
</td>
</tr>
</table>
</td>
</tr>
<!-- CONTENT -->
<tr>
<td align="center" style="min-width: 590px;">
<table
width="590"
border="0"
cellpadding="0"
bgcolor="#ffffff"
style="min-width: 590px; background-color: rgb(255, 255, 255); padding: 20px; border-collapse:separate;"
>
<tbody>
<td
valign="top"
style="font-family:Arial,Helvetica,sans-serif; color: #555; font-size: 14px;"
>
<p>Hello <t t-out="object.user_id.name" />,</p>
<p>The ticket "<t
t-out="object.display_name"
/>" stage has changed to <t
t-out="object.stage_id.name"
/>.</p>
</td>
</tbody>
</table>
</td>
</tr>
<!-- FOOTER -->
<tr>
<td align="center" style="min-width: 590px;">
<table
width="590"
border="0"
cellpadding="0"
bgcolor="#875A7B"
style="min-width: 590px; background-color: rgb(135,90,123); padding: 20px; border-collapse:separate;"
>
<tr>
<td
valign="middle"
align="left"
style="color: #fff; padding-top: 10px; padding-bottom: 10px; font-size: 12px;"
>
<t t-out="object.company_id.phone" />
</td>
<td
valign="middle"
align="left"
style="color: #fff; padding-top: 10px; padding-bottom: 10px; font-size: 12px;"
>
<t t-out="object.company_id.email" />
</td>
<td
valign="middle"
align="left"
style="color: #fff; padding-top: 10px; padding-bottom: 10px; font-size: 12px;"
>
<t t-out="object.company_id.website" />
</td>
</tr>
</table>
</td>
</tr>
</tbody>
</table>
<div>
<p>Hello <t
t-out="object.partner_id.name or object.partner_name or ''"
/>,</p>
<p>The ticket "<t
t.out="object.display_name"
/>" stage has changed to <t t-out="object.stage_id.name" />.</p>
</div>
</field>
</record>
<!-- Sequence -->
Expand Down
56 changes: 47 additions & 9 deletions helpdesk_mgmt/models/helpdesk_ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,15 @@ def _onchange_partner_id(self):
def _creation_subtype(self):
return self.env.ref("helpdesk_mgmt.hlp_tck_created")

def _message_auto_subscribe_followers(self, updated_values, default_subtype_ids):
"""Auto-subscribe ticket partner."""
result = super()._message_auto_subscribe_followers(
updated_values, default_subtype_ids
)
if updated_values.get("partner_id"):
result.append((self.partner_id.id, default_subtype_ids, False))
return result

@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
Expand Down Expand Up @@ -209,12 +218,6 @@ def _prepare_ticket_number(self, values):
seq = seq.with_company(values["company_id"])
return seq.next_by_code("helpdesk.ticket.sequence") or "/"

def _compute_access_url(self):
res = super()._compute_access_url()
for item in self:
item.access_url = "/my/ticket/%s" % (item.id)
return res

# ---------------------------------------------------
# Mail gateway
# ---------------------------------------------------
Expand Down Expand Up @@ -251,10 +254,8 @@ def message_new(self, msg, custom_values=None):
"partner_id": msg.get("author_id"),
}
defaults.update(custom_values)

# Write default values coming from msg
ticket = super().message_new(msg, custom_values=defaults)

# Use mail gateway tools to search for partners to subscribe
email_list = tools.email_split(
(msg.get("to") or "") + "," + (msg.get("cc") or "")
Expand All @@ -267,7 +268,6 @@ def message_new(self, msg, custom_values=None):
if p
]
ticket.message_subscribe(partner_ids)

return ticket

def message_update(self, msg, update_vals=None):
Expand Down Expand Up @@ -315,3 +315,41 @@ def _notify_get_reply_to(self, default=None):
super(HelpdeskTicket, leftover)._notify_get_reply_to(default=default)
)
return res

# ---------------------------------------------------
# Portal
# ---------------------------------------------------

def _compute_access_url(self):
res = super(HelpdeskTicket, self)._compute_access_url()
for ticket in self:
ticket.access_url = "/my/ticket/%s" % (ticket.id)
return res

def _notify_get_recipients_groups(self, msg_vals=None):
groups = super(HelpdeskTicket, self)._notify_get_recipients_groups(
msg_vals=msg_vals
)
self.ensure_one()
for group_name, _group_method, group_data in groups:
if group_name == "portal":
group_data["has_button_access"] = True
return groups

def partner_can_access(self):
if not self.partner_id:
return False
user = (
self.env["res.users"]
.sudo()
.search([("partner_id", "=", self.partner_id.id)])
)
if not user or not self.with_user(user).check_access_rights(
"read", raise_exception=False
):
return False
return True

def get_access_link(self):
# _notify_get_action_link is not callable from email template
return self._notify_get_action_link("view")
4 changes: 4 additions & 0 deletions helpdesk_mgmt/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
* Marcel Savegnago
* Eduardo Aparício

* `TAKOBI <https://takobi.online>`_:

* Lorenzo Battistini

* `Obertix <https://www.obertix.net>`_:

* Vicent Cubells
Expand Down
4 changes: 4 additions & 0 deletions helpdesk_mgmt/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,10 @@ <h2><a class="toc-backref" href="#toc-entry-13">Contributors</a></h2>
<li>Eduardo Aparício</li>
</ul>
</li>
<li><a class="reference external" href="https://takobi.online">TAKOBI</a>:<ul>
<li>Lorenzo Battistini</li>
</ul>
</li>
<li><a class="reference external" href="https://www.obertix.net">Obertix</a>:<ul>
<li>Vicent Cubells</li>
</ul>
Expand Down
3 changes: 3 additions & 0 deletions helpdesk_mgmt/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ def setUpClass(cls):
groups="helpdesk_mgmt.group_helpdesk_user",
context=ctx,
)
cls.admin = cls.env.ref("base.user_admin")
cls.user_portal = cls.env.ref("base.demo_user0")
cls.user_demo = cls.env.ref("base.user_demo")
cls.stage_closed = cls.env.ref("helpdesk_mgmt.helpdesk_ticket_stage_done")
cls.team_a = helpdesk_ticket_team.create(
{"name": "Team A", "user_ids": [(6, 0, [cls.user_own.id, cls.user.id])]}
Expand Down
Loading
Loading