← Back to team overview

credativ team mailing list archive

[Merge] lp:~credativ/openobject-addons/elico-6.1-fixes-gap-analysis-xls-import-warnings into lp:~openerp-community/openobject-addons/elico-6.1

 

Tom Pickering has proposed merging lp:~credativ/openobject-addons/elico-6.1-fixes-gap-analysis-xls-import-warnings into lp:~openerp-community/openobject-addons/elico-6.1.

Requested reviews:
  OpenERP Community (openerp-community)

For more details, see:
https://code.launchpad.net/~credativ/openobject-addons/elico-6.1-fixes-gap-analysis-xls-import-warnings/+merge/218433

This branch improves the clarity of warning messages displayed when a user tries to import an invalid Gap Analysis from a spreadsheet.
-- 
https://code.launchpad.net/~credativ/openobject-addons/elico-6.1-fixes-gap-analysis-xls-import-warnings/+merge/218433
Your team credativ is subscribed to branch lp:~credativ/openobject-addons/elico-6.1-fixes-gap-analysis-xls-import-warnings.
=== modified file 'gap_analysis/wizard/import_from_sheet.py'
--- gap_analysis/wizard/import_from_sheet.py	2013-06-22 02:18:01 +0000
+++ gap_analysis/wizard/import_from_sheet.py	2014-05-06 14:02:57 +0000
@@ -125,10 +125,15 @@
         def retrieve_gap_analysis(filecontents):
             warning = ''
             g_cat_pool = self.pool.get('gap_analysis.functionality.category')
+            g_eft_pool = self.pool.get('gap_analysis.effort')
             gap_lines_entries = {}
             rb = open_workbook(file_contents=filecontents,formatting_info=True, encoding_override="utf-8")
+            missing_categories = []
+            missing_efforts = []
+            sheet_count = 1
             
             for rs in rb.sheets():    
+                line_count = 4
                 for line in range(3, rs.nrows):
                     try:
                         keep = getcell(rs, line,  1)
@@ -168,22 +173,37 @@
                         total_dev      = getfloat(getcell(rs, line,29))
                         
                         if functionality:
+                            if effort:
+                                effort_ids = g_eft_pool.search(cr, uid, [('name','=',str(effort))], context=context)
+                                if not effort_ids:
+                                    eft_str = str(effort)
+                                    if eft_str not in missing_efforts:
+                                        missing_efforts.append(eft_str)
+                                        warning += 'Effort %s does not exist in OpenERP. Please create it first, then upload your Gap Analysis again.\n\n' % eft_str
+
                             if category:
                                 categ_ids = g_cat_pool.search(cr, uid, ['|',('name','ilike',category),('full_path','ilike',category)])
                                 if categ_ids:
-                                    category = categ_ids[0]
+                                    if not missing_efforts:
+                                        category = categ_ids[0]
                             
-                                    gap_line = GapLineTemp(gap_analysis, keep, functionality.strip(), function_desc, category, critical_level, phase, contributors, openerp_fct, basic_report, advan_report, basic_process, advan_process, basic_screen, advan_screen, basic_workflow, advan_workflow, acl, obj, calcul_field, basic_wizard, advan_wizard, effort, duration_wk, total_cost, total_analysis, total_dev, testing, training, project_mgmt)
-                                    if gap_line:
-                                        gap_lines_entries[rs.name.lower().strip() + str(line)] = gap_line
+                                        gap_line = GapLineTemp(gap_analysis, keep, functionality.strip(), function_desc, category, critical_level, phase, contributors, openerp_fct, basic_report, advan_report, basic_process, advan_process, basic_screen, advan_screen, basic_workflow, advan_workflow, acl, obj, calcul_field, basic_wizard, advan_wizard, effort, duration_wk, total_cost, total_analysis, total_dev, testing, training, project_mgmt)
+                                        if gap_line:
+                                            gap_lines_entries[rs.name.lower().strip() + str(line)] = gap_line
                                 else:
-                                    warning += 'The category ' + str(category) + ' does not exist in OpenERP. Please create it first, then upload you Gap analysis again.\n'
+                                    cat_str = str(category)
+                                    if cat_str not in missing_categories:
+                                        missing_categories.append(cat_str)
+                                        warning += 'The category %s does not exist in OpenERP. Please create it first, then upload your Gap Analysis again.\n\n' % cat_str
                             else:
-                                warning += 'The category ' + str(category) + ' does not exist in OpenERP. Please create it first, then upload you Gap analysis again.\n'
+                                warning += 'Missing category in spreadsheet row %d. Please specify a category and upload your Gap Analysis again.\n\n' % line_count
                         else:
                             print(" ("+ str(line) +"), No functionality... ########################  .......")
                     except RuntimeError as error:
                         print(" ("+ str(line) +", "+ str(col) +"), didn't make it ########################  ......."+ str(error))
+
+                    line_count += 1
+                sheet_count += 1
             
             if warning != '':
                 raise osv.except_osv(_('Error'), warning)
@@ -342,8 +362,12 @@
             g_cat_pool = self.pool.get('gap_analysis.functionality.category')
             warning = ''
             rb = open_workbook(file_contents=filecontents,formatting_info=True, encoding_override="utf-8")
+            missing_categories = []
+            missing_efforts = []
+            sheet_count = 1
             
-            for rs in rb.sheets():    
+            for rs in rb.sheets():
+                line_count = 4
                 for line in range(3, rs.nrows):
                     try:
                         keep = False                        
@@ -378,21 +402,36 @@
                         category       = getcell(rs, line, 25, forceText=True)
                         
                         if functionality:
+                            if effort:
+                                effort_ids = g_eft_pool.search(cr, uid, [('name','=',str(effort))], context=context)
+                                if not effort_ids:
+                                    eft_str = str(effort)
+                                    if eft_str not in missing_efforts:
+                                        missing_efforts.append(eft_str)
+                                        warning += 'Effort %s does not exist in OpenERP. Please create it first, then upload your Gap Analysis again.\n\n' % eft_str
+
                             if category:
                                 categ_ids = g_cat_pool.search(cr, uid, ['|',('name','ilike',category),('full_path','ilike',category)])
                                 if categ_ids:
-                                    category = categ_ids[0]
-                                    one_fct = GapLineTemp(gap_analysis, keep, functionality.strip(), function_desc, category, critical_level, phase, contributors, openerp_fct, basic_report, advan_report, basic_process, advan_process, basic_screen, advan_screen, basic_workflow, advan_workflow, acl, obj, calcul_field, basic_wizard, advan_wizard, effort, duration_wk, total_cost, total_analysis, total_dev, testing, training, project_mgmt)
-                                    if one_fct:
-                                        fct_entries[rs.name.lower().strip() + str(line)] = one_fct
+                                    if not missing_efforts:
+                                        category = categ_ids[0]
+                                        one_fct = GapLineTemp(gap_analysis, keep, functionality.strip(), function_desc, category, critical_level, phase, contributors, openerp_fct, basic_report, advan_report, basic_process, advan_process, basic_screen, advan_screen, basic_workflow, advan_workflow, acl, obj, calcul_field, basic_wizard, advan_wizard, effort, duration_wk, total_cost, total_analysis, total_dev, testing, training, project_mgmt)
+                                        if one_fct:
+                                            fct_entries[rs.name.lower().strip() + str(line)] = one_fct
                                 else:
-                                    warning += 'The category ' + str(category) + ' dont exist in OpenERP. Please create it first, then upload you Gap analysis.\n'
+                                    cat_str = str(category)
+                                    if cat_str not in missing_categories:
+                                        missing_categories.append(cat_str)
+                                        warning += 'The category %s does not exist in OpenERP. Please create it first, then upload your Gap Analysis again.\n\n' % cat_id
                             else:
-                                warning += 'The category ' + str(category) + ' dont exist in OpenERP. Please create it first, then upload you Gap analysis.\n'
+                                warning += 'Missing category in spreadsheet row %d. Please specify a category and upload your Gap Analysis again.\n\n' % line_count
                         else:
                             print(" ("+ str(line) +"), No functionality... ########################  .......")
                     except RuntimeError as error:
                         print(" ("+ str(line) +", "+ str(col) +"), didn't make it ########################  ......."+ str(error))
+
+                    line_count += 1
+                sheet_count += 1
             
             if warning != '':
                 raise osv.except_osv(_('Error'), warning)