Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
6403 มุมมอง

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!

Related Posts ตอบกลับ มุมมอง กิจกรรม
2
มิ.ย. 24
1419
1
ก.ย. 21
4004
Error in odoo12 community แก้ไขแล้ว
1
มี.ค. 19
8610
[v12] Restore deleted superadmin user แก้ไขแล้ว
6
พ.ย. 24
9515
0
พ.ค. 20
2422