Files
odoo_source/addons/project_sms/models/project_task.py
T
Xavier BOL (xbo) 1b6af2addb [FIX] project_sms: cannot change task stage to stage with sms template
Before this commit when the portal user changes the stage of a task
to a stage with sms template, he got a traceback saying he has no access
to the `sms.template` model.

This commit fixes by checking if the user is a portal one to send the
sms in sudo when the write on the task is correctly done.

Steps to reproduce:
==================
1) install `project_sms` module,
2) create a project,
3) in the kanban of tasks for this project create 2 stages,
4) edit the last one to set a sms template,
5) share the project in edit mode to a portal user,
6) create a task with the quick create,
7) log in as portal user and go the project shared
8) move the task into the last stage.

Actual Behavior:
---------------
A traceback is occurred saying the portal user has no access to
`sms.template` model.

Expected behavior:
-----------------
The task should be in the last stage and the sms should be sent.

closes odoo/odoo#99363

X-original-commit: 9aa5e65273885001106a5fcc64677a284b77f61d
Signed-off-by: Laurent Stukkens (ltu) <ltu@odoo.com>
2022-09-01 06:46:55 +02:00

31 lines
945 B
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, models
class ProjectTask(models.Model):
_inherit = "project.task"
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)
@api.model_create_multi
def create(self, vals_list):
tasks = super().create(vals_list)
tasks._send_sms()
return tasks
def write(self, vals):
res = super().write(vals)
if 'stage_id' in vals:
if self.env.user.has_group('base.group_portal') and not self.env.su:
# sudo as sms template model is protected
self.sudo()._send_sms()
else:
self._send_sms()
return res