flectra/addons/sales_team/models/res_users.py

23 lines
867 B
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2018-01-16 11:34:37 +01:00
# Part of Odoo, Flectra. See LICENSE file for full copyright and licensing details.
2018-01-16 11:34:37 +01:00
from flectra import api, fields, models
class ResUsers(models.Model):
_inherit = 'res.users'
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