-
Notifications
You must be signed in to change notification settings - Fork 287
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] default_warehouse_from_sale_team: hook to fill allowed sales teams
Implement a hook to fill allowed sales teams in users that are already a member 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.
- Loading branch information
Showing
3 changed files
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from . import models | ||
from .hooks import post_init_hook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |