Skip to content
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

Compute the active company with attachments #165369

Open
ThiagoMForgeFlow opened this issue May 14, 2024 · 1 comment
Open

Compute the active company with attachments #165369

ThiagoMForgeFlow opened this issue May 14, 2024 · 1 comment
Labels
Logistics about stock, mrp, delivery, purchase

Comments

@ThiagoMForgeFlow
Copy link

Impacted versions:

15, 16, 17

Steps to reproduce:

  1. Create a record rule that does not allow editing a Purchase Order with a company other than the active one.
    2024-05-14_11-45
  2. Create a Purchase Order with the company that the user has by default.
  3. Mark all companies as available and select one as active other than the user.
    2024-05-14_12-06
  4. Try to attach an attachment to the Purchase Order.

Current behavior:

The system allows adding or deleting attachments without correctly evaluating the record rule.

Expected behavior:

With the record rule active, the system should not allow an attachment to be added since the active company does not match the company of the Purchase Order.

The value obtained from self.env.company is not correct, since it is returning the user's default company and not the one that is visually active.

def company(self):
        company_ids = self.context.get('allowed_company_ids', [])
        if company_ids:
            if not self.su:
                user_company_ids = self.user._get_company_ids()
                if set(company_ids) - set(user_company_ids):
                    raise AccessError(_("Access to unauthorized or invalid companies."))
            return self['res.company'].browse(company_ids[0])
        return self.user.company_id.with_env(self)

The value of allowed_company_ids is empty when it should not be.

Support ticket number submitted via odoo.com/help:

@vava-odoo vava-odoo added Logistics about stock, mrp, delivery, purchase labels May 17, 2024
@LoisRForgeFlow
Copy link
Contributor

Support ticket ID 3940230

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Logistics about stock, mrp, delivery, purchase
Projects
None yet
Development

No branches or pull requests

3 participants