[FIX] mail, mass_mailing: fix attachment ownership
Attachments that are uploaded on a record that isn't saved yet are created with res_id set to 0. In the case of attachments linked through a m2m rather than the usual (res_model, res_id), it means they may not be readable afer the creation of the record, except by their creator. Re-attaching them to the mailing / template at the end of the create() call fixes the ownership. Fixes #81935 closes odoo/odoo#82120 X-original-commit: 05fb705f2729ffdf07ab36accda20415a44e1aa6 Signed-off-by: Olivier Dony <odo@odoo.com>
This commit is contained in:
@@ -79,6 +79,15 @@ class MailTemplate(models.Model):
|
||||
# CRUD
|
||||
# ------------------------------------------------------------
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
templates = super().create(vals_list)
|
||||
# fix attachment ownership
|
||||
for template in templates:
|
||||
if template.attachment_ids:
|
||||
template.attachment_ids.write({'res_model': self._name, 'res_id': template.id})
|
||||
return templates
|
||||
|
||||
def unlink(self):
|
||||
self.unlink_action()
|
||||
return super(MailTemplate, self).unlink()
|
||||
|
||||
@@ -417,6 +417,12 @@ class MassMailing(models.Model):
|
||||
if mailing.ab_testing_enabled and not mailing.campaign_id
|
||||
]
|
||||
self.env['utm.campaign'].create(campaign_vals)
|
||||
|
||||
# fix attachment ownership
|
||||
for mailing in mailings:
|
||||
if mailing.attachment_ids:
|
||||
mailing.attachment_ids.write({'res_model': self._name, 'res_id': mailing.id})
|
||||
|
||||
return mailings
|
||||
|
||||
def write(self, values):
|
||||
|
||||
Reference in New Issue
Block a user