Skip to Content
Menu
This question has been flagged

I have a Send by Mail action like this:

...
return {
            'type': 'ir.actions.act_window',
            'view_type': 'form',
            'view_mode': 'form',
            'res_model': 'mail.compose.message',
            'views': [(compose_form_id, 'form')],
            'view_id': compose_form_id,
            'target': 'new',
            'context': ctx,
        }

But if the user has read only access to the record it shows error:

Sorry, you are not allowed to modify this document. Only users with the following access level are currently allowed to do that:

Server application error {"message":"Odoo Server Error","code":200,"data":{"debug":"Traceback (most recent call last):
  File \"F:\\Software\\eclipse\\odoo\\odoo\\http.py\", line 638, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File \"F:\\Software\\eclipse\\odoo\\odoo\\http.py\", line 675, in dispatch
    result = self._call_function(**self.params)
  File \"F:\\Software\\eclipse\\odoo\\odoo\\http.py\", line 331, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File \"F:\\Software\\eclipse\\odoo\\odoo\\service\\model.py\", line 119, in wrapper
    return f(dbname, *args, **kwargs)
  File \"F:\\Software\\eclipse\\odoo\\odoo\\http.py\", line 324, in checked_call
    result = self.endpoint(*a, **kw)
  File \"F:\\Software\\eclipse\\odoo\\odoo\\http.py\", line 933, in __call__
    return self.method(*args, **kw)
  File \"F:\\Software\\eclipse\\odoo\\odoo\\http.py\", line 504, in response_wrap
    response = f(*args, **kw)
  File \"F:\\Software\\eclipse\\odoo\\addons\\web\\controllers\\main.py\", line 885, in call_kw
    return self._call_kw(model, method, args, kwargs)
  File \"F:\\Software\\eclipse\\odoo\\addons\\web\\controllers\\main.py\", line 877, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File \"F:\\Software\\eclipse\\odoo\\odoo\\api.py\", line 679, in call_kw
    return call_kw_model(method, model, args, kwargs)
  File \"F:\\Software\\eclipse\\odoo\\odoo\\api.py\", line 664, in call_kw_model
    result = method(recs, *args, **kwargs)
  File \"F:\\Software\\eclipse\\odoo\\addons\\mail\\models\\mail_message.py\", line 726, in create
    message = super(Message, self).create(values)
  File \"F:\\Software\\eclipse\\odoo\\odoo\\models.py\", line 3830, in create
    record = self.browse(self._create(old_vals))
  File \"F:\\Software\\eclipse\\odoo\\odoo\\models.py\", line 3999, in _create
    self.check_access_rule('create')
  File \"F:\\Software\\eclipse\\odoo\\addons\\mail\\wizard\\mail_compose_message.py\", line 147, in check_access_rule
    return super(MailComposer, self).check_access_rule(operation)
  File \"F:\\Software\\eclipse\\odoo\\addons\\mail\\models\\mail_message.py\", line 658, in check_access_rule
    DocumentModel.check_mail_message_access(mids.ids, operation)  # ?? mids ?
  File \"F:\\Software\\eclipse\\odoo\\addons\\mail\\models\\mail_thread.py\", line 562, in check_mail_message_access
    DocModel.check_access_rights(check_operation)
  File \"F:\\Software\\eclipse\\odoo\\addons\\muk_dms\\models\\muk_dms_base.py\", line 299, in check_access_rights
    return super(DMSAccessModel, self).check_access_rights(operation, raise_exception)
  File \"F:\\Software\\eclipse\\odoo\\odoo\\models.py\", line 3289, in check_access_rights
    return self.env['ir.model.access'].check(self._name, operation, raise_exception)
  File \"<decorator-gen-4>\", line 2, in check
  File \"F:\\Software\\eclipse\\odoo\\odoo\\tools\\cache.py\", line 87, in lookup
    value = d[key] = self.method(*args, **kwargs)
  File \"F:\\Software\\eclipse\\odoo\\odoo\\addons\\base\\ir\\ir_model.py\", line 940, in check
    raise AccessError(msg % msg_params)
AccessError: (u'Sorry, you are not allowed to modify this document. Only users with the following access level are currently allowed to do that:

I don't need to modify the record but I want to be able to send a mail even if I have readonly access to the record

Avatar
Discard

any codes before return actions? then please post here. you are probably trying to access a model which is securely restricted to admin only. And also you didn't post the complete log which will define which model. solutions are either you have to add security lines for user's group or try to access as superuser.

Author

The whole function is:

@api.multi

def action_send_mail(self):

self.ensure_one()

attachment = {

'name': ("%s" %self.filename),

'datas': self.get_file_data(),

'datas_fname': self.filename,

'res_model': 'music_audiofile',

'type': 'binary'

}

id = self.env['ir.attachment'].create(attachment)

email_template = self.env.ref('music.email_template_music_audiofile')

old_ids = email_template.attachment_ids.ids

for old_att in self.env['ir.attachment'].browse(old_ids):

old_att.unlink()

email_template.attachment_ids = [(4,id.id)]

ir_model_data = self.env['ir.model.data']

try:

template_id = ir_model_data.get_object_reference('music', 'email_template_music_audiofile')[1]

except ValueError:

template_id = False

try:

compose_form_id = ir_model_data.get_object_reference('mail', 'email_compose_message_wizard_form')[1]

except ValueError:

compose_form_id = False

ctx = dict()

ctx.update({

'default_model': 'music.audiofile',

'default_res_id': self.ids[0],

'default_use_template': bool(template_id),

'default_template_id': template_id,

'default_composition_mode': 'comment',

})

return {

'type': 'ir.actions.act_window',

'view_type': 'form',

'view_mode': 'form',

'res_model': 'mail.compose.message',

'views': [(compose_form_id, 'form')],

'view_id': compose_form_id,

'target': 'new',

'context': ctx,

}

It attaches the binary field (audiofile) and uses message compose wizard to send a mail. The user has READ ONLY access to the model 'music.audiofile' (Admin group has write access and no problem sending the mail) but I don't see why it asks for writing permissions.

Related Posts Replies Views Activity
0
Jan 21
1431
0
Mar 19
4076
0
Feb 16
3365
1
Feb 16
2918
0
Mar 15
8360