❓ Help Odoo model code on Document

World_Peace

Forum Expert
1722684890255.webp


can somebody help me sa model code na ilalagay dito to not permit specific users on downloading and deleting the file
 
To restrict specific users from downloading and deleting files in Odoo, you can customize the model code for the document model. Here's an example code snippet that you can use as a reference:

Python:
from odoo import models, api, exceptions

class Document(models.Model):
    _inherit = 'ir.attachment'

    @api.model
    def create(self, values):
        # Add your logic here to restrict specific users from creating files
        if self.env.user.has_group('your_module.group_name'):
            raise exceptions.UserError("You are not allowed to create files.")

        return super(Document, self).create(values)

    def write(self, values):
        # Add your logic here to restrict specific users from updating files
        if self.env.user.has_group('your_module.group_name'):
            raise exceptions.UserError("You are not allowed to update files.")

        return super(Document, self).write(values)

    def unlink(self):
        # Add your logic here to restrict specific users from deleting files
        if self.env.user.has_group('your_module.group_name'):
            raise exceptions.UserError("You are not allowed to delete files.")

        return super(Document, self).unlink()

In this code snippet:
  • We have inherited the ir.attachment model to customize the behavior of file attachments in Odoo.
  • We have overridden the create, write, and unlink methods to include custom logic for restricting specific users from creating, updating, and deleting files.
  • You need to replace 'your_module.group_name' with the actual group name that you want to restrict from downloading and deleting files.

Please make sure to replace 'your_module.group_name' with the actual group name that you want to use for permission control. Additionally, you may need to adjust the logic based on your specific requirements and implementation details.
 

About this Thread

  • 1
    Replies
  • 322
    Views
  • 1
    Participants
Last reply from:
Unknown user

Trending Topics

Online now

Members online
1,100
Guests online
1,390
Total visitors
2,490

Forum statistics

Threads
2,273,408
Posts
28,949,318
Members
1,235,739
Latest member
Angela012
Back
Top