تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
6430 أدوات العرض

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
يونيو 24
1425
1
سبتمبر 21
4029
1
مارس 19
8622
6
نوفمبر 24
9535
0
مايو 20
2437