Skip to content

Commit

Permalink
[FIX] mail: don't raise access error on register_as_main_attachment
Browse files Browse the repository at this point in the history
When you read a record with the document viewer on the right side
that you don't have write access to this record
and the message_main_attachment_id was not yet set on the record

the document viewer try to set a value for message_main_attachment_id
that raise an access error

Set the value is not important but the popup
Access error can be really annoying

closes odoo#44722

Signed-off-by: Quentin De Paoli (qdp) <[email protected]>
  • Loading branch information
tfr-odoo committed Feb 6, 2020
1 parent 32b385b commit e6a41b1
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions addons/mail/models/ir_attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import api, models

from odoo.exceptions import AccessError

class IrAttachment(models.Model):
_inherit = 'ir.attachment'
Expand All @@ -26,4 +26,9 @@ def register_as_main_attachment(self, force=True):
# we are just checking that it exists on the model before writing it
if related_record and hasattr(related_record, 'message_main_attachment_id'):
if force or not related_record.message_main_attachment_id:
related_record.message_main_attachment_id = self
#Ignore AccessError, if you don't have access to modify the document
#Just don't set the value
try:
related_record.message_main_attachment_id = self
except AccessError:
pass

0 comments on commit e6a41b1

Please sign in to comment.