Added __terp__.py test on base_module_quality,bugfixed base_vat
[odoo/odoo.git] / addons / base_module_quality / base_module_quality.py
1 # -*- encoding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2008 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 pooler
23 import os
24 from tools import config
25
26 class abstract_quality_check(object):
27     '''
28         This Class provide...
29     '''
30
31 #    #This float have to store the rating of the module.
32 #    #Used to compute the final score (average of all scores).
33 #    score = 0.0
34 #
35 #    #This char have to store the result.
36 #    #Used to display the result of the test.
37 #    result = ""
38 #
39 #    #This char have to store the result with more details.
40 #    #Used to provide more details if necessary.
41 #    result_details = ""
42 #
43 #    #This bool defines if the test can be run only if the module is installed.
44 #    #True => the module have to be installed.
45 #    #False => the module can be uninstalled.
46 #    bool_installed_only = True
47
48     def __init__(self):
49         '''
50         this method should initialize the var
51         '''
52         #This float have to store the rating of the module.
53         #Used to compute the final score (average of all scores).
54         self.score = 0.0
55
56         #This char have to store the result.
57         #Used to display the result of the test.
58         self.result = ""
59
60         #This char have to store the result with more details.
61         #Used to provide more details if necessary.
62         self.result_details = ""
63
64         #This bool defines if the test can be run only if the module is installed.
65         #True => the module have to be installed.
66         #False => the module can be uninstalled.
67         self.bool_installed_only = True
68
69
70         #This variable is use to make result of test should have more weight (Some tests are more critical than others)
71         self.ponderation = 0.0
72
73         self.tests = []
74         self.list_folders = os.listdir(config['addons_path']+'/base_module_quality/')
75         for item in self.list_folders:
76             self.item = item
77             path = config['addons_path']+'/base_module_quality/'+item
78             if os.path.exists(path+'/'+item+'.py') and item not in ['report', 'wizard', 'security']:
79                 item2 = 'base_module_quality.' + item +'.' + item
80                 x = __import__(item2)
81                 x2 = getattr(x, item)
82                 x3 = getattr(x2, item)
83                 self.tests.append(x3)
84 #        raise 'Not Implemented'
85
86     def run_test(self, cr, uid, module_path="", module_state=""):
87         '''
88         this method should do the test and fill the score, result and result_details var
89         '''
90 #        raise 'Not Implemented'
91
92     def get_objects(self, cr, uid, module):
93         # This function returns all object of the given module..
94         pool = pooler.get_pool(cr.dbname)
95         ids2 = pool.get('ir.model.data').search(cr, uid, [('module','=', module), ('model','=','ir.model')])
96         model_list = []
97         model_data = pool.get('ir.model.data').browse(cr, uid, ids2)
98         for model in model_data:
99             model_list.append(model.res_id)
100         obj_list = []
101         for mod in pool.get('ir.model').browse(cr, uid, model_list):
102             obj_list.append(str(mod.model))
103         return obj_list
104
105     def get_ids(self, cr, uid, object_list):
106         #This method return dictionary with ids of records of object for module
107         pool = pooler.get_pool(cr.dbname)
108         result_ids = {}
109         for obj in object_list:
110             ids = pool.get(obj).search(cr, uid, [])
111             result_ids[obj] = ids
112         return result_ids
113
114     def format_table(self, test='', header=[], data_list=[]):
115         res_format = {}
116         if test=='method':
117             detail = ""
118             detail += "\n===Method Test===\n"
119             res_format['detail'] = detail
120             if not data_list[2]:
121                 detail += ('{| border="1" cellspacing="0" cellpadding="5" align="left" \n! %-40s \n! %-16s \n! %-20s \n! %-16s ') % (header[0].ljust(40), header[1].ljust(16), header[2].ljust(20), header[3].ljust(16))
122                 for res in data_list[1]:
123                     detail += ('\n|-\n| %s \n| %s \n| %s \n| %s ') % (res, data_list[1][res][0], data_list[1][res][1], data_list[1][res][2])
124                 res_format['detail'] = detail + '\n|}'
125             res_format['summary'] = data_list[0]
126         elif test=='pylint':
127             res_format['summary'] = data_list[0]
128             res_format['detail'] = data_list[1]
129         elif test=='speed':
130             detail = ""
131             detail += "\n===Speed Test===\n"
132             res_format['detail'] = detail
133             if not data_list[2]:
134                 detail += ('{| border="1" cellspacing="0" cellpadding="5" align="left" \n! %-40s \n! %-10s \n! %-10s \n! %-10s \n! %-10s \n! %-20s') % (header[0].ljust(40), header[1].ljust(10), header[2].ljust(10), header[3].ljust(10), header[4].ljust(10), header[5].ljust(20))
135                 for data in data_list[1]:
136                     detail +=  ('\n|-\n| %s \n| %s \n| %s \n| %s \n| %s \n| %s ') % (data[0], data[1], data[2], data[3], data[4], data[5])
137                     res_format['detail'] = detail  + '\n|}\n'
138             res_format['summary'] = data_list[0]
139         elif test=='terp':
140             res_format['summary'] = data_list[0]
141             res_format['detail'] = data_list[1]    
142         return res_format
143
144     def add_quatation(self, x, y):
145         return x/y
146
147
148
149 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
150