diff options
| author | Nicolas Martinelli <nim@odoo.com> | 2018-03-02 10:04:57 +0100 |
|---|---|---|
| committer | Nicolas Martinelli <nim-odoo@users.noreply.github.com> | 2018-03-05 08:42:11 +0100 |
| commit | 4badf49ad0b5e3b269e725d1a0dd12a65ec68e48 (patch) | |
| tree | 55d0e523f33515f507abe6401e44e183f697d967 /addons | |
| parent | 566ce21d42338ca806f8961ae02f9576bf011569 (diff) | |
[FIX] pad, pad_project, note_pad: duplicate object
The duplication of a task crashes at the following:
`content = myPad.getHtml(path).get('html', '')`
The copy mechanism is quite cumbersome:
- In `copy` method, generate an URL of a pad which doesn't exist since
`object_id` is still undefined.
- The `create` method somehow attempts to fill in the previously created
pad thanks to `_set_pad_value`.
The logic is made simpler. The pad URL field is set as `copy=False`,
therefore the create mechanism will take care of handling the pad
creation and its synchronization.
opw-1818757
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/note_pad/models/note.py | 2 | ||||
| -rw-r--r-- | addons/pad/models/pad.py | 30 | ||||
| -rw-r--r-- | addons/pad_project/models/project.py | 8 |
3 files changed, 11 insertions, 29 deletions
diff --git a/addons/note_pad/models/note.py b/addons/note_pad/models/note.py index 080e313a873..49536d79b88 100644 --- a/addons/note_pad/models/note.py +++ b/addons/note_pad/models/note.py @@ -11,4 +11,4 @@ class NotePad(models.Model): _pad_fields = ['note_pad'] - note_pad_url = fields.Char('Pad Url', pad_content_field='memo') + note_pad_url = fields.Char('Pad Url', pad_content_field='memo', copy=False) diff --git a/addons/pad/models/pad.py b/addons/pad/models/pad.py index a1e31bf485a..deb920ec69e 100644 --- a/addons/pad/models/pad.py +++ b/addons/pad/models/pad.py @@ -101,16 +101,19 @@ class PadCommon(models.AbstractModel): @api.multi def write(self, vals): - self._set_pad_value(vals) + self._set_field_to_pad(vals) + self._set_pad_to_field(vals) return super(PadCommon, self).write(vals) @api.model def create(self, vals): - self._set_pad_value(vals) + # Case of a regular creation: we receive the pad url, so we need to update the + # corresponding field + self._set_pad_to_field(vals) pad = super(PadCommon, self).create(vals) - # In case the pad is created programmatically, the content is not filled in yet since it is - # normally initialized by the JS layer + # Case of a programmatical creation (e.g. copy): we receive the field content, so we need + # to create the corresponding pad if self.env.context.get('pad_no_create', False): return pad for k, field in self._fields.items(): @@ -124,9 +127,7 @@ class PadCommon(models.AbstractModel): pad[k] = pad_info.get('url') return pad - # Set the pad content in vals - def _set_pad_value(self, vals): - + def _set_field_to_pad(self, vals): # Update the pad if the `pad_content_field` is modified for k, field in self._fields.items(): if hasattr(field, 'pad_content_field') and vals.get(field.pad_content_field) and self[k]: @@ -135,22 +136,9 @@ class PadCommon(models.AbstractModel): path = self[k].split('/p/')[1] myPad.setHtmlFallbackText(path, vals[field.pad_content_field]) + def _set_pad_to_field(self, vals): # Update the `pad_content_field` if the pad is modified for k, v in list(vals.items()): field = self._fields.get(k) if hasattr(field, 'pad_content_field'): vals[field.pad_content_field] = self.pad_get_content(v) - - @api.multi - def copy(self, default=None): - self.ensure_one() - if not default: - default = {} - for k, field in self._fields.items(): - if hasattr(field, 'pad_content_field'): - 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) diff --git a/addons/pad_project/models/project.py b/addons/pad_project/models/project.py index eae27a4f6a7..f994b3a5ea7 100644 --- a/addons/pad_project/models/project.py +++ b/addons/pad_project/models/project.py @@ -8,7 +8,7 @@ class ProjectTask(models.Model): _name = "project.task" _inherit = ["project.task", 'pad.common'] - description_pad = fields.Char('Pad URL', pad_content_field='description') + description_pad = fields.Char('Pad URL', pad_content_field='description', copy=False) use_pad = fields.Boolean(related="project_id.use_pads", string="Use collaborative pad") @api.model @@ -19,12 +19,6 @@ class ProjectTask(models.Model): 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" |
