Example #1
0
 def _get_alias_values(self, type, alias_name=None):
     if not alias_name:
         alias_name = self.name
         if self.company_id != self.env.ref('base.main_company'):
             alias_name += '-' + str(self.company_id.name)
     try:
         remove_accents(alias_name).encode('ascii')
     except UnicodeEncodeError:
         try:
             remove_accents(self.code).encode('ascii')
             safe_alias_name = self.code
         except UnicodeEncodeError:
             safe_alias_name = self.type
         _logger.warning("Cannot use '%s' as email alias, fallback to '%s'",
                         alias_name, safe_alias_name)
         alias_name = safe_alias_name
     return {
         'alias_defaults': {
             'move_type': type == 'purchase' and 'in_invoice'
             or 'out_invoice',
             'company_id': self.company_id.id,
             'journal_id': self.id
         },
         'alias_parent_thread_id': self.id,
         'alias_name': alias_name,
     }
Example #2
0
 def _jitsi_sanitize_name(self, name):
     sanitized = re.sub(r'[^\w+.]+', '-', remove_accents(name).lower())
     counter, sanitized_suffixed = 1, sanitized
     existing = self.env['chat.room'].search([
         ('name', '=like', '%s%%' % sanitized)
     ]).mapped('name')
     while sanitized_suffixed in existing:
         sanitized_suffixed = '%s-%d' % (sanitized, counter)
         counter += 1
     return sanitized_suffixed
Example #3
0
    def _clean_and_check_unique(self, name):
        """When an alias name appears to already be an email, we keep the local
        part only. A sanitizing / cleaning is also performed on the name. If
        name already exists an UserError is raised. """
        sanitized_name = remove_accents(name).lower().split('@')[0]
        sanitized_name = re.sub(r'[^\w+.]+', '-', sanitized_name)
        sanitized_name = sanitized_name.encode('ascii',
                                               errors='replace').decode()

        catchall_alias = self.env['ir.config_parameter'].sudo().get_param(
            'mail.catchall.alias')
        bounce_alias = self.env['ir.config_parameter'].sudo().get_param(
            'mail.bounce.alias')
        domain = [('alias_name', '=', sanitized_name)]
        if self:
            domain += [('id', 'not in', self.ids)]
        if sanitized_name in [catchall_alias, bounce_alias
                              ] or self.search_count(domain):
            raise UserError(
                _('The e-mail alias is already used. Please enter another one.'
                  ))
        return sanitized_name
Example #4
0
 def test_non_latin(self):
     self.assertEqual(remove_accents('العربية'), 'العربية')
     self.assertEqual(remove_accents('русский алфавит'), 'русскии алфавит')
Example #5
0
 def test_latin(self):
     self.assertEqual(remove_accents('Niño Hernández'), 'Nino Hernandez')
     self.assertEqual(remove_accents('Anaïs Clémence'), 'Anais Clemence')
Example #6
0
 def test_empty_string(self):
     self.assertEqual(remove_accents(False), False)
     self.assertEqual(remove_accents(''), '')
     self.assertEqual(remove_accents(None), None)