← Back to team overview

openerp-community team mailing list archive

[Merge] lp:~credativ/openobject-addons/elico-6.1-fixes-gap-analysis-aeroo-seq into lp:~openerp-community/openobject-addons/elico-6.1

 

Tom Pickering has proposed merging lp:~credativ/openobject-addons/elico-6.1-fixes-gap-analysis-aeroo-seq 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-aeroo-seq/+merge/218427

This branch includes changes which allow users to specify the ordering of rows in the Gap Analysis Aeroo Report. The user is able to specify one of several sorting modes based on Phase, Category and Critical Level.
-- 
https://code.launchpad.net/~credativ/openobject-addons/elico-6.1-fixes-gap-analysis-aeroo-seq/+merge/218427
Your team OpenERP Community is requested to review the proposed merge of lp:~credativ/openobject-addons/elico-6.1-fixes-gap-analysis-aeroo-seq into lp:~openerp-community/openobject-addons/elico-6.1.
=== modified file 'gap_analysis/gap_analysis.py'
--- gap_analysis/gap_analysis.py	2013-06-22 02:18:01 +0000
+++ gap_analysis/gap_analysis.py	2014-05-06 13:40:19 +0000
@@ -228,6 +228,10 @@
         if type(ids) != type([]):
             ids = [ids]
         
+        cat_ids = gap_cat_pool.search(cr, uid, [], context=context)
+        seq_components = gap_cat_pool.read(cr, uid, cat_ids, ['sequence'], context=context)
+        max_seq_len = max([len(str(c['sequence'])) for c in seq_components])
+                
         for gap_id in ids:
             cr.execute("SELECT DISTINCT c.code FROM gap_analysis_line l, gap_analysis_functionality_category c WHERE l.category=c.id AND l.gap_id = %s",(gap_id,))
             categ_codes = map(lambda x: x[0], cr.fetchall()) or []
@@ -243,7 +247,7 @@
                     current_categ = categ
                     seq = ''
                     while current_categ:
-                        seq = str(current_categ.sequence) + seq
+                        seq = str(current_categ.sequence).zfill(max_seq_len) + seq
                         current_categ = current_categ.parent_id or False
                     
                     line_ids = gapline_pool.search(cr, uid, [('category','=',categ.id),('gap_id','=',gap_id)], order='critical desc, effort asc') or []
@@ -475,4 +479,4 @@
     
 gap_analysis_line()
 
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
\ No newline at end of file
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== modified file 'gap_analysis_aeroo_report/report/gap_analysis_report.py'
--- gap_analysis_aeroo_report/report/gap_analysis_report.py	2013-06-22 02:18:01 +0000
+++ gap_analysis_aeroo_report/report/gap_analysis_report.py	2014-05-06 13:40:19 +0000
@@ -76,7 +76,59 @@
         context.update({'workload_type_list':ranges_list})
         return result            
     
+
+    def sort_lines_by_phase(self, lines, context=None):
+        lines_with_num_phase = []
+        lines_with_alpha_phase = []
+        for l in lines:
+            try:
+                float(l.phase)
+                lines_with_num_phase.append(l)
+            except ValueError:
+                lines_with_alpha_phase.append(l)
+                                                                                                                                   
+        sorted_num_phase   = sorted(lines_with_num_phase  , key=lambda l: float(l.phase))
+        sorted_alpha_phase = sorted(lines_with_alpha_phase, key=lambda l:       l.phase )
+        return sorted_num_phase + sorted_alpha_phase
+
+
+    def sort_lines_by_seq(self, lines, context=None):
+        if not context:
+            context = {}
+
+        return sorted(lines, key=lambda l: l.seq)
+
+    def sort_lines_by_crit(self, lines, context=None):
+        if not context:
+            context = {}
+
+        return sorted(lines, key=lambda l: l.critical, reverse=True)
+
+    def sort_lines(self, lines, context=None):
+        if not context:
+            context = {}
+
+        sort_mode = context.get('sort_mode', 'phaseseq')
+
+        # Because 'sorted' is guaranteed to be stable,
+        # sorting by each key from the hierarchically lowest first
+        # sorts lines as required.
+        sorted_lines = []
+        if sort_mode == 'phasecritseq':
+            sorted_lines = self.sort_lines_by_seq(lines, context=context)
+            sorted_lines = self.sort_lines_by_crit(lines, context=context)
+            sorted_lines = self.sort_lines_by_phase(sorted_lines[:], context=context)
+        elif sort_mode == 'seqphasecrit':
+            sorted_lines = self.sort_lines_by_crit(lines, context=context)
+            sorted_lines = self.sort_lines_by_phase(lines, context=context)
+            sorted_lines = self.sort_lines_by_seq(sorted_lines[:], context=context)
+        if sort_mode == 'critphaseseq':
+            sorted_lines = self.sort_lines_by_seq(lines, context=context)
+            sorted_lines = self.sort_lines_by_phase(sorted_lines[:], context=context)
+            sorted_lines = self.sort_lines_by_crit(lines, context=context)
+        return sorted_lines
     
+
     def get_lines(self, context=None):
         if not context:
             context = {}
@@ -99,7 +151,8 @@
         if active_id:
             # First we get all the used category for this Gap Analysis
             active_gap = gap_pool.browse(self.cr, self.uid, active_id)
-            for one_line in active_gap.gap_lines:
+            ordered = self.sort_lines(active_gap.gap_lines, context=context)
+            for one_line in ordered:
                 res = {}
                 
                 res['functionality'] = one_line.functionality.name

=== modified file 'gap_analysis_aeroo_report/wizard/wizard_view.py'
--- gap_analysis_aeroo_report/wizard/wizard_view.py	2013-06-22 02:18:01 +0000
+++ gap_analysis_aeroo_report/wizard/wizard_view.py	2014-05-06 13:40:19 +0000
@@ -21,16 +21,37 @@
 ##############################################################################
 
 from osv import osv, fields
+from osv.osv import except_osv
 from tools.translate import _
 
 class gap_analysis_wizard(osv.osv_memory):
     _name='gap_analysis.gap_analysis_wizard'
+
+    def _get_sort_modes(self, cr, uid, context=None):
+        return [('phasecritseq','Group by Phase'),('seqphasecrit', 'Group by Category'),('critphaseseq', 'Group by Critical Level')]
+
+    _columns = {
+        'sort_mode' : fields.selection(_get_sort_modes, string='Sorting', help='Use \'Group by Phase\' for generating a customer facing implementation breakdown. Use \'Group by Category\' for for planning the complete implementation for a single module (e.g. sales).'),
+    }
+
+    _defaults = {
+        'sort_mode' : _get_sort_modes(None, None, None)[0],
+    }
     
     def print_xls(self, cr, uid, ids, context=None):
         if context is None:
             context = {}
         
         data = {'model':'gap_analysis', 'ids':context.get('active_ids', []), 'id':ids[0], 'report_type': 'aeroo'}
+        sort_mode = self.read(cr, uid, ids, ['sort_mode'], context=context)[0]['sort_mode']
+
+        if not sort_mode:
+            raise except_osv(
+                                _('Error: Sort Mode Unspecified'),
+                                _('Please select a sort mode from the selection box.')
+                            )
+        else:
+            context.update(sort_mode=sort_mode)
         
         return {
             'type': 'ir.actions.report.xml',
@@ -58,4 +79,4 @@
         }
 gap_analysis_tasks_list()
 
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
\ No newline at end of file
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== modified file 'gap_analysis_aeroo_report/wizard/wizard_view.xml'
--- gap_analysis_aeroo_report/wizard/wizard_view.xml	2013-06-22 02:18:01 +0000
+++ gap_analysis_aeroo_report/wizard/wizard_view.xml	2014-05-06 13:40:19 +0000
@@ -8,7 +8,14 @@
             <field name="arch" type="xml">
 				<form string="Gap Analysis Report Wizard">
 					<newline/>
-					<group col="4" colspan="4">
+                                        <label colspan="4" nolabel="1" string="You can export a summary of the complete Gap Analysis to a spreadsheet for further checking or analysis."/>
+                                        <group col="1" colspan="2"/>
+                                        <group col="2" colspan="2">
+                                                <field name="sort_mode" colspan="2"/>
+                                        </group>
+                                        <separator colspan="4"/>
+                                        <group col="1" colspan="2"/>
+					<group col="2" colspan="2">
 						<button icon="gtk-cancel" special="cancel" string="Cancel" colspan="1"/>
 						<button icon="gtk-print" name="print_xls" string="Generate XLS" type="object" colspan="1" default_focus="1" />
 					</group>
@@ -76,4 +83,4 @@
             target="new"
             key2="client_action_multi" />
     </data>
-</openerp>
\ No newline at end of file
+</openerp>

=== modified file 'gap_analysis_project_long_term/gap_analysis_project_long_term.py'
--- gap_analysis_project_long_term/gap_analysis_project_long_term.py	2013-06-22 02:18:01 +0000
+++ gap_analysis_project_long_term/gap_analysis_project_long_term.py	2014-05-06 13:40:19 +0000
@@ -218,4 +218,4 @@
     
 gap_analysis_line()
 
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
\ No newline at end of file
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: