Skip to content

Commit

Permalink
[FIX] mail, mass_mailing: fix attachment ownership
Browse files Browse the repository at this point in the history
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 odoo#81935

closes odoo#82120

X-original-commit: 05fb705
Signed-off-by: Olivier Dony <[email protected]>
  • Loading branch information
odony committed Jan 10, 2022
1 parent 31e58ef commit e58471b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
9 changes: 9 additions & 0 deletions addons/mail/models/mail_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ def _compute_render_model(self):
# 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()
Expand Down
6 changes: 6 additions & 0 deletions addons/mass_mailing/models/mailing.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,12 @@ def create(self, vals_list):
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):
Expand Down

0 comments on commit e58471b

Please sign in to comment.