Skip to content

Commit

Permalink
TA#66863 [16.0][MIG] project_task_stage_external_mail (#405)
Browse files Browse the repository at this point in the history
TA#66863 [16.0][MIG] project_task_stage_external_mail

---------

Co-authored-by: Majda EL MARIOULI <[email protected]>
  • Loading branch information
lanto-razafindrabe and majouda authored Jul 7, 2024
1 parent 7b2f6d0 commit 8e1867e
Show file tree
Hide file tree
Showing 16 changed files with 276 additions and 0 deletions.
1 change: 1 addition & 0 deletions .docker_files/main/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"depends": [
"project",
"project_task_date_planned",
"project_task_stage_external_mail",
"project_task_type",
],
"installable": True,
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ RUN gitoo install-all --conf_file /gitoo.yml --destination "${THIRD_PARTY_ADDONS
USER odoo

COPY project_task_date_planned /mnt/extra-addons/project_task_date_planned
COPY project_task_stage_external_mail /mnt/extra-addons/project_task_stage_external_mail
COPY project_task_type /mnt/extra-addons/project_task_type

COPY .docker_files/main /mnt/extra-addons/main
Expand Down
39 changes: 39 additions & 0 deletions project_task_stage_external_mail/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
================================
Project Task Stage External Mail
================================

.. contents:: Table of Contents

Context
-------
In Odoo, you are able to attach an email template to a task stage.

.. image:: static/description/vanilla_odoo_task_stage_form.png

Since version 12.0, instead of publishing an email, an internal note is sent.

Use Case
--------
The main purpose of the module is to have automatic messages at the
creation of support task to be published to clients.

Usage
-----
As ``Project / Manager``, I go to the form view of a task stage.

I select an email template to be sent for this stage.
I notice a new checkbox ``External Mail``. This box is unchecked by default.
I check the box then save.

.. image:: static/description/task_stage_external_mail_checked.png

As ``Project / User``, I go to the form view of a task.

I set move the task to the stage ``Open``.
I notice that an external email was sent.

.. image:: static/description/task_to_open_with_external_email.png

Contributors
------------
* Numigi (tm) and all its contributors (https://bit.ly/numigiens)
4 changes: 4 additions & 0 deletions project_task_stage_external_mail/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2024-today Numigi and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from . import models
22 changes: 22 additions & 0 deletions project_task_stage_external_mail/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2024-today Numigi and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

{
"name": "Project Task Stage External Mail",
"version": "16.0.1.0.0",
"category": "Project",
"summary": "Send an external email for a task stage",
"author": "Numigi",
"license": "LGPL-3",
"depends": [
"project",
"mail",
],
"data": [
"views/project_task_type.xml",
],
"demo": [
"demo/mail_template.xml",
],
"application": False,
}
22 changes: 22 additions & 0 deletions project_task_stage_external_mail/demo/mail_template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0"?>
<odoo>
<data noupdate="1">

<record id="demo_mail_template_task_open" model="mail.template">
<field name="name">Task Open</field>
<field name="model_id" ref="project.model_project_task"/>
<field name="subject">Task Open: {{object.display_name}}</field>
<field name="use_default_to" eval="True"/>
<field name="body_html" type="html">
<div>
Hello,
</div>
<div>
this is an automated message to inform you that a ticket was open in your project.
</div>
</field>
<field name="auto_delete" eval="True"/>
</record>

</data>
</odoo>
53 changes: 53 additions & 0 deletions project_task_stage_external_mail/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * project_task_stage_external_mail
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-06-17 19:07+0000\n"
"PO-Revision-Date: 2023-06-17 19:07+0000\n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: project_task_stage_external_mail
#: model:mail.template,body_html:project_task_stage_external_mail.demo_mail_template_task_open
msgid "<div>\n"
" Hello,\n"
"</div>\n"
"<div>\n"
" this is an automated message to inform you that a ticket was open in your project.\n"
"</div>\n"
" "
msgstr "<div>\n"
" Bonjour,\n"
"</div>\n"
"<div>\n"
" ceci est un message pour vous informer qu'un ticket a été ouvert dans votre projet.\n"
"</div>\n"
" "

#. module: project_task_stage_external_mail
#: model:ir.model.fields,field_description:project_task_stage_external_mail.field_project_task_type__external_mail
msgid "External Mail"
msgstr "Envoi en externe"

#. module: project_task_stage_external_mail
#: model:ir.model,name:project_task_stage_external_mail.model_project_task
msgid "Task"
msgstr ""

#. module: project_task_stage_external_mail
#: model:mail.template,subject:project_task_stage_external_mail.demo_mail_template_task_open
msgid "Task Open: ${object.display_name}"
msgstr "Ticket Ouvert: ${object.display_name}"

#. module: project_task_stage_external_mail
#: model:ir.model,name:project_task_stage_external_mail.model_project_task_type
msgid "Task Stage"
msgstr ""
4 changes: 4 additions & 0 deletions project_task_stage_external_mail/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2024-today Numigi and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from . import project_task
23 changes: 23 additions & 0 deletions project_task_stage_external_mail/models/project_task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2024-today Numigi and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo import models, fields


class ProjectTaskTypeExternalMail(models.Model):
_inherit = "project.task.type"

external_mail = fields.Boolean()


class ProjectTask(models.Model):
_inherit = "project.task"

def _track_template(self, changes):
res = super(ProjectTask, self)._track_template(changes)
test_task = self[0]
if "stage_id" in res and test_task.stage_id.external_mail:
res["stage_id"][-1]["subtype_id"] = self.env[
"ir.model.data"
]._xmlid_to_res_id("mail.mt_comment")
return res
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions project_task_stage_external_mail/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Copyright 2024-today Numigi and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from . import test_project_task
88 changes: 88 additions & 0 deletions project_task_stage_external_mail/tests/test_project_task.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Copyright 2024-today Numigi and all its contributors (https://bit.ly/numigiens)
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo.tests import common


class TestProjectTask(common.SavepointCase):

@classmethod
def setUpClass(cls):
super().setUpClass()
cls.user_demo = cls.env.ref("base.user_demo")
cls.discussion_type = cls.env.ref("mail.mt_comment")
cls.internal_note_type = cls.env.ref("mail.mt_note")
cls.template = cls.env.ref(
"project_task_stage_external_mail.demo_mail_template_task_open"
)
cls.project = cls.env["project.project"].create(
{
"name": "Project 1",
}
)
cls.external_partner = cls.env["res.partner"].create(
{
"name": "tpartner",
"email": "[email protected]",
}
)
cls.project.message_subscribe([cls.external_partner.id])

cls.stage1 = cls.env["project.task.type"].create(
{
"name": "New",
"mail_template_id": cls.template.id,
"external_mail": False,
"project_ids": [(4, cls.project.id)],
}
)
cls.stage2 = cls.env["project.task.type"].create(
{
"name": "Open",
"mail_template_id": cls.template.id,
"external_mail": True,
"project_ids": [(4, cls.project.id)],
}
)

cls.task1 = cls.env["project.task"].create(
{
"name": "ttask 1",
"stage_id": cls.stage1.id,
"partner_id": cls.user_demo.partner_id.id,
"project_id": cls.project.id,
"user_ids": [(4, cls.user_demo.id)],
}
)
cls.task2 = cls.env["project.task"].create(
{
"name": "ttask 2",
"stage_id": cls.stage2.id,
"partner_id": cls.user_demo.partner_id.id,
"project_id": cls.project.id,
"user_ids": [(4, cls.user_demo.id)],
}
)

def _get_sent_message(self, task):
messages = task.message_ids.filtered(
lambda m: "Task Open: " in (m.subject or "")
).sorted(key=lambda s: s.id, reverse=True)
return messages

def _get_message_recipients(self, task):
message = self._get_sent_message(task)
return message.mapped("notification_ids.res_partner_id")

def test_givenExternalMailIsUnChecked_thenInternalNote(self):
assert self._get_sent_message(self.task1).subtype_id == self.internal_note_type

def test_givenExternalMailIsUnchecked_thenExternalPartnerNotInRecipients(self):
assert self._get_message_recipients(self.task1)
assert self.external_partner not in self._get_message_recipients(self.task1)

def test_givenExternalMailIsChecked_thenCommentSent(self):
assert self._get_sent_message(self.task2).subtype_id == self.discussion_type

def test_givenExternalMailIsChecked_thenExternalPartnerInRecipients(self):
assert self.external_partner in self._get_message_recipients(self.task2)
15 changes: 15 additions & 0 deletions project_task_stage_external_mail/views/project_task_type.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<odoo>

<record id="task_stage_with_external_mail" model="ir.ui.view">
<field name="name">Task Stage: add field external_mail</field>
<field name="model">project.task.type</field>
<field name="inherit_id" ref="project.task_type_edit"/>
<field name="arch" type="xml">
<field name="mail_template_id" position="after">
<field name="external_mail" attrs="{'invisible': [('mail_template_id', '=', False)]}" />
</field>
</field>
</record>

</odoo>

0 comments on commit 8e1867e

Please sign in to comment.