fsm_visit_confirmation: completely separated from ratings now
This commit is contained in:
parent
81a4a904c7
commit
2322dbaae1
8 changed files with 78 additions and 3 deletions
|
|
@ -1 +1,2 @@
|
||||||
from . import controllers
|
from . import controllers
|
||||||
|
from . import models
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@
|
||||||
"data": [
|
"data": [
|
||||||
"data/mail_templates.xml",
|
"data/mail_templates.xml",
|
||||||
"views/project_portal_project_task_templates.xml",
|
"views/project_portal_project_task_templates.xml",
|
||||||
|
"views/project_task_type_views.xml",
|
||||||
],
|
],
|
||||||
"installable": True,
|
"installable": True,
|
||||||
"auto_install": False,
|
"auto_install": False,
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
<odoo>
|
<odoo>
|
||||||
<record id="fsm_visit_confirmation_email_template" model="mail.template">
|
<record id="fsm_visit_confirmation_email_template" model="mail.template">
|
||||||
<field name="name">FSM Visit Confirmation</field>
|
<field name="name">FSM Visit Confirmation</field>
|
||||||
<field name="model_id" ref="industry_fsm.model_project_task"/>
|
<field name="model_id" ref="project.model_project_task"/>
|
||||||
<field name="subject">Service Visit Confirmation: {{ object.name }}</field>
|
<field name="subject">Service Visit Confirmation: {{ object.name }}</field>
|
||||||
<field name="email_from">{{ user.email_formatted }}</field>
|
<field name="email_from">{{ user.email_formatted }}</field>
|
||||||
<field name="partner_to">{{ object.work_order_contacts and object.work_order_contacts[0].id or object.partner_id.id }}</field>
|
<field name="partner_to">{{ object.work_order_contacts and object.work_order_contacts[0].id or object.partner_id.id }}</field>
|
||||||
|
|
|
||||||
2
fsm_visit_confirmation/models/__init__.py
Normal file
2
fsm_visit_confirmation/models/__init__.py
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
from . import project_task_type
|
||||||
|
from . import project_task
|
||||||
28
fsm_visit_confirmation/models/project_task.py
Normal file
28
fsm_visit_confirmation/models/project_task.py
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
from odoo import models
|
||||||
|
|
||||||
|
|
||||||
|
class ProjectTask(models.Model):
|
||||||
|
_inherit = "project.task"
|
||||||
|
|
||||||
|
def write(self, vals):
|
||||||
|
# Store old stage for comparison
|
||||||
|
old_stages = {task.id: task.stage_id for task in self}
|
||||||
|
|
||||||
|
# Execute original write method
|
||||||
|
result = super().write(vals)
|
||||||
|
|
||||||
|
# If stage changed and new stage has an approval template, send the email
|
||||||
|
if "stage_id" in vals:
|
||||||
|
for task in self.filtered(
|
||||||
|
lambda task: task.stage_id != old_stages[task.id]
|
||||||
|
and task.stage_id.approval_template_id
|
||||||
|
):
|
||||||
|
task.stage_id.approval_template_id.send_mail(
|
||||||
|
task.id,
|
||||||
|
force_send=True,
|
||||||
|
email_values={
|
||||||
|
"email_to": task.partner_id.email if task.partner_id else False
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
return result
|
||||||
11
fsm_visit_confirmation/models/project_task_type.py
Normal file
11
fsm_visit_confirmation/models/project_task_type.py
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
from odoo import fields, models
|
||||||
|
|
||||||
|
|
||||||
|
class ProjectTaskType(models.Model):
|
||||||
|
_inherit = 'project.task.type'
|
||||||
|
|
||||||
|
approval_template_id = fields.Many2one(
|
||||||
|
'mail.template',
|
||||||
|
string='Approval Template',
|
||||||
|
help='Template to use for approval emails when a task reaches this stage.'
|
||||||
|
)
|
||||||
|
|
@ -3,13 +3,14 @@
|
||||||
import logging
|
import logging
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from odoo import http
|
from odoo import http
|
||||||
|
from odoo.addons.mail.tests.common import MailCommon
|
||||||
from odoo.tests import HttpCase, tagged
|
from odoo.tests import HttpCase, tagged
|
||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
@tagged("post_install", "-at_install")
|
@tagged("post_install", "-at_install")
|
||||||
class TestFSMVisitConfirmation(HttpCase):
|
class TestFSMVisitConfirmation(HttpCase, MailCommon):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
@ -142,6 +143,24 @@ class TestFSMVisitConfirmation(HttpCase):
|
||||||
)
|
)
|
||||||
self.assertTrue(messages, "A message should be posted on the task")
|
self.assertTrue(messages, "A message should be posted on the task")
|
||||||
|
|
||||||
|
def test_03_stage_approved_sends_email(self):
|
||||||
|
"""Test that moving a task to the approved stage sends an email"""
|
||||||
|
# Set the approval template on the approved stage
|
||||||
|
template = self.env.ref(
|
||||||
|
"fsm_visit_confirmation.fsm_visit_confirmation_email_template"
|
||||||
|
)
|
||||||
|
self.stage_approved.approval_template_id = template
|
||||||
|
|
||||||
|
with self.mock_mail_gateway():
|
||||||
|
self.task.write({"stage_id": self.stage_approved.id})
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
len(self._new_mails),
|
||||||
|
1,
|
||||||
|
"Moving task to approved stage should send an email",
|
||||||
|
)
|
||||||
|
self.assertEqual(self._new_mails[0].email_to, self.customer.email)
|
||||||
|
|
||||||
def test_02_task_request_changes_flow(self):
|
def test_02_task_request_changes_flow(self):
|
||||||
"""Test the complete task request changes flow"""
|
"""Test the complete task request changes flow"""
|
||||||
# Test the FSM confirmation change endpoint
|
# Test the FSM confirmation change endpoint
|
||||||
|
|
|
||||||
13
fsm_visit_confirmation/views/project_task_type_views.xml
Normal file
13
fsm_visit_confirmation/views/project_task_type_views.xml
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<odoo>
|
||||||
|
<record id="view_project_task_type_form_inherit_fsm_visit_confirmation" model="ir.ui.view">
|
||||||
|
<field name="name">project.task.type.form.inherit.fsm.visit.confirmation</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="approval_template_id"/>
|
||||||
|
</field>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
</odoo>
|
||||||
Loading…
Reference in a new issue