From d2707fa7d79e3e69f5d923b47887dec1478ad73f Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Mon, 19 Sep 2016 11:41:38 +0200 Subject: [PATCH] [FIX] pad: initialize pad at creation When a pad is created programmatically (e.g. through a project task or a note), the pad is empty when it is first displayed. It is necessary to edit the record and save it in order to be able to see the content. This is because the pad is normally initialized by the JS layer, at the first edition, thanks to a call to `pad_generate_url`. Therefore, a programmatic pad creation won't initialize it. opw-685826 --- addons/pad/pad.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/addons/pad/pad.py b/addons/pad/pad.py index 0199368327a..711bbd46fc5 100644 --- a/addons/pad/pad.py +++ b/addons/pad/pad.py @@ -91,7 +91,24 @@ class pad_common(osv.osv_memory): def create(self, cr, uid, vals, context=None): self._set_pad_value(cr, uid, vals, context) - return super(pad_common, self).create(cr, uid, vals, context=context) + res = super(pad_common, self).create(cr, uid, vals, context=context) + + # In case the pad is created programmatically, the content is not filled in yet since it is + # normally initialized by the JS layer + pad_urls = {} + for k, field in self._fields.iteritems(): + if hasattr(field, 'pad_content_field') and k not in vals: + ctx = dict(context or {}) + ctx.update({ + 'model': self._name, + 'field_name': k, + 'object_id': res, + }) + pad = self.pad_generate_url(cr, uid, ctx) + pad_urls[k] = pad.get('url') + if pad_urls: + self.write(cr, uid, res, pad_urls, context=context) + return res # Set the pad content in vals def _set_pad_value(self, cr, uid, vals, context=None):