<commit_before># -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Addons modules by CLEARCORP S.A.
#    Copyright (C) 2009-TODAY CLEARCORP S.A. (<http://clearcorp.co.cr>).
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from osv import osv, fields
from openerp.tools import translate

class account_account(osv.osv):
    _name = "account.account"
    _inherit = "account.account"
    
    #Change the way that the user can see the account when is search in a many2one field.
    #Add the company prefix in the name of the company and the shortcurt of the parent's account.
    def name_get(self, cr, uid, ids, context=None):
        if not ids:
            return []
        res = []
        for obj_account in self.browse(cr,uid,ids):
            obj_company = self.pool.get('res.company').browse(cr,uid,obj_account.company_id.id)
            #If the company of the account have prefix, add in the account's name. 
            prefix= obj_company.prefix
            if prefix == False:
                prefix = ''
            data = []
            account = obj_account.parent_id
            #Add the parent's name shortcut.
            if account.parent_id:
                while account.parent_id:
                    data.insert(0,(account.shortcut or account.name))
                    account = account.parent_id
                data.append(obj_account.name)
                data = '/'.join(data)
                data = obj_account.code + ' ' + data
                data = prefix and prefix + '-' + data or data
            else:
                #If there not exist a parent, concat the account's name. 
                data.append(obj_account.name)
                data = '/'.join(data)
                data = prefix and prefix + ' ' + data or data
            res.append((obj_account.id, data))
        return res
    
    
    #Add the company prefix and the regular expression that permit search include the special characteres.    
    def name_search(self, cr, uid, name, args=None, operator='ilike', context=None, limit=100):
        regular_expresion = '[-_.\s]*'
        ids = []
        list = []
        account_ids = []
                
        if not args:
            args = []       
            
        if name:           
            company_ids = self.pool.get('res.company').search(cr, uid, [])
            code_regular = ''
            code = name.replace('-', '').replace('_','').replace('.','').replace(' ','') #replace special characteres
            for c in code:
                code_regular += c + regular_expresion #add the regular expression to the name
                 
            ids = self.search(cr, uid, [('code', '=like', code_regular)]+args, limit=limit)
            if not ids:
                ids = self.search(cr, uid, [('shortcut', '=', name)]+ args, limit=limit)
            if not ids:
                ids = self.search(cr, uid, [('name', operator, name)]+ args, limit=limit)
                                       
            for company in self.pool.get('res.company').browse(cr, uid, company_ids):
                prefix = company.prefix
                if prefix != False:
                    if name.lower().find(prefix) == 0:
                        len_sub = len(company.prefix) #Find the size of the prefix
                        code = name[len_sub:]   #Create a substring without the prefix
                        new_name = name[len_sub:] #Save the original name without the prefix to search the name and the shortcut
                        
                        code = code.replace('-', '').replace('_','').replace('.','').replace(' ','')
                        code_regular_prefix = ''
                        
                        for c in code:
                            code_regular_prefix += c + regular_expresion
                        
                        list += ['&',('company_id','=', company.name), ('code', '=like', code_regular_prefix)]
                        list += ['&',('company_id','=', company.name), ('shortcut', 'ilike', new_name)]
                        list += ['&',('company_id','=', company.name), ('name', operator, new_name)]
                    
            ids += self.search(cr, uid, list + args, limit=limit)
            #If any account are repeat
            for account in ids:
                if account not in account_ids:
                    account_ids.append(account)
                         
        return self.name_get(cr, uid, account_ids, context=context) #search the names that match with the ids.

class account_journal(osv.osv):
    _name = "account.journal"
    _inherit = "account.journal"    
    
    #Add the company prefix to the journal name.
    def name_get(self, cr, user, ids, context=None):<commit_msg>[MRG] Fix name_search method for account_account object<commit_after># -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Addons modules by CLEARCORP S.A.
#    Copyright (C) 2009-TODAY CLEARCORP S.A. (<http://clearcorp.co.cr>).
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as
#    published by the Free Software Foundation, either version 3 of the
#    License, or (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

import re
from osv import osv, fields
from openerp.tools import translate

class account_account(osv.osv):
    _name = "account.account"
    _inherit = "account.account"
    
    #Change the way that the user can see the account when is search in a many2one field.
    #Add the company prefix in the name of the company and the shortcurt of the parent's account.
    def name_get(self, cr, uid, ids, context=None):
        if not ids:
            return []
        res = []
        for obj_account in self.browse(cr,uid,ids):
            obj_company = self.pool.get('res.company').browse(cr,uid,obj_account.company_id.id)
            #If the company of the account have prefix, add in the account's name. 
            prefix= obj_company.prefix
            if prefix == False:
                prefix = ''
            data = []
            account = obj_account.parent_id
            #Add the parent's name shortcut.
            if account.parent_id:
                while account.parent_id:
                    data.insert(0,(account.shortcut or account.name))
                    account = account.parent_id
                data.append(obj_account.name)
                data = '/'.join(data)
                data = obj_account.code + ' ' + data
                data = prefix and prefix + '-' + data or data
            else:
                #If there not exist a parent, concat the account's name. 
                data.append(obj_account.name)
                data = '/'.join(data)
                data = prefix and prefix + ' ' + data or data
            res.append((obj_account.id, data))
        return res
    
    
    #Add the company prefix and the regular expression that permit search include the special characteres.    
    def name_search(self, cr, uid, name, args=None, operator='ilike', context=None, limit=100):
        ids =  list = account_ids = ids_company = []
        code = code_regular = new_code = ''        
        regular_expresion = '%'
        
        if not args:
            args = []       
            
        if name:           
            company_ids = self.pool.get('res.company').search(cr, uid, [])
            code = name 
            code = code.replace('-','').replace('_', '').replace('.','').replace(' ','')
           
            for c in code:
                new_code += c + regular_expresion            
                
            ids += self.search(cr, uid, [('code', 'ilike', new_code)], limit=limit)
        
            ids+= self.search(cr, uid, [('shortcut', '=', name)], limit=limit)
       
            ids+= self.search(cr, uid, [('name', operator, name)], limit=limit)
                                       
            for company in self.pool.get('res.company').browse(cr, uid, company_ids):
                prefix = company.prefix
                if prefix != False:
                    if name.lower().find(prefix) == 0:
                        len_sub = len(company.prefix) #Find the size of the prefix
                        code = name[len_sub:]   #Create a substring without the prefix
                        new_name = name[len_sub:] #Save the original name without the prefix to search the name and the shortcut
                        
                        code.replace('-','').replace('_', '').replace('.','').replace(' ','')
                        
                        for c in code:
                            code_regular += c + regular_expresion
                        
                        list += ['&',('company_id','=', company.name), ('code', '=like', code_regular)]                            
                        list += ['&',('company_id','=', company.name), ('shortcut', '=', new_name)]
                        list += ['&',('company_id','=', company.name), ('name', operator, new_name)]
                        
                        ids_company = self.search(cr, uid, list, limit=limit)
                        ids += ids_company

            #If any account are repeat
            for account in ids:
                if account not in account_ids:
                    account_ids.append(account)
                         
        return self.name_get(cr, uid, account_ids, context=context) #search the names that match with the ids.

class account_journal(osv.osv):
    _name = "account.journal"
    _inherit = "account.journal"    
    
    #Add the company prefix to the journal name.
    def name_get(self, cr, user, ids, context=None):
{'fraction_non_alphanumeric': 0.13136126595935982, 'fraction_numerical': 0.002157885272433016, 'mean_word_length': 1.8060040363269425, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '666369', 'n_tokens_mistral': 2948, 'n_tokens_neox': 2815, 'n_words': 945}