From b8ca0c6985a5a3e87413aba8370d061f46f3c20b Mon Sep 17 00:00:00 2001 From: Deep Patel Date: Mon, 12 Jun 2017 19:12:59 +0530 Subject: [PATCH] [IMP] sales_team : assign the `Sales` channel on salesmen creation Purpose ======= When a new sales user is created, user is not in any team. The dashboard doesn't make any sense and he wouldn't know how to start working Specification ============= On salesman creation, the user should be assign to a Sales channel IF there is only one sales team of this type. --- addons/sales_team/models/res_users.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/addons/sales_team/models/res_users.py b/addons/sales_team/models/res_users.py index e73cf3e1590..325664abae6 100644 --- a/addons/sales_team/models/res_users.py +++ b/addons/sales_team/models/res_users.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo import fields, models +from odoo import api, fields, models class ResUsers(models.Model): @@ -10,3 +10,13 @@ class ResUsers(models.Model): sale_team_id = fields.Many2one( 'crm.team', 'Sales Channel', help='Sales Channel the user is member of. Used to compute the members of a sales channel through the inverse one2many') + + @api.model + def create(self, vals): + # Assign the new user in the sales team if there's only one sales team of type `Sales` + user = super(ResUsers, self).create(vals) + if user.has_group('sales_team.group_sale_salesman') and not user.sale_team_id: + teams = self.env['crm.team'].search([('team_type', '=', 'sales')]) + if len(teams.ids) == 1: + user.sale_team_id = teams.id + return user