[IMP] moved openerpweb into base.common to be renamed web.commom
[odoo/odoo.git] / addons / base_module_record / wizard / base_module_record_objects.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 wizard
23 import osv
24 import pooler
25 import time
26 import base_module_save
27
28 info = '''<?xml version="1.0"?>
29 <form string="Module Recording">
30     <label string="Thanks For using Module Recorder" colspan="4" align="0.0"/>
31 </form>'''
32
33 intro_start_form = '''<?xml version="1.0"?>
34 <form string="Objects Recording">
35     <field name="check_date"/>
36     <newline/>
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>
41 </form>'''
42
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'}
48 }
49
50 def _info_default(self, cr, uid, data, context):
51      pool = pooler.get_pool(cr.dbname)
52      mod = pool.get('ir.model')
53      list=('ir.ui.view','ir.ui.menu','ir.model','ir.model.fields','ir.model.access',\
54         'res.partner','res.partner.address','res.partner.category','workflow',\
55         'workflow.activity','workflow.transition','ir.actions.server','ir.server.object.lines')
56      data['form']['objects']=mod.search(cr,uid,[('model','in',list)])
57      cr.execute('select max(create_date) from ir_model_data')
58      c=(cr.fetchone())[0].split('.')[0]
59      c = time.strptime(c,"%Y-%m-%d %H:%M:%S")
60      sec=c.tm_sec!=59 and c.tm_sec + 1
61      c=(c[0],c[1],c[2],c[3],c[4],sec,c[6],c[7],c[8])
62      data['form']['check_date']=time.strftime("%Y-%m-%d %H:%M:%S",c)
63      return data['form']
64
65 def _record_objects(self, cr, uid, data, context):
66     check_date=data['form']['check_date']
67     filter=data['form']['filter_cond']
68     pool = pooler.get_pool(cr.dbname)
69     user=(pool.get('res.users').browse(cr,uid,uid)).login
70     mod = pool.get('ir.module.record')
71     mod_obj = pool.get('ir.model')
72     mod.recording_data = []
73
74     for id in data['form']['objects'][0][2]:
75         obj_name=(mod_obj.browse(cr,uid,id)).model
76         obj_pool=pool.get(obj_name)
77         if filter =='created':
78             search_condition =[('create_date','>',check_date)]
79         elif filter =='modified':
80             search_condition =[('write_date','>',check_date)]
81         elif filter =='created_modified':
82             search_condition =['|',('create_date','>',check_date),('write_date','>',check_date)]
83         if '_log_access' in dir(obj_pool):
84               if not (obj_pool._log_access):
85                   search_condition=[]
86               if '_auto' in dir(obj_pool):
87                   if not obj_pool._auto:
88                       continue
89         search_ids=obj_pool.search(cr,uid,search_condition)
90         for s_id in search_ids:
91              args=(cr.dbname,uid,obj_name,'copy',s_id,{},context)
92              mod.recording_data.append(('query',args, {}, s_id))
93     return {}
94
95 def inter_call(self,cr,uid,data,context):
96     res=base_module_save._create_module(self,cr, uid, data, context)
97     return res
98
99 def _create_yaml(self,cr,uid,data,context):
100     res=base_module_save._create_yaml(self,cr, uid, data, context)
101     return res
102
103 class base_module_record_objects(wizard.interface):
104     states = {
105          'init': {
106             'actions': [_info_default],
107             'result': {
108                 'type':'form',
109                 'arch':intro_start_form,
110                 'fields': intro_start_fields,
111                 'state':[
112                     ('end', 'Cancel', 'gtk-cancel'),
113                     ('record', 'Record', 'gtk-ok'),
114                 ]
115             }
116          },
117          'record': {
118             'actions': [],
119             'result': {'type':'action','action':_record_objects,'state':'check'}
120                 },
121          'check': {
122             'actions': [],
123             'result': {'type':'choice','next_state':base_module_save._check}
124         },
125          'info': {
126             'actions': [],
127             'result': {
128                 'type':'form',
129                 'arch':base_module_save.intro_start_form,
130                 'fields':base_module_save.intro_start_fields,
131                 'state':[
132                     ('end', 'Cancel', 'gtk-cancel'),
133                     ('save', 'Continue', 'gtk-ok'),
134                 ]
135             },
136          },
137          'save': {
138             'actions': [inter_call],
139             'result': {
140                 'type':'form',
141                 'arch':base_module_save.intro_save_form,
142                 'fields': base_module_save.intro_save_fields,
143                 'state':[('end', 'Close', 'gtk-ok'),]
144                 },
145                 },
146          'save_yaml': {
147             'actions': [_create_yaml],
148             'result': {
149                 'type':'form',
150                 'arch':base_module_save.yaml_save_form,
151                 'fields': base_module_save.yaml_save_fields,
152                 'state':[
153                     ('end', 'Close', 'gtk-ok'),
154                 ]
155             }
156          },
157          'end': {
158             'actions': [],
159             'result': {'type':'form', 'arch':info, 'fields':{}, 'state':[('end','OK')]}
160         },
161     }
162 base_module_record_objects('base_module_record.module_record_objects')
163
164 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
165