<commit_before># -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
#    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 fields, osv
import sugar
import sugarcrm_fields_mapping

def import_users(self, cr, uid, context=None):
    if not context:
        context = {}
    map_user = {'Users': 
           {'name': ['first_name', 'last_name'], 
           'login': 'user_name',
           'new_password' : '<PASSWORD>',
           } ,
       }
    user_obj = self.pool.get('res.users')
    ids = self.search(cr, uid, [])
    PortType,sessionid = sugar.login(context.get('username',''), context.get('password',''))
    sugar_data = sugar.search(PortType,sessionid, 'Users')
    for val in sugar_data:
        user_ids = user_obj.search(cr, uid, [('login', '=', val.get('user_name'))])
        if user_ids:
            return user_ids[0]
        fields, datas = sugarcrm_fields_mapping.sugarcrm_fields_mapp(val, 'Users', map_user)
        openerp_val = dict(zip(fields,datas))
        openerp_val['context_lang'] = context.get('lang','en_US')
        new_user_id = user_obj.create(cr, uid, openerp_val, context)
    return new_user_id    
  
def get_lead_status(self, cr, uid, sugar_val,context=None):
    if not context:
       context = {}  
    stage_id = ''          
    stage_dict = {'status': #field in the sugarcrm database
             { #Mapping of sugarcrm stage : openerp opportunity stage 
                'New' : 'New',
                'Assigned':'Qualification',
               'In Progress': 'Proposition',
               'Recycled': 'Negotiation',
               'Dead': 'Lost'
            },}  
    stage = stage_dict['status'].get(sugar_val['status'], '')
    lead_pool = self.pool.get("crm.lead")
    stage_pool = self.pool.get('crm.case.stage')
    stage_ids = stage_pool.search(cr, uid, [("type", '=', 'lead'), ('name', '=', stage)])
    for stage in stage_pool.browse(cr, uid, stage_ids, context):
        stage_id = stage.id         
    return stage_id

def get_opportunity_status(self, cr, uid, sugar_val,context=None):
    if not context:
       context = {} 
    stage_id = ''           
    stage_dict = {'sales_stage': #field in the sugarcrm database
             { #Mapping of sugarcrm stage : openerp opportunity stage Mapping
                'Need Analysis': 'New',
                'Closed Lost': 'Lost',
               'Closed Won': 'Won',
               'Value Proposition': 'Proposition',
               'Negotiation/Review': 'Negotiation'
            },}  
    stage = stage_dict['sales_stage'].get(sugar_val['sales_stage'], '')
    lead_pool = self.pool.get("crm.lead")
    stage_pool = self.pool.get('crm.case.stage')
    stage_ids = stage_pool.search(cr, uid, [("type", '=', 'opportunity'), ('name', '=', stage)])
    for stage in stage_pool.browse(cr, uid, stage_ids, context):
        stage_id = stage.id         
    return stage_id
  
def import_leads(self, cr, uid, context=None):
   if not context:
       context = {} 
   user_id = import_users(self, cr, uid, context) 
   map_lead = {               
            'Leads':{'name': ['first_name','last_name'],
                   'contact_name': ['first_name','last_name'],
                   'description': 'description',
                   'partner_name': ['first_name','last_name'],
                   'email_from': 'email1',
                   'phone': 'phone_work',
                   'mobile': 'phone_mobile',
                   'write_date':'date_modified',
                   'function':'title',
                   'street': 'primary_address_street',
                   'zip': 'primary_address_postalcode',
                   'city':'primary_address_city',
                  },
               }
      
   ids = self.search(cr, uid, [])
   lead_pool = self.pool.get('crm.lead')
   PortType,sessionid = sugar.login(context.get('username',''), context.get('password',''))
   sugar_data = sugar.search(PortType,sessionid, 'Leads')
   for val in sugar_data:
       fields, datas = sugarcrm_fields_mapping.sugarcrm_fields_mapp(val, 'Leads', map_lead)
       stage_id = get_lead_status(self, cr, uid, val, context)
       openerp_val = dict(zip(fields,datas))
       openerp_val['type'] = 'lead'
       openerp_val['user_id'] = user_id
       openerp_val['stage_id'] = stage_id
       new_lead_id = lead_pool.create(cr, uid, openerp_val, context)
   return new_lead_id    
        
def import_opportunities(self, cr, uid, context=None):
   if not context:
       context = {} 
   user_id = import_users(self, cr, uid, context) 
   map_opportunity = {'Opportunities':  {'name': 'name',
          'probability': 'probability',
          'planned_revenue': 'amount_usdollar',
          'date_deadline':'date_closed'
          },
      }
   ids = self.search(cr, uid, [])
   lead_pool = self.pool.get('crm.lead')
   PortType,sessionid = sugar.login(context.get('username',''), context.get('password',''))
   sugar_data = sugar.search(PortType,sessionid, 'Opportunities')
   for val in sugar_data:
       fields, datas = sugarcrm_fields_mapping.sugarcrm_fields_mapp(val, 'Opportunities', map_opportunity)
       stage_id = get_opportunity_status(self, cr, uid, val, context)
       openerp_val = dict(zip(fields,datas))
       openerp_val['type'] = 'opportunity'
       openerp_val['user_id'] = user_id
       openerp_val['stage_id'] = stage_id
       new_opportunity_id = lead_pool.create(cr, uid, openerp_val, context)
   return new_opportunity_id           <commit_msg>[FIX]: correct buildbots warning for sugarcrm.<commit_after># -*- coding: utf-8 -*-
##############################################################################
#
#    OpenERP, Open Source Management Solution
#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
#    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 fields, osv
import sugar
import sugarcrm_fields_mapping

def import_users(self, cr, uid, context=None):
    if not context:
        context = {}
    map_user = {'Users': 
           {'name': ['first_name', 'last_name'], 
           'login': 'user_name',
           'new_password' : '<PASSWORD>',
           } ,
       }
    user_obj = self.pool.get('res.users')
    PortType,sessionid = sugar.login(context.get('username',''), context.get('password',''))
    sugar_data = sugar.search(PortType,sessionid, 'Users')
    for val in sugar_data:
        user_ids = user_obj.search(cr, uid, [('login', '=', val.get('user_name'))])
        if user_ids:
            return user_ids[0]
        fields, datas = sugarcrm_fields_mapping.sugarcrm_fields_mapp(val, 'Users', map_user)
        openerp_val = dict(zip(fields,datas))
        openerp_val['context_lang'] = context.get('lang','en_US')
        new_user_id = user_obj.create(cr, uid, openerp_val, context)
    return new_user_id    
  
def get_lead_status(self, cr, uid, sugar_val,context=None):
    if not context:
       context = {}  
    stage_id = ''          
    stage_dict = {'status': #field in the sugarcrm database
             { #Mapping of sugarcrm stage : openerp opportunity stage 
                'New' : 'New',
                'Assigned':'Qualification',
               'In Progress': 'Proposition',
               'Recycled': 'Negotiation',
               'Dead': 'Lost'
            },}  
    stage = stage_dict['status'].get(sugar_val['status'], '')
    stage_pool = self.pool.get('crm.case.stage')
    stage_ids = stage_pool.search(cr, uid, [("type", '=', 'lead'), ('name', '=', stage)])
    for stage in stage_pool.browse(cr, uid, stage_ids, context):
        stage_id = stage.id         
    return stage_id

def get_opportunity_status(self, cr, uid, sugar_val,context=None):
    if not context:
       context = {} 
    stage_id = ''           
    stage_dict = {'sales_stage': #field in the sugarcrm database
             { #Mapping of sugarcrm stage : openerp opportunity stage Mapping
                'Need Analysis': 'New',
                'Closed Lost': 'Lost',
               'Closed Won': 'Won',
               'Value Proposition': 'Proposition',
               'Negotiation/Review': 'Negotiation'
            },}  
    stage = stage_dict['sales_stage'].get(sugar_val['sales_stage'], '')
    stage_pool = self.pool.get('crm.case.stage')
    stage_ids = stage_pool.search(cr, uid, [("type", '=', 'opportunity'), ('name', '=', stage)])
    for stage in stage_pool.browse(cr, uid, stage_ids, context):
        stage_id = stage.id         
    return stage_id
  
def import_leads(self, cr, uid, context=None):
   if not context:
       context = {} 
   user_id = import_users(self, cr, uid, context) 
   map_lead = {               
            'Leads':{'name': ['first_name','last_name'],
                   'contact_name': ['first_name','last_name'],
                   'description': 'description',
                   'partner_name': ['first_name','last_name'],
                   'email_from': 'email1',
                   'phone': 'phone_work',
                   'mobile': 'phone_mobile',
                   'write_date':'date_modified',
                   'function':'title',
                   'street': 'primary_address_street',
                   'zip': 'primary_address_postalcode',
                   'city':'primary_address_city',
                  },
               }
      
   lead_pool = self.pool.get('crm.lead')
   PortType,sessionid = sugar.login(context.get('username',''), context.get('password',''))
   sugar_data = sugar.search(PortType,sessionid, 'Leads')
   for val in sugar_data:
       fields, datas = sugarcrm_fields_mapping.sugarcrm_fields_mapp(val, 'Leads', map_lead)
       stage_id = get_lead_status(self, cr, uid, val, context)
       openerp_val = dict(zip(fields,datas))
       openerp_val['type'] = 'lead'
       openerp_val['user_id'] = user_id
       openerp_val['stage_id'] = stage_id
       new_lead_id = lead_pool.create(cr, uid, openerp_val, context)
   return new_lead_id    
        
def import_opportunities(self, cr, uid, context=None):
   if not context:
       context = {} 
   user_id = import_users(self, cr, uid, context) 
   map_opportunity = {'Opportunities':  {'name': 'name',
          'probability': 'probability',
          'planned_revenue': 'amount_usdollar',
          'date_deadline':'date_closed'
          },
      }
   lead_pool = self.pool.get('crm.lead')
   PortType,sessionid = sugar.login(context.get('username',''), context.get('password',''))
   sugar_data = sugar.search(PortType,sessionid, 'Opportunities')
   for val in sugar_data:
       fields, datas = sugarcrm_fields_mapping.sugarcrm_fields_mapp(val, 'Opportunities', map_opportunity)
       stage_id = get_opportunity_status(self, cr, uid, val, context)
       openerp_val = dict(zip(fields,datas))
       openerp_val['type'] = 'opportunity'
       openerp_val['user_id'] = user_id
       openerp_val['stage_id'] = stage_id
       new_opportunity_id = lead_pool.create(cr, uid, openerp_val, context)
   return new_opportunity_id           
{'fraction_non_alphanumeric': 0.15268028079132098, 'fraction_numerical': 0.0019144862795149968, 'mean_word_length': 2.7234927234927233, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '399781', 'n_tokens_mistral': 3922, 'n_tokens_neox': 3752, 'n_words': 882}