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

[IMP] default_warehouse_from_sale_team: hook to fill allowed sales teams T#79454 #1673

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions default_warehouse_from_sale_team/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import models
from .hooks import post_init_hook
1 change: 1 addition & 0 deletions default_warehouse_from_sale_team/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"demo/stock_warehouse_demo.xml",
"demo/crm_team_demo.xml",
],
"post_init_hook": "post_init_hook",
"installable": True,
"application": False,
"auto_install": False,
Expand Down
25 changes: 25 additions & 0 deletions default_warehouse_from_sale_team/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import logging

_logger = logging.getLogger(__name__)


def post_init_hook(env):
fill_user_allowed_salesteams(env)


def fill_user_allowed_salesteams(env):
"""Fill allowed sales teams in users that are already members of any team.

Since this module implements a feature to restrict which sales teams a user may be a member of, users that already
belong to any team are configured to be allowed for those teams, to avoid inconsistencies between allowed and
already-configured memberships. In other words, if a user already belongs to a team, it most likely means they
should be allowed to belong to it, so allowance is granted.
"""
teams_per_user = env["crm.team.member"]._read_group(
domain=[],
groupby=["user_id"],
aggregates=["crm_team_id:recordset"],
)
for user, teams in teams_per_user:
user.sale_team_ids |= teams
_logger.info("Field 'Allowed sales Teams' has been set to %d users.", len(teams_per_user))
Loading