跳至內容
選單
此問題已被標幟
1 回覆
6425 瀏覽次數

Hi,

I am using "document" module of odoo12 for attaching the documents in sale order and purchase order in my custom module. but I want to restrict other user from deleting those attachment only the super user can delete those attachment.

Could anyone help me to achieve this.

頭像
捨棄
最佳答案

You just need to override the unlink method of the ir.attachment object. In the method, check if the logged in user (self._uid) is super admin or not. If it is not super admin, raise the exception.

from odoo import api, fields, models, SUPERUSER_ID
from odoo.exceptions import ValidationError

_inherit = 'ir.attachment'
@api.multi
def unlink(self):
    for rec in self:
        if rec.res_model in ['sale.order', 'purchase.order'] and rec.res_id and self._uid != SUPERUSER_ID:
            raise ValidationError("Sorry, you are not allowed to delete the attachment.")
    return super(IrAttachment, self).unlink() ​   ​    ​   ​     ​   ​    ​   ​


頭像
捨棄
作者

Thank you Sudhir, it works for me!

相關帖文 回覆 瀏覽次數 活動
2
6月 24
1423
1
9月 21
4016
1
3月 19
8619
6
11月 24
9529
0
5月 20
2433