1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
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.
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.
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/>.
20 ##############################################################################
27 from tools.translate import _
28 from osv import osv, fields
31 def _create_yaml(self, cr, uid, data, context=None):
32 mod = self.pool.get('ir.module.record')
34 res_xml = mod.generate_yaml(cr, uid)
36 raise osv.except_osv(_('Error'),_(str(e)))
38 'yaml_file': base64.encodestring(res_xml),
41 def _create_module(self, cr, uid, ids, context=None):
42 mod = self.pool.get('ir.module.record')
43 res_xml = mod.generate_xml(cr, uid)
44 data = self.read(cr, uid, ids, [], context=context)[0]
45 s = StringIO.StringIO()
46 zip = zipfile.ZipFile(s, 'w')
47 dname = data['directory_name']
48 data['update_name'] = ''
49 data['demo_name'] = ''
50 if ['data_kind'] =='demo':
51 data['demo_name'] = '"%(directory_name)s_data.xml"' % data
53 data['update_name'] = '"%(directory_name)s_data.xml"' % data
54 data['depends'] = ','.join(map(lambda x: '"'+x+'"', mod.depends.keys()))
57 "version" : "%(version)s",
58 "author" : "%(author)s",
59 "website" : "%(website)s",
60 "category" : "%(category)s",
61 "description": \"\"\"%(description)s\"\"\",
62 "depends" : [%(depends)s],
64 "demo_xml" : [ %(demo_name)s],
65 "update_xml" : [%(update_name)s],
69 '__init__.py':'#\n# Generated by the OpenERP module recorder !\n#\n',
70 '__openerp__.py':_terp,
71 dname+'_data.xml': res_xml
73 for name,datastr in filewrite.items():
74 info = zipfile.ZipInfo(dname+'/'+name)
75 info.compress_type = zipfile.ZIP_DEFLATED
76 info.external_attr = 2175008768
79 zip.writestr(info, datastr)
82 'module_file': base64.encodestring(s.getvalue()),
83 'module_filename': data['directory_name']+'-'+data['version']+'.zip'
86 class base_module_save(osv.osv_memory):
87 _name = 'base.module.save'
88 _description = "Base Module Save"
90 def default_get(self, cr, uid, fields, context=None):
91 mod = self.pool.get('ir.module.record')
93 info = "Details of "+str(len(mod.recording_data))+" Operation(s):\n\n"
94 res = super(base_module_save, self).default_get(cr, uid, fields, context=context)
95 for line in mod.recording_data:
96 result.setdefault(line[0],{})
97 result[line[0]].setdefault(line[1][3], {})
98 result[line[0]][line[1][3]].setdefault(line[1][3], 0)
99 result[line[0]][line[1][3]][line[1][3]]+=1
100 for key1,val1 in result.items():
102 for key2,val2 in val1.items():
104 for key3,val3 in val2.items():
105 info+="\t\t"+key3+" : "+str(val3)+"\n"
106 if 'info_text' in fields:
107 res.update({'info_text': info})
108 if 'info_status' in fields:
109 info_status = mod.recording and 'record' or 'no'
110 res.update({'info_status': info_status})
114 'info_text': fields.text('Information', readonly=True),
115 'info_status': fields.selection([('no', 'Not Recording'),('record', 'Recording')], 'Status', readonly=True),
116 'info_yaml': fields.boolean('YAML'),
119 def record_save(self, cr, uid, ids, context=None):
120 data = self.read(cr, uid, ids, [], context=context)[0]
121 mod = self.pool.get('ir.module.record')
122 mod_obj = self.pool.get('ir.model.data')
123 if len(mod.recording_data):
124 if data['info_yaml']:
125 mod = self.pool.get('ir.module.record')
126 res=_create_yaml(self, cr, uid, data, context)
127 model_data_ids = mod_obj.search(cr, uid,[('model', '=', 'ir.ui.view'), ('name', '=', 'yml_save_form_view')], context=context)
128 resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
130 'name': _('Message'),
132 'default_yaml_file': tools.ustr(res['yaml_file']),
136 'res_model': 'base.module.record.objects',
137 'views': [(resource_id, 'form')],
138 'type': 'ir.actions.act_window',
142 model_data_ids = mod_obj.search(cr, uid,[('model', '=', 'ir.ui.view'), ('name', '=', 'info_start_form_view')], context=context)
143 resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
145 'name': _('Message'),
149 'res_model': 'base.module.record.objects',
150 'views': [(resource_id, 'form')],
151 'type': 'ir.actions.act_window',
154 model_data_ids = mod_obj.search(cr, uid,[('model', '=', 'ir.ui.view'), ('name', '=', 'module_recording_message_view')], context=context)
155 resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
158 'name': _('Message'),
162 'res_model': 'base.module.record.objects',
163 'views': [(resource_id, 'form')],
164 'type': 'ir.actions.act_window',
170 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: