Skip to content

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.

@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
@bosd
Copy link
Contributor Author

bosd commented Sep 11, 2025

@max3903 Can you please merge?

@yvaucher
Copy link
Member

/ocabot merge patch

@OCA-git-bot
Copy link
Contributor

On my way to merge this fine PR!
Prepared branch 18.0-ocabot-merge-pr-255-by-yvaucher-bump-patch, awaiting test results.

OCA-git-bot added a commit that referenced this pull request Sep 17, 2025
Signed-off-by yvaucher
@OCA-git-bot
Copy link
Contributor

@yvaucher your merge command was aborted due to failed check(s), which you can inspect on this commit of 18.0-ocabot-merge-pr-255-by-yvaucher-bump-patch.

After fixing the problem, you can re-issue a merge command. Please refrain from merging manually as it will most probably make the target branch red.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants