Skip to content

[16.0] mrp_bom_hierarchy: Permission error when viewing BoM with read-only access #1488

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
marco-lucaf opened this issue Feb 27, 2025 · 0 comments
Labels

Comments

@marco-lucaf
Copy link

marco-lucaf commented Feb 27, 2025

Module

mrp_bom_hierarchy

Describe the bug

When trying to display a BoM in read-only mode to a user with limited permissions, odoo raises a permission error stating that the user needs write access to mrp.bom.line, even though they're only trying to view the bom.

To Reproduce

Affected versions:

  • Odoo 16.0 (with mrp_bom_hierarchy module installed)

Steps to reproduce the behavior:

  1. Create a user with read-only access to BoMs (without write permissions on mrp.bom.line)
  2. Try to view a BoM with this user
  3. An access error is raised when the system tries to compute the "has_bom" field

Expected behavior
Users with read-only access should be able to view the BoM hierarchy without encountering permission errors.

Additional context
The issue is in the _compute_has_bom method. When computing whether a BoM line has a sub-BoM, the system tries to access information that requires elevated permissions.

Proposed solution

Adding sudo() to the _compute_has_bom method solves the issue by temporarily elevating the permissions for this specific operation:

@api.depends("product_id", "bom_id")     
def _compute_has_bom(self):         
    self = self.sudo()         
    res = super()._compute_child_bom_id()
        for line in self:
            line.has_bom = bool(line.child_bom_id)
        return res

This allows read-only users to view the BoM hierarchy while maintaining proper security restrictions elsewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant