From 4b3a8b4f7a3a200da70ba4ddb82bb26280949868 Mon Sep 17 00:00:00 2001 From: "Audric Onockx (auon)" Date: Thu, 23 Mar 2023 16:26:34 +0000 Subject: [PATCH] [FIX] project_sms: send sms, but for real `/project_sms:ProjectTask._send_sms` called `_message_sms_with_template` without numbers, and so no sms was sent. Now, we give the method an `sms_numbers` arg, and it works. closes odoo/odoo#116514 X-original-commit: 5de1b941ce580253a21f0e4f6da0a8ca818f26b3 Signed-off-by: Xavier Bol (xbo) --- addons/project_sms/models/project_project.py | 6 +++- addons/project_sms/models/project_task.py | 6 +++- .../project_sms/tests/test_project_sharing.py | 33 ++++++++++++++++--- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/addons/project_sms/models/project_project.py b/addons/project_sms/models/project_project.py index b5ca63698a2..27e21368b75 100644 --- a/addons/project_sms/models/project_project.py +++ b/addons/project_sms/models/project_project.py @@ -10,7 +10,11 @@ class ProjectProject(models.Model): def _send_sms(self): for project in self: if project.partner_id and project.stage_id and project.stage_id.sms_template_id: - project._message_sms_with_template(template=project.stage_id.sms_template_id, partner_ids=project.partner_id.ids) + project._message_sms_with_template( + template=project.stage_id.sms_template_id, + partner_ids=project.partner_id.ids, + sms_numbers=project.partner_id.mapped('mobile'), + ) @api.model_create_multi def create(self, vals_list): diff --git a/addons/project_sms/models/project_task.py b/addons/project_sms/models/project_task.py index 32461038f67..d65bc4d9614 100644 --- a/addons/project_sms/models/project_task.py +++ b/addons/project_sms/models/project_task.py @@ -10,7 +10,11 @@ class ProjectTask(models.Model): def _send_sms(self): for task in self: if task.partner_id and task.stage_id and task.stage_id.sms_template_id: - task._message_sms_with_template(template=task.stage_id.sms_template_id, partner_ids=task.partner_id.ids) + task._message_sms_with_template( + template=task.stage_id.sms_template_id, + partner_ids=task.partner_id.ids, + sms_numbers=task.partner_id.mapped('mobile'), + ) @api.model_create_multi def create(self, vals_list): diff --git a/addons/project_sms/tests/test_project_sharing.py b/addons/project_sms/tests/test_project_sharing.py index 717eb04524d..45d456e937b 100644 --- a/addons/project_sms/tests/test_project_sharing.py +++ b/addons/project_sms/tests/test_project_sharing.py @@ -3,29 +3,52 @@ from odoo import Command from odoo.addons.project.tests.test_project_sharing import TestProjectSharingCommon +from odoo.addons.sms.tests.common import SMSCommon -class TestProjectSharingWithSms(TestProjectSharingCommon): +class TestProjectSharingWithSms(TestProjectSharingCommon, SMSCommon): @classmethod def setUpClass(cls): super().setUpClass() + project_settings = cls.env["res.config.settings"].create({'group_project_stages': True}) + project_settings.execute() cls.sms_template = cls.env['sms.template'].sudo().create({ 'body': '{{ object.name }}', 'model_id': cls.env['ir.model'].sudo().search([('model', '=', 'project.task')]).id, }) - cls.project_portal.type_ids[-1].write({'sms_template_id': cls.sms_template.id}) + cls.task_stage_with_sms = cls.project_portal.type_ids[-1] + cls.task_stage_with_sms.write({'sms_template_id': cls.sms_template.id}) + + cls.sms_template_2 = cls.env['sms.template'].sudo().create({ + 'body': '{{ object.name }}', + 'model_id': cls.env['ir.model'].sudo().search([('model', '=', 'project.project')]).id, + }) + cls.project_stage_with_sms = cls.project_portal.stage_id.browse(2) + cls.project_stage_with_sms.write({'sms_template_id': cls.sms_template_2.id}) + cls.project_portal.write({ 'collaborator_ids': [ Command.create({'partner_id': cls.user_portal.partner_id.id}), ], }) + cls.project_portal.partner_id.mobile = cls.random_numbers[0] def test_portal_user_can_change_stage_with_sms_template(self): """ Test user portal can change the stage of a task to a stage with a sms template The sms template should be sent and the stage should be changed on the task. """ - stage = self.project_portal.type_ids[-1] - self.task_portal.with_user(self.user_portal).write({'stage_id': stage.id}) - self.assertEqual(self.task_portal.stage_id, stage) + with self.mockSMSGateway(): + self.task_portal.with_user(self.user_portal).write({ + 'stage_id': self.task_stage_with_sms.id, + }) + self.assertEqual(self.task_portal.stage_id, self.task_stage_with_sms) + self.assertSMSIapSent([self.task_portal.partner_id.mobile]) + + with self.mockSMSGateway(): + self.project_portal.write({ + 'stage_id': self.project_stage_with_sms.id, + }) + self.assertEqual(self.project_portal.stage_id, self.project_stage_with_sms) + self.assertSMSIapSent([self.project_portal.partner_id.mobile])