[FIX] (project_)pad: Don't create/copy pads on tasks that don't use them

Purpose
=======

Currently if a project doesn't use pads, the created and duplicated tasks will initialize/copy them. That could be a real issue when migrating customers if we create a task for all the existing issues, since the models have been merged.

Specification
=============

Avoid this falsy behavior. We're forced to crappy fix with a context key as the project.task model 'inherit' from pad.common.
This commit is contained in:
Yannick Tivisse
2017-11-27 12:26:44 +01:00
parent ac5ba4a2b0
commit d3efda05fd
2 changed files with 22 additions and 3 deletions
+7 -2
View File
@@ -106,6 +106,8 @@ class PadCommon(models.AbstractModel):
# In case the pad is created programmatically, the content is not filled in yet since it is
# normally initialized by the JS layer
if self.env.context.get('pad_no_create', False):
return pad
for k, field in self._fields.items():
if hasattr(field, 'pad_content_field') and k not in vals:
ctx = {
@@ -141,6 +143,9 @@ class PadCommon(models.AbstractModel):
default = {}
for k, field in self._fields.items():
if hasattr(field, 'pad_content_field'):
pad = self.pad_generate_url()
default[k] = pad.get('url')
if self.env.context.get('pad_no_create', False):
default[k] = ''
else:
pad = self.pad_generate_url()
default[k] = pad.get('url')
return super(PadCommon, self).copy(default)
+15 -1
View File
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models
from odoo import api, fields, models
class ProjectTask(models.Model):
@@ -11,6 +11,20 @@ class ProjectTask(models.Model):
description_pad = fields.Char('Pad URL', pad_content_field='description')
use_pad = fields.Boolean(related="project_id.use_pads", string="Use collaborative pad")
@api.model
def create(self, vals):
# When using quick create, the project_id is in the context, not in the vals
project_id = vals.get('project_id', False) or self.default_get(['project_id'])['project_id']
if not self.env['project.project'].browse(project_id).use_pads:
self = self.with_context(pad_no_create=True)
return super(ProjectTask, self).create(vals)
@api.multi
def copy(self, default=None):
if not self.use_pad:
self = self.with_context(pad_no_create=True)
return super(ProjectTask, self).copy(default)
class ProjectProject(models.Model):
_inherit = "project.project"