1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). All Rights Reserved
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU Affero 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.
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 Affero General Public License for more details.
18 # You should have received a copy of the GNU Affero General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ##############################################################################
23 from osv import osv, fields
25 from tools.translate import _
29 class base_module_data(osv.osv_memory):
30 _name = 'base.module.data'
31 _description = "Base Module Data"
34 'check_date': fields.datetime('Record from Date', required=True),
35 'objects': fields.many2many('ir.model', 'base_module_record_model_rel', 'objects', 'model_id', 'Objects'),
36 'filter_cond': fields.selection([('created', 'Created'), ('modified', 'Modified'), ('created_modified', 'Created & Modified')], 'Records only', required=True),
37 'info_yaml': fields.boolean('YAML'),
40 def _get_default_objects(self, cr, uid, context=None):
41 names = ('ir.ui.view', 'ir.ui.menu', 'ir.model', 'ir.model.fields', 'ir.model.access',
42 'res.partner', 'res.partner.category', 'workflow',
43 'workflow.activity', 'workflow.transition', 'ir.actions.server', 'ir.server.object.lines')
44 return self.pool.get('ir.model').search(cr, uid, [('model', 'in', names)])
47 'check_date': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
48 'objects': _get_default_objects,
49 'filter_cond': 'created',
52 def _create_xml(self, cr, uid, data, context=None):
53 mod = self.pool.get('ir.module.record')
54 res_xml = mod.generate_xml(cr, uid)
55 return {'res_text': res_xml }
57 def _create_yaml(self, cr, uid, data, context=None):
58 mod = self.pool.get('ir.module.record')
59 res_xml = mod.generate_yaml(cr, uid)
60 return { 'res_text': res_xml }
62 def record_objects(self, cr, uid, ids, context=None):
63 data = self.read(cr, uid, ids, [], context=context)[0]
64 check_date = data['check_date']
65 filter = data['filter_cond']
66 user = (self.pool.get('res.users').browse(cr, uid, uid)).login
67 mod = self.pool.get('ir.module.record')
68 mod_obj = self.pool.get('ir.model')
69 mod.recording_data = []
70 for id in data['objects']:
71 obj_name=(mod_obj.browse(cr, uid, id)).model
72 obj_pool=self.pool.get(obj_name)
73 if filter =='created':
74 search_condition =[('create_date','>',check_date)]
75 elif filter =='modified':
76 search_condition =[('write_date','>',check_date)]
77 elif filter =='created_modified':
78 search_condition =['|',('create_date','>',check_date),('write_date','>',check_date)]
79 if '_log_access' in dir(obj_pool):
80 if not (obj_pool._log_access):
82 if '_auto' in dir(obj_pool):
83 if not obj_pool._auto:
85 search_ids=obj_pool.search(cr,uid,search_condition)
86 for s_id in search_ids:
87 args=(cr.dbname,uid,obj_name,'copy', s_id,{}, context)
88 mod.recording_data.append(('query', args, {}, s_id))
90 mod_obj = self.pool.get('ir.model.data')
91 if len(mod.recording_data):
93 res=self._create_yaml(cr, uid, data, context)
95 res=self._create_xml(cr, uid, data, context)
96 model_data_ids = mod_obj.search(cr, uid, [('model', '=', 'ir.ui.view'), ('name', '=', 'module_create_xml_view')], context=context)
97 resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
99 'name': _('Data Recording'),
100 'context': {'default_res_text': tools.ustr(res['res_text'])},
103 'res_model': 'base.module.record.data',
104 'views': [(resource_id, 'form')],
105 'type': 'ir.actions.act_window',
109 model_data_ids = mod_obj.search(cr, uid,[('model', '=', 'ir.ui.view'), ('name', '=', 'module_recording_message_view')], context=context)
110 resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
112 'name': _('Module Recording'),
116 'res_model': 'base.module.record.objects',
117 'views': [(resource_id, 'form')],
118 'type': 'ir.actions.act_window',
124 class base_module_record_data(osv.osv_memory):
125 _name = 'base.module.record.data'
126 _description = "Base Module Record Data"
129 'res_text': fields.text('Result'),
132 base_module_record_data()
134 #vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: