<commit_before># -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import api, fields, models


class CRMSettings(models.TransientModel):
    _inherit = 'sale.config.settings'

    generate_sales_team_alias = fields.Boolean("Automatically generate an email alias at the sales channel creation",
        help="Odoo will generate an email alias based on the sales channel name")
    alias_prefix = fields.Char('Default Alias Name for Leads')
    alias_domain = fields.Char('Alias Domain', default=lambda self: self.env["ir.config_parameter"].sudo().get_param("mail.catchall.domain"))
    # TDE TODO: as it is not linked to ir.values anymore, it should be renamed, but not in stable
    default_generate_lead_from_alias = fields.Boolean('Manual Assignation of Emails')
    group_use_lead = fields.Boolean(string="Leads", implied_group='crm.group_use_lead')
    module_crm_voip = fields.Boolean("Asterisk (VoIP)")

    def _find_default_lead_alias_id(self):
        alias = self.env.ref('crm.mail_alias_lead_info', False)
        if not alias:
            alias = self.env['mail.alias'].search([
                ('alias_model_id.model', '=', 'crm.lead'),
                ('alias_force_thread_id', '=', False),
                ('alias_parent_model_id.model', '=', 'crm.team'),
                ('alias_parent_thread_id', '=', False),
                ('alias_defaults', '=', '{}')
            ], limit=1)
        return alias

    @api.model
    def get_default_generate_sales_team_alias(self, fields):
        return {
            'generate_sales_team_alias': self.env['ir.values'].get_default('sale.config.settings', 'generate_sales_team_alias')
        }

    @api.multi
    def set_default_generate_sales_team_alias(self):
        IrValues = self.env['ir.values']
        if self.env['res.users'].has_group('base.group_erp_manager'):
            IrValues = IrValues.sudo()
        IrValues.set_default('sale.config.settings', 'generate_sales_team_alias', self.generate_sales_team_alias)

    @api.model
    def get_default_default_generate_lead_from_alias(self, fields):
        return {
            'default_generate_lead_from_alias': self.env['ir.config_parameter'].sudo().get_param('sale_config_settings.default_generate_lead_from_alias')
        }

    @api.multi
    def set_default_default_generate_lead_from_alias(self):
        self.env['ir.config_parameter'].sudo().set_param('sale_config_settings.default_generate_lead_from_alias', self.default_generate_lead_from_alias)

    @api.onchange('group_use_lead')
    def _onchange_group_use_lead(self):
        """ Reset alias / leads configuration if leads are not used """
        if not self.group_use_lead:
            self.default_generate_lead_from_alias = False

    @api.onchange('default_generate_lead_from_alias')
    def _onchange_default_generate_lead_from_alias(self):
        self.alias_prefix = 'info' if self.default_generate_lead_from_alias else False

    @api.model
    def get_default_alias_prefix(self, fields):
        alias = self._find_default_lead_alias_id()
        return {'alias_prefix': alias.alias_name if alias else False}

    @api.multi
    def set_default_alias_prefix(self):
        for record in self:
            alias = self._find_default_lead_alias_id()
            if alias:
                alias.write({'alias_name': record.alias_prefix})
            else:
                self.env['mail.alias'].with_context(alias_model_name='crm.lead', alias_parent_model_name='crm.team').create({'alias_name': record.alias_prefix})

        return True<commit_msg>[FIX] crm: setting alias_prefix easy reinited<commit_after># -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import api, fields, models


class CRMSettings(models.TransientModel):
    _inherit = 'sale.config.settings'

    generate_sales_team_alias = fields.Boolean("Automatically generate an email alias at the sales channel creation",
        help="Odoo will generate an email alias based on the sales channel name")
    alias_prefix = fields.Char('Default Alias Name for Leads')
    alias_domain = fields.Char('Alias Domain', default=lambda self: self.env["ir.config_parameter"].sudo().get_param("mail.catchall.domain"))
    # TDE TODO: as it is not linked to ir.values anymore, it should be renamed, but not in stable
    default_generate_lead_from_alias = fields.Boolean('Manual Assignation of Emails')
    group_use_lead = fields.Boolean(string="Leads", implied_group='crm.group_use_lead')
    module_crm_voip = fields.Boolean("Asterisk (VoIP)")

    def _find_default_lead_alias_id(self):
        alias = self.env.ref('crm.mail_alias_lead_info', False)
        if not alias:
            alias = self.env['mail.alias'].search([
                ('alias_model_id.model', '=', 'crm.lead'),
                ('alias_force_thread_id', '=', False),
                ('alias_parent_model_id.model', '=', 'crm.team'),
                ('alias_parent_thread_id', '=', False),
                ('alias_defaults', '=', '{}')
            ], limit=1)
        return alias

    @api.model
    def get_default_generate_sales_team_alias(self, fields):
        return {
            'generate_sales_team_alias': self.env['ir.values'].get_default('sale.config.settings', 'generate_sales_team_alias')
        }

    @api.multi
    def set_default_generate_sales_team_alias(self):
        IrValues = self.env['ir.values']
        if self.env['res.users'].has_group('base.group_erp_manager'):
            IrValues = IrValues.sudo()
        IrValues.set_default('sale.config.settings', 'generate_sales_team_alias', self.generate_sales_team_alias)

    @api.model
    def get_default_default_generate_lead_from_alias(self, fields):
        return {
            'default_generate_lead_from_alias': self.env['ir.config_parameter'].sudo().get_param('sale_config_settings.default_generate_lead_from_alias')
        }

    @api.multi
    def set_default_default_generate_lead_from_alias(self):
        self.env['ir.config_parameter'].sudo().set_param('sale_config_settings.default_generate_lead_from_alias', self.default_generate_lead_from_alias)

    @api.onchange('group_use_lead')
    def _onchange_group_use_lead(self):
        """ Reset alias / leads configuration if leads are not used """
        if not self.group_use_lead:
            self.default_generate_lead_from_alias = False

    @api.onchange('default_generate_lead_from_alias')
    def _onchange_default_generate_lead_from_alias(self):
        if self.default_generate_lead_from_alias:
            self.alias_prefix = self.alias_prefix or 'info'
        else:
            self.alias_prefix = False

    @api.model
    def get_default_alias_prefix(self, fields):
        alias = self._find_default_lead_alias_id()
        return {'alias_prefix': alias.alias_name if alias else False}

    @api.multi
    def set_default_alias_prefix(self):
        for record in self:
            alias = self._find_default_lead_alias_id()
            if alias:
                alias.write({'alias_name': record.alias_prefix})
            else:
                self.env['mail.alias'].with_context(alias_model_name='crm.lead', alias_parent_model_name='crm.team').create({'alias_name': record.alias_prefix})

        return True
{'fraction_non_alphanumeric': 0.11054863866466001, 'fraction_numerical': 0.0005472704884389109, 'mean_word_length': 3.4195888754534463, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7635662', 'n_tokens_mistral': 2291, 'n_tokens_neox': 2171, 'n_words': 409}