[FIX] pad_project: copy the content in the pad when use_pad=False

Before this commit, when the user edits the description of a task with
use_pad=True and then change the project of this task to one with
use_pads=False. The description written in the pad server is not copied
in the description field of the task.

This commit copies the content of the pad for this case when the use_pad
changes to become False and description_pad is set.

Step to reproduce:
-----------------

1. Go to Settings of the Project App and enable the Collaborative Pads
2. Go to the Project App, in the Projects dashboard (kanban view of projects)
3. Create two Projects (one called "Project A" and the other called "Project B")
4. Edit the Project B to activate the pad, that is, check the Use
collaborative pads checkbox.
5. Go to the view list of tasks in the "Project B"
6. Click on "Create" button to create a task in the task form view.
7. Write a description for this task.
8. Change the project of this task by the "Project A". With this change,
the collaborative pad is disabled for this task since the Project A has
not the pad, and then the description field is empty rather than have
the content that we have just written.

task-2515150

closes #70401

closes odoo/odoo#70917

X-original-commit: 32a8f598d6a958f2a08b204524007cc075697fda
Signed-off-by: LTU-Odoo <IT-Ideas@users.noreply.github.com>
This commit is contained in:
Xavier BOL (xbo)
2021-05-17 18:32:55 +00:00
parent d4d09d0fe1
commit c006e97f71
+12
View File
@@ -16,6 +16,18 @@ class ProjectTask(models.Model):
string="Availability of collaborative pads",
readonly=True)
@api.onchange('use_pad')
def _onchange_use_pads(self):
""" Copy the content in the pad when the user change the project of the task to the one with no pads enabled.
This case is when the use_pad becomes False and we have already generated the url pad,
that is the description_pad field contains the url of the pad.
"""
if not self.use_pad and self.description_pad:
vals = {'description_pad': self.description_pad}
self._set_pad_to_field(vals)
self.description = vals['description']
@api.model
def create(self, vals):
# When using quick create, the project_id is in the context, not in the vals