Skip to content

[18.0][FIX] sales_team_operating_unit: Add default company_id#856

Open
solomonprabu wants to merge 4 commits into
OCA:18.0from
solomonprabu:18.0-fix-sales_team_operating_unit
Open

[18.0][FIX] sales_team_operating_unit: Add default company_id#856
solomonprabu wants to merge 4 commits into
OCA:18.0from
solomonprabu:18.0-fix-sales_team_operating_unit

Conversation

@solomonprabu
Copy link
Copy Markdown

Adding default company to resolve incompatible records error coming up while creating sales team, when a user doesn't have multi-company access.

Warning

image

…compatible records error coming up while creating sales team, when a user doesn't have multicompany access while creating sales team
@OCA-git-bot OCA-git-bot added series:18.0 mod:sales_team_operating_unit Module sales_team_operating_unit labels May 21, 2026
Copy link
Copy Markdown
Contributor

@AaronHForgeFlow AaronHForgeFlow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you modify the _get_default_operating_unit function instead?

or Have you considered an onchange on operating_unit_id?

@AaronHForgeFlow AaronHForgeFlow self-requested a review May 21, 2026 11:30
@solomonprabu
Copy link
Copy Markdown
Author

Why don't you modify the _get_default_operating_unit function instead?

or Have you considered an onchange on operating_unit_id?

Thank you for the suggestions. I evaluated both approaches also a third approach, but decided on overriding default_get for the following reasons:

  1. Modifying _get_default_operating_unit: While this would inject the default value, altering a method explicitly named for operating units to compute or handle base company logic breaks the single-responsibility principle and reduces code readability. Overriding default_get keeps the initialization logic clean and centralized.
  2. Using an onchange method: Since the operating unit domain is already restricted to the user's current company, an onchange would introduce unnecessary RPC overhead and redundant computations during UI interactions. Also if the user decides to go with the default OU, the onchange method is left untriggered. All these makes it a less desirable approach.
  3. Alternative (default attribute): Ideally, defining a default attribute directly on the company_id field would be the cleanest solution. However, since company_id is inherited from the Odoo core crm.team model, we cannot safely modify its attribute directly without risk of overriding core behavior or creating inheritance conflicts.

IMHO Overriding default_get is the most robust and standard Odoo approach here, especially since company_id remains invisible for users without multi-company privileges (base.group_multi_company), meaning the field relies entirely on backend initialization.

Copy link
Copy Markdown
Contributor

@AaronHForgeFlow AaronHForgeFlow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks for the explanation. Please leave one commit only

…compatible records error coming up while creating sales team, when a user doesn't have multicompany access while creating sales team
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:sales_team_operating_unit Module sales_team_operating_unit series:18.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants