Skip to content

[18.0][FIX] brand: Default Company for Correct Brand Validation on wizards #255

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
wants to merge 1 commit into
base: 18.0
Choose a base branch
from

Conversation

bosd
Copy link
Contributor

@bosd bosd commented May 16, 2025

Defaults the company_id field on the product.pricelist.print wizard to self.env.company.

Problem:

The brand requirement validation, which is handled by the res.brand.mixin and configured via the brand_use_level field on res.company, was not consistently being enforced on the "Print Pricelist" wizard (product.pricelist.print).

When a company's brand_use_level was set to 'required', the wizard did not reliably:

  1. Make the brand_id field mandatory in the user interface (UI).
  2. Prevent the user from proceeding if a brand_id was not selected, by raising a ValidationError.

This was primarily due to the company_id field on the product.pricelist.print wizard instance (inherited from res.brand.mixin) not having an explicit default value. As a result, the related brand_use_level field on the wizard might not compute its value correctly at the moment of wizard creation or when UI attributes were determined. This could lead to the mixin's @api.constrains (like _check_brand_requirement) and its _get_view method (which sets UI properties) not functioning with the intended company context.

Solution:

This pull request addresses the issue by explicitly setting a default value for the company_id field within our inherited ProductPricelistPrint model. The company_id now defaults to the current user's company:

More models might benefit from this change as we encountered inconsistent behaviour on the sale_brand module as well.

Defaults the `company_id` field on the `product.pricelist.print` wizard to `self.env.company`.

This ensures that the `brand_use_level` field (which is related to `company_id.brand_use_level`) is correctly computed upon wizard initialization. Consequently, the brand requirement checks (Python constraints like `_check_brand_requirement`) and UI adjustments (dynamic 'required' or 'invisible' attributes on `brand_id` field via `_get_view`) inherited from the `res.brand.mixin` can function as intended.

Without this explicit default, the mixin's logic might not have the correct company context immediately upon wizard load, potentially leading to brand requirement rules not being enforced as expected.
@OCA-git-bot
Copy link
Contributor

Hi @sbejaoui,
some modules you are maintaining are being modified, check this out!

@bosd bosd marked this pull request as ready for review May 16, 2025 16:01
@bosd bosd changed the title [FIX] brand: Default Company for Correct Brand Validation on wizards [18.0][FIX] brand: Default Company for Correct Brand Validation on wizards May 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants