~openerp-commiter/openobject-addons/trunk-extra-addons

« back to all changes in this revision

Viewing changes to base_module_quality/wizard/module_quality_check.py

account_indian is a branch of the trunk addons
make account_indian up to date with the trunk-extra-addons

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution
 
5
#    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
 
6
#    $Id$
 
7
#
 
8
#    This program is free software: you can redistribute it and/or modify
 
9
#    it under the terms of the GNU General Public License as published by
 
10
#    the Free Software Foundation, either version 3 of the License, or
 
11
#    (at your option) any later version.
 
12
#
 
13
#    This program is distributed in the hope that it will be useful,
 
14
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
#    GNU General Public License for more details.
 
17
#
 
18
#    You should have received a copy of the GNU General Public License
 
19
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
#
 
21
##############################################################################
 
22
import wizard
 
23
import pooler
 
24
from osv import osv, fields
 
25
 
 
26
import tools
 
27
import os
 
28
 
 
29
from base_module_quality import base_module_quality
 
30
 
 
31
#TODO: add cheks: do the class quality_check inherits the class abstract_quality_check?
 
32
 
 
33
 
 
34
class wiz_quality_check(osv.osv):
 
35
    _name = 'wizard.quality.check'
 
36
    _columns = {
 
37
        'name': fields.char('Rated Module', size=64, ),
 
38
        'final_score': fields.char('Final Score (%)', size=10,),
 
39
        'test_ids' : fields.one2many('quality.check.detail', 'quality_check_id', 'Tests',)
 
40
    }
 
41
wiz_quality_check()
 
42
 
 
43
 
 
44
class quality_check_detail(osv.osv):
 
45
    _name = 'quality.check.detail'
 
46
    _columns = {
 
47
        'quality_check_id': fields.many2one('wizard.quality.check', 'Quality'),
 
48
        'name': fields.char('Name',size=128,),
 
49
        'score': fields.float('Score (%)',),
 
50
        'ponderation': fields.float('Ponderation',help='Some tests are more critical than others, so they have a bigger weight in the computation of final rating'),
 
51
        'note': fields.text('Note',),
 
52
        'summary': fields.text('Summary',),
 
53
        'detail' : fields.text('Details',),
 
54
        'state': fields.selection([('done','Done'),('skipped','Skipped'),], 'State', size=6, help='The test will be completed only if the module is installed or if the test may be processed on uninstalled module.'),
 
55
    }
 
56
quality_check_detail()
 
57
 
 
58
 
 
59
class create_quality_check(wizard.interface):
 
60
 
 
61
    def _create_quality_check(self, cr, uid, data, context={}):
 
62
        pool = pooler.get_pool(cr.dbname)
 
63
        objs = []
 
64
        for id in data['ids']:
 
65
            module_data = pool.get('ir.module.module').browse(cr, uid, id)
 
66
            #list_folders = os.listdir(config['addons_path']+'/base_module_quality/')
 
67
            abstract_obj = base_module_quality.abstract_quality_check()
 
68
            score_sum = 0.0
 
69
            ponderation_sum = 0.0
 
70
            create_ids = []
 
71
            for test in abstract_obj.tests:
 
72
                ad = tools.config['addons_path']
 
73
                if module_data.name == 'base':
 
74
                    ad = tools.config['root_path']+'/addons'
 
75
                module_path = os.path.join(ad, module_data.name)
 
76
                val = test.quality_test()
 
77
                if not val.bool_installed_only or module_data.state == "installed":
 
78
                    val.run_test(cr, uid, str(module_path))
 
79
                    if not val.error:
 
80
                        data = {
 
81
                            'name': val.name,
 
82
                            'score': val.score * 100,
 
83
                            'ponderation': val.ponderation,
 
84
                            'summary': val.result,
 
85
                            'detail': val.result_details,
 
86
                            'state': 'done',
 
87
                            'note': val.note,
 
88
                        }
 
89
                        score_sum += val.score * val.ponderation
 
90
                        ponderation_sum += val.ponderation
 
91
                    else:
 
92
                        data = {
 
93
                            'name': val.name,
 
94
                            'score': 0,
 
95
                            'summary': val.result,
 
96
                            'state': 'skipped',
 
97
                            'note': val.note,
 
98
                        }
 
99
                else:
 
100
                    data = {
 
101
                        'name': val.name,
 
102
                        'note': val.note,
 
103
                        'score': 0,
 
104
                        'state': 'skipped',
 
105
                        'summary': _("The module has to be installed before running this test.")
 
106
                    }
 
107
                create_ids.append((0, 0, data))
 
108
 
 
109
            final_score = '%.2f' % (score_sum / ponderation_sum * 100)
 
110
            data = {
 
111
                'name': module_data.name,
 
112
                'final_score': final_score,
 
113
                'test_ids' : create_ids,
 
114
            }
 
115
            obj = pool.get('wizard.quality.check').create(cr, uid, data, context)
 
116
            objs.append(obj)
 
117
        return objs
 
118
 
 
119
    def _open_quality_check(self, cr, uid, data, context):
 
120
        obj_ids = self._create_quality_check(cr, uid, data, context)
 
121
        return {
 
122
            'domain': "[('id','in', ["+','.join(map(str,obj_ids))+"])]",
 
123
            'name': _('Quality Check'),
 
124
            'view_type': 'form',
 
125
            'view_mode': 'tree,form',
 
126
            'res_model': 'wizard.quality.check',
 
127
            'type': 'ir.actions.act_window'
 
128
            }
 
129
 
 
130
    states = {
 
131
        'init' : {
 
132
            'actions' : [],
 
133
            'result': {'type':'action', 'action':_open_quality_check, 'state':'end'}
 
134
        }
 
135
    }
 
136
 
 
137
create_quality_check("create_quality_check_wiz")
 
138
 
 
139
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
 
b'\\ No newline at end of file'