<commit_before># -*- coding: utf-8 -*-
###############################################################################
#
# ODOO (ex OpenERP) 
# Open Source Management Solution
# Copyright (C) 2001-2015 Micronaet S.r.l. (<http://www.micronaet.it>)
# Developer: <NAME> @thebrush (<https://it.linkedin.com/in/thebrush>)
# 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 os
import sys
import logging
import openerp
import openerp.addons.decimal_precision as dp
from openerp.osv import fields, osv, expression, orm
from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta
from openerp import SUPERUSER_ID
from openerp import tools
from openerp.tools.translate import _
from openerp.tools import (DEFAULT_SERVER_DATE_FORMAT, 
    DEFAULT_SERVER_DATETIME_FORMAT, 
    DATETIME_FORMATS_MAP, 
    float_compare)


_logger = logging.getLogger(__name__)


class ResPartnerUniqueNameWizard(orm.TransientModel):
    ''' Wizard for unify partner with name
    '''
    _name = 'res.partner.unique.name.wizard'

    # --------------------
    # Wizard button event:
    # --------------------
    def unify_all_terms(self, cr, uid, ids, context=None):
        ''' Search terms not used
            Try to unify other
        '''
        _logger.info('Start unify terms:')

        term_pool = self.pool.get(
            'fashion.form.characteristic.rel.specific')
        term_ids = term_pool.search(cr, uid, [], order='id', 
            context=context)
        
        term_double = {}
        unify_name = []
        exclude = [u'User', u'Accounting', u'Production']
        _logger.info('Create database of double:')
        
        for term in term_pool.browse(
                cr, uid, term_ids, context=context):
            if term.name in exclude:
                continue    
            if term.name in term_double:
                # DB (name) = (keep id, remove ids)
                term_double[term.name][1].append(term.id)
                if term.name not in unify_name:
                    unify_name.append(term.name)
            else:    
                term_double[term.name] = [term.id, []]

        _logger.info('Correct query data:')

        query_db = (
            ('fashion_form_characteristic_rel', 'stitch_cut_id'),
            ('fashion_form_characteristic_rel', 'stitch_top_id'),
            ('fashion_form_characteristic_rel', 'stitch_top_type_id'),
            ('fashion_form_characteristic_rel', 'stitch_type_id'),
            ('fashion_form_characteristic_rel', 'stitch_verse_id'),
            )
        deactivate_ids = []        
        
        for name in unify_name:
            keep_id, remove_ids = term_double[name]
            
            for table, field in query_db:
                query = 'UPDATE %s SET %s = %s WHERE %s in %s;' % (
                    table, field, keep_id, field, tuple(remove_ids), 
                    )
                query = query.replace(',)', ')')    
                try:    
                    _logger.info(query)
                    cr.execute(query)                
                except:
                    _logger.error('%s %s' % (table, field))

            deactivate_ids.extend(remove_ids)

        term_pool.write(cr, uid, deactivate_ids, {<commit_msg>correct procedure for double terms<commit_after># -*- coding: utf-8 -*-
###############################################################################
#
# ODOO (ex OpenERP) 
# Open Source Management Solution
# Copyright (C) 2001-2015 Micronaet S.r.l. (<http://www.micronaet.it>)
# Developer: <NAME> @thebrush (<https://it.linkedin.com/in/thebrush>)
# 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 os
import sys
import logging
import openerp
import openerp.addons.decimal_precision as dp
from openerp.osv import fields, osv, expression, orm
from datetime import datetime, timedelta
from dateutil.relativedelta import relativedelta
from openerp import SUPERUSER_ID
from openerp import tools
from openerp.tools.translate import _
from openerp.tools import (DEFAULT_SERVER_DATE_FORMAT, 
    DEFAULT_SERVER_DATETIME_FORMAT, 
    DATETIME_FORMATS_MAP, 
    float_compare)


_logger = logging.getLogger(__name__)


class ResPartnerUniqueNameWizard(orm.TransientModel):
    ''' Wizard for unify partner with name
    '''
    _name = 'res.partner.unique.name.wizard'

    # --------------------
    # Wizard button event:
    # --------------------
    def unify_all_terms(self, cr, uid, ids, context=None):
        ''' Search terms not used
            Try to unify other
        '''
        _logger.info('Start unify terms:')

        term_pool = self.pool.get(
            'fashion.form.characteristic.rel.specific')
        term_ids = term_pool.search(cr, uid, [], order='id', 
            context=context)
        
        term_double = {}
        unify_name = []
        _logger.info('Create database of double:')
        
        for term in term_pool.browse(
                cr, uid, term_ids, context=context):
            k = (term.name, term.type)
            if k in term_double:
                term_double[k][1].append(term.id)
                if k not in unify_name:
                    unify_name.append(k)
            else:    
                term_double[k] = [term.id, []]

        _logger.info('Correct query data:')

        query_db = (
            ('fashion_form_characteristic_rel', 'stitch_cut_id'),
            ('fashion_form_characteristic_rel', 'stitch_top_id'),
            ('fashion_form_characteristic_rel', 'stitch_top_type_id'),
            ('fashion_form_characteristic_rel', 'stitch_type_id'),
            ('fashion_form_characteristic_rel', 'stitch_verse_id'),
            )
        deactivate_ids = []        
        
        for k in unify_name:
            keep_id, remove_ids = term_double[k]
            
            for table, field in query_db:
                query = 'UPDATE %s SET %s = %s WHERE %s in %s;' % (
                    table, field, keep_id, field, tuple(remove_ids), 
                    )
                query = query.replace(',)', ')')    
                try:    
                    _logger.info(query)
                    cr.execute(query)                
                except:
                    _logger.error('%s %s' % (table, field))

            deactivate_ids.extend(remove_ids)

        term_pool.write(cr, uid, deactivate_ids, {
{'fraction_non_alphanumeric': 0.14110508649625614, 'fraction_numerical': 0.0028401755744900596, 'mean_word_length': 2.314933675652546, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 4, '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': '3002306', 'n_tokens_mistral': 2237, 'n_tokens_neox': 2095, 'n_words': 606}