Sanjay Gohel (Open ERP) has proposed merging 
lp:~openerp-dev/openobject-addons/trunk-import_sugarcrm-finalize_correction-sgo 
into lp:~openerp-dev/openobject-addons/trunk-import_sugarcrm.

Requested reviews:
  Atul Patel(OpenERP) (atp-openerp)

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-import_sugarcrm-finalize_correction-sgo/+merge/67660

Hello,

I have made all correction
add error message.

kindly check it

Thanks
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-import_sugarcrm-finalize_correction-sgo/+merge/67660
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-import_sugarcrm.
=== modified file 'import_sugarcrm/__openerp__.py'
--- import_sugarcrm/__openerp__.py	2011-05-30 16:59:08 +0000
+++ import_sugarcrm/__openerp__.py	2011-07-12 07:16:11 +0000
@@ -27,7 +27,7 @@
             "Contacts", "Employees", Meetings, Phonecalls, Emails, and Project, Project Tasks Data into OpenERP Module.""",
     'author': 'OpenERP SA',
     'website': 'http://www.openerp.com',
-    'depends': ['import_base', 'crm_claim', 'project', 'project_issue', 'hr', 'document'],
+    'depends': ['import_base','crm','hr'],
     'init_xml': [],
     'update_xml': ["wizard/import_message_view.xml",
                    "import_sugarcrm_view.xml"],

=== modified file 'import_sugarcrm/import_sugarcrm.py'
--- import_sugarcrm/import_sugarcrm.py	2011-07-04 09:54:11 +0000
+++ import_sugarcrm/import_sugarcrm.py	2011-07-12 07:16:11 +0000
@@ -157,6 +157,7 @@
     
     def import_document(self, val):
         File,Filename = sugar.get_document_revision_search(self.context.get('port'), self.context.get('session_id'), val.get('document_revision_id'))
+        File = base64.encodestring(File)
         res_id, res_model  = self.import_related_document(val)
         val['res_id'] = res_id
         val['res_model'] = res_model
@@ -168,9 +169,10 @@
     def get_document_mapping(self): 
         return { 
                 'model' : 'ir.attachment',
-                'dependencies' : [self.TABLE_USER, self.TABLE_ACCOUNT,self.TABLE_CONTACT, self.TABLE_OPPORTUNITY, self.TABLE_CASE, self.TABLE_BUG],
+                'dependencies' : [self.TABLE_USER],
                 'hook' : self.import_document,
-                'map' : {'name':'document_name',
+                'map' : {
+                         'name':'document_name',
                          'description': ppconcat('description'),
                          'datas': 'datas',
                          'datas_fname': 'datas_fname',
@@ -203,7 +205,7 @@
     def get_email_mapping(self): 
         return { 
                 'model' : 'mailgate.message',
-                'dependencies' : [self.TABLE_USER, self.TABLE_PROJECT, self.TABLE_PROJECT_TASK, self.TABLE_ACCOUNT, self.TABLE_CONTACT, self.TABLE_LEAD, self.TABLE_OPPORTUNITY, self.TABLE_MEETING, self.TABLE_CALL],
+                'dependencies' : [self.TABLE_USER, self.TABLE_ACCOUNT, self.TABLE_CONTACT, self.TABLE_LEAD, self.TABLE_OPPORTUNITY, self.TABLE_MEETING, self.TABLE_CALL],
                 'hook' : self.import_email,
                 'map' : {'name':'name',
                          'history' : const("1"),
@@ -948,26 +950,48 @@
     }
     
     def _get_email_id(self, cr, uid, context=None):
-        return self.pool.get('res.users').browse(cr, uid, uid, context=context).user_email    
+        return self.pool.get('res.users').browse(cr, uid, uid, context=context).user_email
+    
+    def get_all(self, cr, uid,model, context=None):
+        obj_module = self.pool.get('ir.module.module')
+        module_id = obj_module.search(cr, uid, [('name', '=', model)])
+        flag = False
+        if module_id:
+                for id in module_id:
+                    module_state = obj_module.browse(cr, uid, id).state
+                    if module_state == 'installed':
+                        flag = True
+                    else:
+                        flag = False
+        return flag
+                
+    def _get_project(self, cr, uid, context=None):
+        return self.get_all(cr,uid,'project',context=context)
+                        
+    def _get_crm_claim(self, cr, uid, context=None):
+        return self.get_all(cr,uid,'crm_claim',context=context)
+                    
+    def _get_project_issue(self, cr, uid, context=None):
+        return self.get_all(cr,uid,'project_issue',context=context)
     
     _defaults = {#to be set to true, but easier for debugging
        'opportunity': True,
        'contact' : True,
        'account' : True,
-        'employee' : False,
+        'employee' : True,
         'meeting' : True,
         'call' : True,
-        'claim' : True,    
+        'claim' : _get_crm_claim,    
         'email_history' : True, 
-        'project' : True,   
-        'project_task': True,     
-        'bug': True,
-        'document': False,
+        'project' : _get_project,   
+        'project_task': _get_project,     
+        'bug': _get_project_issue,
+        'document': True,
         'instance_name': 'sugarcrm',
         'email_from': _get_email_id,
-        'username' : 'tfr',
-        'password' : 'a',
-        'url':  "http://localhost/sugarcrm/soap.php";        
+        'username' : 'admin',
+        'password' : '',
+        'url':  "http://sugarcrm.example.com/soap.php";        
     }
     
     def check_url(self, url, context):
@@ -987,8 +1011,6 @@
         if not context:
             context = {}
         url = context.get('url')
-        
-        
         url_split = str(url).split('/')
         while len(url_split) >= 3:
             #3 case, soap.php is already at the end of url should be valid
@@ -1011,35 +1033,41 @@
         if not context:
             context = {}
         key_list = []
+        list = []
         for current in self.browse(cr, uid, ids, context):
             context.update({'username': current.username, 'password': current.password, 'url': current.url, 'email_user': current.email_from or False, 'instance_name': current.instance_name or False})
+            if current.contact:
+                key_list.append('Contacts')
+            if current.account:
+                key_list.append('Accounts')  
             if current.opportunity:
                 key_list.append('Leads')
                 key_list.append('Opportunities')
-            if current.contact:
-                key_list.append('Contacts')
-            if current.account:
-                key_list.append('Accounts') 
             if current.employee:
-                key_list.append('Employees')  
+                key_list.append('Employees') 
             if current.meeting:
                 key_list.append('Meetings')
             if current.call:
                 key_list.append('Calls')
             if current.claim:
-                key_list.append('Cases')                
+                key_list.append('Cases')  
+                list.append('crm_claim')
             if current.email_history:
                 key_list.append('Emails') 
                 key_list.append('Notes') 
+                list.append('project')
             if current.project:
                 key_list.append('Project')
+                list.append('project')
             if current.project_task:
                 key_list.append('ProjectTask')
+                list.append('project')
             if current.bug:
                 key_list.append('Bugs')
+                list.append('project_issue')
             if current.document:
                 key_list.append('Documents')
-        return key_list
+        return key_list,list
 
 
     def do_import_all(self, cr, uid, *args):
@@ -1053,9 +1081,16 @@
         return True 
 
     def import_from_scheduler_all(self, cr, uid, ids, context=None):
-        keys = self.get_key(cr, uid, ids, context)
+        keys, module_list = self.get_key(cr, uid, ids, context)
+        set_list = set(module_list)
+        model = list(set_list)
         if not keys:
             raise osv.except_osv(_('Warning !'), _('Select Module to Import.'))
+        for module in model:
+            state = self.get_all(cr,uid,module,context=context)
+            if state == False:
+                keys =  ', '.join(keys)
+                raise osv.except_osv(_('Error !!'), _("%s data required %s Module to be installed, Please install %s module") %(keys,module,module))
         cron_obj = self.pool.get('ir.cron')
         url = self.parse_valid_url(context)
         args = (keys,context.get('email_user'), context.get('instance_name'), url, context.get('username'), context.get('password') )
@@ -1068,18 +1103,25 @@
             'res_id': new_create_id,
             'type': 'ir.actions.act_window',
         }
-    
-    
+        
     def import_all(self, cr, uid, ids, context=None):
         
 #        """Import all sugarcrm data into openerp module"""
-        keys = self.get_key(cr, uid, ids, context)
+        keys, module_list = self.get_key(cr, uid, ids, context)
+        set_list = set(module_list)
+        model = list(set_list)
+        if not keys:
+            raise osv.except_osv(_('Warning !'), _('Select Module to Import.'))
+        for module in model:
+            state = self.get_all(cr,uid,module,context=context)
+            if state == False:
+                keys =  ', '.join(keys)
+                raise osv.except_osv(_('Error !!'), _("%s data required %s Module to be installed, Please install %s module") %(keys,module,module))
         url = self.parse_valid_url(context)
         context.update({'url': url})
         imp = sugar_import(self, cr, uid, context.get('instance_name'), "import_sugarcrm", [context.get('email_user')], context)
         imp.set_table_list(keys)
         imp.start()
-        
         obj_model = self.pool.get('ir.model.data')
         model_data_ids = obj_model.search(cr,uid,[('model','=','ir.ui.view'),('name','=','import.message.form')])
         resource_id = obj_model.read(cr, uid, model_data_ids, fields=['res_id'])

=== modified file 'import_sugarcrm/import_sugarcrm_view.xml'
--- import_sugarcrm/import_sugarcrm_view.xml	2011-07-04 09:54:11 +0000
+++ import_sugarcrm/import_sugarcrm_view.xml	2011-07-12 07:16:11 +0000
@@ -74,8 +74,8 @@
 	                    <group colspan="4" col="6">
 	                        <label string="" colspan="2"/>
 	                        <button  icon="gtk-cancel" special="cancel" string="_Cancel"/>
-	                         <button name="import_from_scheduler_all" string="_Schedule recurrent import"
-	                                   type="object" icon="gtk-execute"/>
+	                         <button name="import_from_scheduler_all" groups="base.group_extended" string="_Schedule Recurrent Import"
+	                                   type="object" icon="gtk-execute" />
 	                        <button name="import_all" string="_Import"
 	                                type="object" icon="terp-camera_test"/>
 	                   </group>		                       

=== modified file 'import_sugarcrm/wizard/import_message_view.xml'
--- import_sugarcrm/wizard/import_message_view.xml	2011-05-30 16:59:08 +0000
+++ import_sugarcrm/wizard/import_message_view.xml	2011-07-12 07:16:11 +0000
@@ -9,7 +9,7 @@
             <field name="type">form</field>
             <field name="arch" type="xml">
                 <form string="Import Message">
-                   <label colspan="4" nolabel="1" string="Import Data Launch: The Import Process is running in the background. You'll receive an email soon when import will be finished"/> 
+                   <label colspan="4" nolabel="1" string="Data are importing, the process is running in the background, You will receive an email at the end of the import."/> 
                    <separator string="" colspan="4" />
                    <button  icon="gtk-ok" special="cancel" string="_Ok"/>
                 </form>

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to