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 ##############################################################################
28 info = '''<?xml version="1.0"?>
29 <form string="Module Recording">
30 <label string="Thanks For using Module Recorder" colspan="4" align="0.0"/>
33 intro_start_form = '''<?xml version="1.0"?>
34 <form string="Objects Recording">
35 <field name="check_date"/>
37 <field name="filter_cond"/>
38 <separator string="Choose objects to record" colspan="4"/>
39 <field name="objects" colspan="4" nolabel="1"/>
40 <group><field name="info_yaml"/></group>
43 intro_start_fields = {
44 'check_date': {'string':"Record from Date",'type':'datetime','required':True, 'default': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S')},
45 'objects':{'string': 'Objects', 'type': 'many2many', 'relation': 'ir.model', 'help': 'List of objects to be recorded'},
46 'filter_cond':{'string':'Records only', 'type':'selection','selection':[('created','Created'),('modified','Modified'),('created_modified','Created & Modified')], 'required':True, 'default': lambda *args:'created'},
47 'info_yaml': {'string':'YAML','type':'boolean'}
50 exp_form = '''<?xml version="1.0"?>
51 <form string="Objects Recording">
52 <separator string="Result, paste this to your module's xml" colspan="4" />
53 <field name="res_text" nolabel="1" colspan="4"/>
57 'res_text': {'string':"Result",'type':'text', },
60 def _info_default(self, cr, uid, data, context):
61 pool = pooler.get_pool(cr.dbname)
62 mod = pool.get('ir.model')
63 list=('ir.ui.view','ir.ui.menu','ir.model','ir.model.fields','ir.model.access',\
64 'res.partner','res.partner.address','res.partner.category','workflow',\
65 'workflow.activity','workflow.transition','ir.actions.server','ir.server.object.lines')
66 data['form']['objects']=mod.search(cr,uid,[('model','in',list)])
67 cr.execute('select max(create_date) from ir_model_data')
68 c=(cr.fetchone())[0].split('.')[0]
69 c = time.strptime(c,"%Y-%m-%d %H:%M:%S")
71 c=(c[0],c[1],c[2],c[3],c[4],sec,c[6],c[7],c[8])
72 data['form']['check_date']=time.strftime("%Y-%m-%d %H:%M:%S",c)
75 def _record_objects(self, cr, uid, data, context):
76 check_date=data['form']['check_date']
77 filter=data['form']['filter_cond']
78 pool = pooler.get_pool(cr.dbname)
79 user=(pool.get('res.users').browse(cr,uid,uid)).login
80 mod = pool.get('ir.module.record')
81 mod_obj = pool.get('ir.model')
82 mod.recording_data = []
84 for id in data['form']['objects'][0][2]:
85 obj_name=(mod_obj.browse(cr,uid,id)).model
86 obj_pool=pool.get(obj_name)
87 if filter =='created':
88 search_condition =[('create_date','>',check_date)]
89 elif filter =='modified':
90 search_condition =[('write_date','>',check_date)]
91 elif filter =='created_modified':
92 search_condition =['|',('create_date','>',check_date),('write_date','>',check_date)]
93 if '_log_access' in dir(obj_pool):
94 if not (obj_pool._log_access):
96 if '_auto' in dir(obj_pool):
97 if not obj_pool._auto:
99 elif '_log_access' not in dir(obj_pool):
100 search_condition = []
101 search_ids=obj_pool.search(cr,uid,search_condition)
102 for s_id in search_ids:
103 args=(cr.dbname,uid,obj_name,'copy',s_id,{},context)
104 mod.recording_data.append(('query',args, {}, s_id))
105 return {'type': 'ir.actions.act_window_close'}
107 def _check(self, cr, uid, data, context):
108 pool = pooler.get_pool(cr.dbname)
109 mod = pool.get('ir.module.record')
110 if len(mod.recording_data):
111 if data['form']['info_yaml']:
118 def _create_xml(self, cr, uid, data, context):
119 pool = pooler.get_pool(cr.dbname)
120 mod = pool.get('ir.module.record')
121 res_xml = mod.generate_xml(cr, uid)
122 return { 'res_text': res_xml }
124 def _create_yaml(self,cr,uid,data,context):
125 pool = pooler.get_pool(cr.dbname)
126 mod = pool.get('ir.module.record')
127 res_xml = mod.generate_yaml(cr, uid)
128 return { 'res_text': res_xml }
130 class base_module_record_objects(wizard.interface):
133 'actions': [_info_default],
136 'arch':intro_start_form,
137 'fields': intro_start_fields,
139 ('end', 'Cancel', 'gtk-cancel'),
140 ('record', 'Record', 'gtk-ok'),
146 'result': {'type':'action','action':_record_objects,'state':'check'}
150 'result': {'type':'choice','next_state':_check}
153 'actions': [ _create_xml ],
159 ('end', 'End', 'gtk-cancel'),
164 'actions': [ _create_yaml ],
170 ('end', 'End', 'gtk-cancel'),
176 'result': {'type':'form', 'arch':info, 'fields':{}, 'state':[('end','OK')]}
179 base_module_record_objects('base_module_record.module_record_data')
181 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: