[FIX] base_module_quality: add import statment for _ and give size to name field...
[odoo/odoo.git] / addons / base_module_quality / wizard / quality_save_report.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20 ##############################################################################
21
22 import base64
23 import cStringIO
24
25 import wizard
26 from osv import osv
27 import pooler
28 from tools.translate import _
29
30 form_rep = '''<?xml version="1.0"?>
31 <form string="Standard entries">
32     <field name="name"/>
33     <newline/>
34     <field name="module_file"/>
35 </form>'''
36
37
38 fields_rep = {
39   'name': {'string': 'File name', 'type': 'char', 'required': True, 'help': 'Save report as .html format', 'size':64},
40   'module_file': {'string': 'Save report', 'type': 'binary', 'required': True},
41 }
42
43 def get_detail(self, cr, uid, datas, context={}):
44     data = pooler.get_pool(cr.dbname).get('module.quality.detail').browse(cr, uid, datas['id'])
45     if not data.detail:
46         raise wizard.except_wizard(_('Warning'), _('No report to save!'))
47     buf = cStringIO.StringIO(data.detail)
48     out = base64.encodestring(buf.getvalue())
49     buf.close()
50     return {'module_file': out, 'name': data.name + '.html'}
51
52 class save_report(wizard.interface):
53     states = {
54         'init': {
55             'actions': [get_detail],
56             'result': {'type': 'form', 'arch': form_rep, 'fields':fields_rep, 'state': [('end','Cancel')]}
57         },
58     }
59 save_report('quality_detail_save')
60
61 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: