[IMP] convert interface wizard to osv memory wizard
bzr revid: ara@tinyerp.com-20110907113745-09fb5qsrjp9kh2fn
This commit is contained in:
parent
d62bfd8a88
commit
a98b13cdbf
|
@ -47,7 +47,7 @@ Select datetime criteria of recording and objects to be recorded and Record modu
|
|||
'website': 'http://www.openerp.com',
|
||||
'depends': ['base'],
|
||||
'init_xml': [],
|
||||
'update_xml': ['security/ir.model.access.csv', 'base_module_record_wizard.xml'],
|
||||
'update_xml': ['security/ir.model.access.csv', 'wizard/base_module_record_object_view.xml', 'wizard/base_module_record_data_view.xml',],
|
||||
'demo_xml': [],
|
||||
'installable': True,
|
||||
'certificate': '0083134865813',
|
||||
|
|
|
@ -20,163 +20,142 @@
|
|||
#
|
||||
##############################################################################
|
||||
|
||||
import wizard
|
||||
import osv
|
||||
import pooler
|
||||
import time
|
||||
from osv import osv, fields
|
||||
import tools
|
||||
from tools.translate import _
|
||||
|
||||
info = '''<?xml version="1.0"?>
|
||||
<form string="Module Recording">
|
||||
<label string="Thanks For using Module Recorder" colspan="4" align="0.0"/>
|
||||
</form>'''
|
||||
|
||||
intro_start_form = '''<?xml version="1.0"?>
|
||||
<form string="Objects Recording">
|
||||
<field name="check_date"/>
|
||||
<newline/>
|
||||
<field name="filter_cond"/>
|
||||
<separator string="Choose objects to record" colspan="4"/>
|
||||
<field name="objects" colspan="4" nolabel="1"/>
|
||||
<group><field name="info_yaml"/></group>
|
||||
</form>'''
|
||||
|
||||
intro_start_fields = {
|
||||
'check_date': {'string':"Record from Date",'type':'datetime','required':True, 'default': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S')},
|
||||
'objects':{'string': 'Objects', 'type': 'many2many', 'relation': 'ir.model', 'help': 'List of objects to be recorded'},
|
||||
'filter_cond':{'string':'Records only', 'type':'selection','selection':[('created','Created'),('modified','Modified'),('created_modified','Created & Modified')], 'required':True, 'default': lambda *args:'created'},
|
||||
'info_yaml': {'string':'YAML','type':'boolean'}
|
||||
}
|
||||
|
||||
exp_form = '''<?xml version="1.0"?>
|
||||
<form string="Objects Recording">
|
||||
<separator string="Result, paste this to your module's xml" colspan="4" />
|
||||
<field name="res_text" nolabel="1" colspan="4"/>
|
||||
</form>'''
|
||||
|
||||
exp_fields = {
|
||||
'res_text': {'string':"Result",'type':'text', },
|
||||
}
|
||||
|
||||
def _info_default(self, cr, uid, data, context):
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
mod = pool.get('ir.model')
|
||||
list=('ir.ui.view','ir.ui.menu','ir.model','ir.model.fields','ir.model.access',\
|
||||
'res.partner','res.partner.address','res.partner.category','workflow',\
|
||||
'workflow.activity','workflow.transition','ir.actions.server','ir.server.object.lines')
|
||||
data['form']['objects']=mod.search(cr,uid,[('model','in',list)])
|
||||
cr.execute('select max(create_date) from ir_model_data')
|
||||
c=(cr.fetchone())[0].split('.')[0]
|
||||
c = time.strptime(c,"%Y-%m-%d %H:%M:%S")
|
||||
sec=c.tm_sec + 1
|
||||
c=(c[0],c[1],c[2],c[3],c[4],sec,c[6],c[7],c[8])
|
||||
data['form']['check_date']=time.strftime("%Y-%m-%d %H:%M:%S",c)
|
||||
return data['form']
|
||||
|
||||
def _record_objects(self, cr, uid, data, context):
|
||||
check_date=data['form']['check_date']
|
||||
filter=data['form']['filter_cond']
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
user=(pool.get('res.users').browse(cr,uid,uid)).login
|
||||
mod = pool.get('ir.module.record')
|
||||
mod_obj = pool.get('ir.model')
|
||||
mod.recording_data = []
|
||||
|
||||
for id in data['form']['objects'][0][2]:
|
||||
obj_name=(mod_obj.browse(cr,uid,id)).model
|
||||
obj_pool=pool.get(obj_name)
|
||||
if filter =='created':
|
||||
search_condition =[('create_date','>',check_date)]
|
||||
elif filter =='modified':
|
||||
search_condition =[('write_date','>',check_date)]
|
||||
elif filter =='created_modified':
|
||||
search_condition =['|',('create_date','>',check_date),('write_date','>',check_date)]
|
||||
if '_log_access' in dir(obj_pool):
|
||||
if not (obj_pool._log_access):
|
||||
search_condition=[]
|
||||
if '_auto' in dir(obj_pool):
|
||||
if not obj_pool._auto:
|
||||
continue
|
||||
elif '_log_access' not in dir(obj_pool):
|
||||
search_condition = []
|
||||
search_ids=obj_pool.search(cr,uid,search_condition)
|
||||
for s_id in search_ids:
|
||||
args=(cr.dbname,uid,obj_name,'copy',s_id,{},context)
|
||||
mod.recording_data.append(('query',args, {}, s_id))
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
|
||||
def _check(self, cr, uid, data, context):
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
mod = pool.get('ir.module.record')
|
||||
if len(mod.recording_data):
|
||||
if data['form']['info_yaml']:
|
||||
return 'save_yaml'
|
||||
else:
|
||||
return 'info'
|
||||
else:
|
||||
return 'end'
|
||||
class base_module_data(osv.osv_memory):
|
||||
_name = 'base.module.data'
|
||||
_description = "Base Module Data"
|
||||
|
||||
def default_get(self, cr, uid, fields, context):
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
mod = pool.get('ir.model')
|
||||
res = super(base_module_data, self).default_get(cr, uid, fields, context=context)
|
||||
|
||||
def _create_xml(self, cr, uid, data, context):
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
mod = pool.get('ir.module.record')
|
||||
res_xml = mod.generate_xml(cr, uid)
|
||||
return { 'res_text': res_xml }
|
||||
list=('ir.ui.view', 'ir.ui.menu', 'ir.model', 'ir.model.fields', 'ir.model.access',\
|
||||
'res.partner', 'res.partner.address', 'res.partner.category', 'workflow',\
|
||||
'workflow.activity', 'workflow.transition', 'ir.actions.server', 'ir.server.object.lines')
|
||||
if 'objects' in fields:
|
||||
res.update({'objects': mod.search(cr, uid, [('model', 'in', list)])})
|
||||
cr.execute('select max(create_date) from ir_model_data')
|
||||
c=(cr.fetchone())[0].split('.')[0]
|
||||
c = time.strptime(c, "%Y-%m-%d %H:%M:%S")
|
||||
sec=c.tm_sec!=59 and c.tm_sec + 1
|
||||
c=(c[0],c[1],c[2],c[3],c[4],sec,c[6],c[7],c[8])
|
||||
if 'check_date' in fields:
|
||||
res.update({'check_date': time.strftime("%Y-%m-%d %H:%M:%S",c)})
|
||||
return res
|
||||
|
||||
def _create_yaml(self,cr,uid,data,context):
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
mod = pool.get('ir.module.record')
|
||||
res_xml = mod.generate_yaml(cr, uid)
|
||||
return { 'res_text': res_xml }
|
||||
|
||||
class base_module_record_objects(wizard.interface):
|
||||
states = {
|
||||
'init': {
|
||||
'actions': [_info_default],
|
||||
'result': {
|
||||
'type':'form',
|
||||
'arch':intro_start_form,
|
||||
'fields': intro_start_fields,
|
||||
'state':[
|
||||
('end', 'Cancel', 'gtk-cancel'),
|
||||
('record', 'Record', 'gtk-ok'),
|
||||
]
|
||||
}
|
||||
},
|
||||
'record': {
|
||||
'actions': [],
|
||||
'result': {'type':'action','action':_record_objects,'state':'check'}
|
||||
},
|
||||
'check': {
|
||||
'actions': [],
|
||||
'result': {'type':'choice','next_state':_check}
|
||||
},
|
||||
'info': {
|
||||
'actions': [ _create_xml ],
|
||||
'result': {
|
||||
'type':'form',
|
||||
'arch': exp_form,
|
||||
'fields':exp_fields,
|
||||
'state':[
|
||||
('end', 'End', 'gtk-cancel'),
|
||||
]
|
||||
},
|
||||
},
|
||||
'save_yaml': {
|
||||
'actions': [ _create_yaml ],
|
||||
'result': {
|
||||
'type':'form',
|
||||
'arch': exp_form,
|
||||
'fields':exp_fields,
|
||||
'state':[
|
||||
('end', 'End', 'gtk-cancel'),
|
||||
]
|
||||
},
|
||||
},
|
||||
'end': {
|
||||
'actions': [],
|
||||
'result': {'type':'form', 'arch':info, 'fields':{}, 'state':[('end','OK')]}
|
||||
},
|
||||
_columns = {
|
||||
'check_date': fields.datetime('Record from Date', size=64, required=True),
|
||||
'objects': fields.many2many('ir.model', 'base_module_record_object_rel', 'objects', 'model_id', 'Objects'),
|
||||
'filter_cond': fields.selection([('created', 'Created'), ('modified', 'Modified'), ('created_modified', 'Created & Modified')], 'Records only', required=True),
|
||||
'info_yaml': fields.boolean('YAML'),
|
||||
}
|
||||
base_module_record_objects('base_module_record.module_record_data')
|
||||
_defaults = {
|
||||
'check_date': time.strftime('%Y-%m-%d %H:%M:%S'),
|
||||
'filter_cond': 'created',
|
||||
}
|
||||
|
||||
def _create_xml(self, cr, uid, data, context):
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
mod = pool.get('ir.module.record')
|
||||
res_xml = mod.generate_xml(cr, uid)
|
||||
return { 'res_text': res_xml }
|
||||
def _create_yaml(self, cr, uid, data, context):
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
mod = pool.get('ir.module.record')
|
||||
res_xml = mod.generate_yaml(cr, uid)
|
||||
return { 'res_text': res_xml }
|
||||
|
||||
def record_objects(self, cr, uid, ids, context):
|
||||
data = self.read(cr, uid, ids, [], context=context)[0]
|
||||
check_date=data['check_date']
|
||||
filter=data['filter_cond']
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
user=(pool.get('res.users').browse(cr, uid, uid)).login
|
||||
mod = pool.get('ir.module.record')
|
||||
mod_obj = pool.get('ir.model')
|
||||
mod.recording_data = []
|
||||
for id in data['objects']:
|
||||
obj_name=(mod_obj.browse(cr, uid, id)).model
|
||||
obj_pool=pool.get(obj_name)
|
||||
if filter =='created':
|
||||
search_condition =[('create_date','>',check_date)]
|
||||
elif filter =='modified':
|
||||
search_condition =[('write_date','>',check_date)]
|
||||
elif filter =='created_modified':
|
||||
search_condition =['|',('create_date','>',check_date),('write_date','>',check_date)]
|
||||
if '_log_access' in dir(obj_pool):
|
||||
if not (obj_pool._log_access):
|
||||
search_condition=[]
|
||||
if '_auto' in dir(obj_pool):
|
||||
if not obj_pool._auto:
|
||||
continue
|
||||
search_ids=obj_pool.search(cr,uid,search_condition)
|
||||
for s_id in search_ids:
|
||||
args=(cr.dbname,uid,obj_name,'copy', s_id,{}, context)
|
||||
mod.recording_data.append(('query', args, {}, s_id))
|
||||
|
||||
mod_obj = self.pool.get('ir.model.data')
|
||||
if len(mod.recording_data):
|
||||
if data['info_yaml']:
|
||||
res=self._create_yaml(cr, uid, data, context)
|
||||
model_data_ids = mod_obj.search(cr, uid, [('model', '=', 'ir.ui.view'), ('name', '=', 'module_create_xml_view')], context=context)
|
||||
resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
|
||||
return {
|
||||
'name': _('Message'),
|
||||
'context': {
|
||||
'default_res_text': tools.ustr(res['res_text']),
|
||||
},
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'res_model': 'base.module.record.data',
|
||||
'views': [(resource_id, 'form')],
|
||||
'type': 'ir.actions.act_window',
|
||||
'target': 'new',
|
||||
}
|
||||
else:
|
||||
res=self._create_xml(cr, uid, data, context)
|
||||
model_data_ids = mod_obj.search(cr, uid, [('model', '=', 'ir.ui.view'), ('name', '=', 'module_create_xml_view')], context=context)
|
||||
resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
|
||||
return {
|
||||
'name': _('Message'),
|
||||
'context': {
|
||||
'default_res_text': tools.ustr(res['res_text']),
|
||||
},
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'res_model': 'base.module.record.data',
|
||||
'views': [(resource_id, 'form')],
|
||||
'type': 'ir.actions.act_window',
|
||||
'target': 'new',
|
||||
}
|
||||
model_data_ids = mod_obj.search(cr, uid,[('model', '=', 'ir.ui.view'), ('name', '=', 'module_recording_message_view')], context=context)
|
||||
resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
|
||||
|
||||
return {
|
||||
'name': _('Message'),
|
||||
'context': context,
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'res_model': 'base.module.record.objects',
|
||||
'views': [(resource_id, 'form')],
|
||||
'type': 'ir.actions.act_window',
|
||||
'target': 'new',
|
||||
}
|
||||
base_module_data()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
class base_module_record_data(osv.osv_memory):
|
||||
_name = 'base.module.record.data'
|
||||
_description = "Base Module Record Data"
|
||||
|
||||
_columns = {
|
||||
'res_text': fields.text('Result'),
|
||||
}
|
||||
base_module_record_data()
|
||||
|
||||
#vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
@ -19,147 +19,169 @@
|
|||
#
|
||||
##############################################################################
|
||||
|
||||
import wizard
|
||||
import osv
|
||||
import pooler
|
||||
import time
|
||||
import base_module_save
|
||||
from osv import osv, fields
|
||||
import tools
|
||||
from tools.translate import _
|
||||
|
||||
info = '''<?xml version="1.0"?>
|
||||
<form string="Module Recording">
|
||||
<label string="Thanks For using Module Recorder" colspan="4" align="0.0"/>
|
||||
</form>'''
|
||||
class base_module_record(osv.osv_memory):
|
||||
_name = 'base.module.record'
|
||||
_description = "Base Module Record"
|
||||
|
||||
def default_get(self, cr, uid, fields, context):
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
mod = pool.get('ir.model')
|
||||
res = super(base_module_record, self).default_get(cr, uid, fields, context=context)
|
||||
|
||||
list=('ir.ui.view', 'ir.ui.menu', 'ir.model', 'ir.model.fields', 'ir.model.access', \
|
||||
'res.partner', 'res.partner.address', 'res.partner.category', 'workflow', \
|
||||
'workflow.activity', 'workflow.transition', 'ir.actions.server', 'ir.server.object.lines')
|
||||
if 'objects' in fields:
|
||||
res.update({'objects': mod.search(cr, uid, [('model', 'in', list)])})
|
||||
cr.execute('select max(create_date) from ir_model_data')
|
||||
c=(cr.fetchone())[0].split('.')[0]
|
||||
c = time.strptime(c, "%Y-%m-%d %H:%M:%S")
|
||||
sec=c.tm_sec!=59 and c.tm_sec + 1
|
||||
c=(c[0],c[1],c[2],c[3],c[4],sec,c[6],c[7],c[8])
|
||||
if 'check_date' in fields:
|
||||
res.update({'check_date': time.strftime("%Y-%m-%d %H:%M:%S", c)})
|
||||
return res
|
||||
|
||||
intro_start_form = '''<?xml version="1.0"?>
|
||||
<form string="Objects Recording">
|
||||
<field name="check_date"/>
|
||||
<newline/>
|
||||
<field name="filter_cond"/>
|
||||
<separator string="Choose objects to record" colspan="4"/>
|
||||
<field name="objects" colspan="4" nolabel="1"/>
|
||||
<group><field name="info_yaml"/></group>
|
||||
</form>'''
|
||||
|
||||
intro_start_fields = {
|
||||
'check_date': {'string':"Record from Date",'type':'datetime','required':True, 'default': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S')},
|
||||
'objects':{'string': 'Objects', 'type': 'many2many', 'relation': 'ir.model', 'help': 'List of objects to be recorded'},
|
||||
'filter_cond':{'string':'Records only', 'type':'selection','selection':[('created','Created'),('modified','Modified'),('created_modified','Created & Modified')], 'required':True, 'default': lambda *args:'created'},
|
||||
'info_yaml': {'string':'YAML','type':'boolean'}
|
||||
}
|
||||
|
||||
def _info_default(self, cr, uid, data, context):
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
mod = pool.get('ir.model')
|
||||
list=('ir.ui.view','ir.ui.menu','ir.model','ir.model.fields','ir.model.access',\
|
||||
'res.partner','res.partner.address','res.partner.category','workflow',\
|
||||
'workflow.activity','workflow.transition','ir.actions.server','ir.server.object.lines')
|
||||
data['form']['objects']=mod.search(cr,uid,[('model','in',list)])
|
||||
cr.execute('select max(create_date) from ir_model_data')
|
||||
c=(cr.fetchone())[0].split('.')[0]
|
||||
c = time.strptime(c,"%Y-%m-%d %H:%M:%S")
|
||||
sec=c.tm_sec!=59 and c.tm_sec + 1
|
||||
c=(c[0],c[1],c[2],c[3],c[4],sec,c[6],c[7],c[8])
|
||||
data['form']['check_date']=time.strftime("%Y-%m-%d %H:%M:%S",c)
|
||||
return data['form']
|
||||
|
||||
def _record_objects(self, cr, uid, data, context):
|
||||
check_date=data['form']['check_date']
|
||||
filter=data['form']['filter_cond']
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
user=(pool.get('res.users').browse(cr,uid,uid)).login
|
||||
mod = pool.get('ir.module.record')
|
||||
mod_obj = pool.get('ir.model')
|
||||
mod.recording_data = []
|
||||
|
||||
for id in data['form']['objects'][0][2]:
|
||||
obj_name=(mod_obj.browse(cr,uid,id)).model
|
||||
obj_pool=pool.get(obj_name)
|
||||
if filter =='created':
|
||||
search_condition =[('create_date','>',check_date)]
|
||||
elif filter =='modified':
|
||||
search_condition =[('write_date','>',check_date)]
|
||||
elif filter =='created_modified':
|
||||
search_condition =['|',('create_date','>',check_date),('write_date','>',check_date)]
|
||||
if '_log_access' in dir(obj_pool):
|
||||
if not (obj_pool._log_access):
|
||||
search_condition=[]
|
||||
if '_auto' in dir(obj_pool):
|
||||
if not obj_pool._auto:
|
||||
continue
|
||||
search_ids=obj_pool.search(cr,uid,search_condition)
|
||||
for s_id in search_ids:
|
||||
args=(cr.dbname,uid,obj_name,'copy',s_id,{},context)
|
||||
mod.recording_data.append(('query',args, {}, s_id))
|
||||
return {}
|
||||
|
||||
def inter_call(self,cr,uid,data,context):
|
||||
res=base_module_save._create_module(self,cr, uid, data, context)
|
||||
return res
|
||||
|
||||
def _create_yaml(self,cr,uid,data,context):
|
||||
res=base_module_save._create_yaml(self,cr, uid, data, context)
|
||||
return res
|
||||
|
||||
class base_module_record_objects(wizard.interface):
|
||||
states = {
|
||||
'init': {
|
||||
'actions': [_info_default],
|
||||
'result': {
|
||||
'type':'form',
|
||||
'arch':intro_start_form,
|
||||
'fields': intro_start_fields,
|
||||
'state':[
|
||||
('end', 'Cancel', 'gtk-cancel'),
|
||||
('record', 'Record', 'gtk-ok'),
|
||||
]
|
||||
}
|
||||
},
|
||||
'record': {
|
||||
'actions': [],
|
||||
'result': {'type':'action','action':_record_objects,'state':'check'}
|
||||
},
|
||||
'check': {
|
||||
'actions': [],
|
||||
'result': {'type':'choice','next_state':base_module_save._check}
|
||||
},
|
||||
'info': {
|
||||
'actions': [],
|
||||
'result': {
|
||||
'type':'form',
|
||||
'arch':base_module_save.intro_start_form,
|
||||
'fields':base_module_save.intro_start_fields,
|
||||
'state':[
|
||||
('end', 'Cancel', 'gtk-cancel'),
|
||||
('save', 'Continue', 'gtk-ok'),
|
||||
]
|
||||
},
|
||||
},
|
||||
'save': {
|
||||
'actions': [inter_call],
|
||||
'result': {
|
||||
'type':'form',
|
||||
'arch':base_module_save.intro_save_form,
|
||||
'fields': base_module_save.intro_save_fields,
|
||||
'state':[('end', 'Close', 'gtk-ok'),]
|
||||
},
|
||||
},
|
||||
'save_yaml': {
|
||||
'actions': [_create_yaml],
|
||||
'result': {
|
||||
'type':'form',
|
||||
'arch':base_module_save.yaml_save_form,
|
||||
'fields': base_module_save.yaml_save_fields,
|
||||
'state':[
|
||||
('end', 'Close', 'gtk-ok'),
|
||||
]
|
||||
}
|
||||
},
|
||||
'end': {
|
||||
'actions': [],
|
||||
'result': {'type':'form', 'arch':info, 'fields':{}, 'state':[('end','OK')]}
|
||||
},
|
||||
_columns = {
|
||||
'check_date': fields.datetime('Record from Date', size=64, required=True),
|
||||
'objects': fields.many2many('ir.model', 'base_module_record_object_rel', 'objects', 'model_id', 'Objects'),
|
||||
'filter_cond': fields.selection([('created', 'Created'), ('modified', 'Modified'), ('created_modified', 'Created & Modified')], 'Records only', required=True),
|
||||
'info_yaml': fields.boolean('YAML'),
|
||||
}
|
||||
base_module_record_objects('base_module_record.module_record_objects')
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
_defaults = {
|
||||
'check_date': time.strftime('%Y-%m-%d %H:%M:%S'),
|
||||
'filter_cond': 'created',
|
||||
}
|
||||
|
||||
def record_objects(self, cr, uid, ids, context):
|
||||
data = self.read(cr, uid, ids, [], context=context)[0]
|
||||
check_date=data['check_date']
|
||||
filter=data['filter_cond']
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
user=(pool.get('res.users').browse(cr,uid,uid)).login
|
||||
mod = pool.get('ir.module.record')
|
||||
mod_obj = pool.get('ir.model')
|
||||
mod.recording_data = []
|
||||
for id in data['objects']:
|
||||
obj_name=(mod_obj.browse(cr,uid,id)).model
|
||||
obj_pool=pool.get(obj_name)
|
||||
if filter =='created':
|
||||
search_condition =[('create_date', '>', check_date)]
|
||||
elif filter =='modified':
|
||||
search_condition =[('write_date', '>', check_date)]
|
||||
elif filter =='created_modified':
|
||||
search_condition =['|',('create_date', '>', check_date), ('write_date', '>', check_date)]
|
||||
if '_log_access' in dir(obj_pool):
|
||||
if not (obj_pool._log_access):
|
||||
search_condition=[]
|
||||
if '_auto' in dir(obj_pool):
|
||||
if not obj_pool._auto:
|
||||
continue
|
||||
search_ids=obj_pool.search(cr,uid,search_condition)
|
||||
for s_id in search_ids:
|
||||
args=(cr.dbname, uid,obj_name, 'copy', s_id,{},context)
|
||||
mod.recording_data.append(('query', args, {}, s_id))
|
||||
|
||||
mod_obj = self.pool.get('ir.model.data')
|
||||
if len(mod.recording_data):
|
||||
if data['info_yaml']:
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
mod = pool.get('ir.module.record')
|
||||
res=base_module_save._create_yaml(self, cr, uid, data, context)
|
||||
model_data_ids = mod_obj.search(cr, uid,[('model', '=', 'ir.ui.view'), ('name', '=', 'yml_save_form_view')], context=context)
|
||||
resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
|
||||
return {
|
||||
'name': _('Message'),
|
||||
'context': {
|
||||
'default_yaml_file': tools.ustr(res['yaml_file']),
|
||||
},
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'res_model': 'base.module.record.objects',
|
||||
'views': [(resource_id, 'form')],
|
||||
'type': 'ir.actions.act_window',
|
||||
'target': 'new',
|
||||
}
|
||||
else:
|
||||
model_data_ids = mod_obj.search(cr, uid, [('model', '=', 'ir.ui.view'), ('name', '=', 'info_start_form_view')], context=context)
|
||||
resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
|
||||
return {
|
||||
'name': _('Message'),
|
||||
'context': context,
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'res_model': 'base.module.record.objects',
|
||||
'views': [(resource_id, 'form')],
|
||||
'type': 'ir.actions.act_window',
|
||||
'target': 'new',
|
||||
}
|
||||
model_data_ids = mod_obj.search(cr, uid, [('model', '=', 'ir.ui.view'), ('name', '=', 'module_recording_message_view')], context=context)
|
||||
resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
|
||||
|
||||
return {
|
||||
'name': _('Message'),
|
||||
'context': context,
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'res_model': 'base.module.record.objects',
|
||||
'views': [(resource_id, 'form')],
|
||||
'type': 'ir.actions.act_window',
|
||||
'target': 'new',
|
||||
}
|
||||
base_module_record()
|
||||
|
||||
class base_module_record_objects(osv.osv_memory):
|
||||
_name = 'base.module.record.objects'
|
||||
_description = "Base Module Record Objects"
|
||||
|
||||
def inter_call(self,cr,uid,data,context):
|
||||
res=base_module_save._create_module(self, cr, uid, data, context)
|
||||
mod_obj = self.pool.get('ir.model.data')
|
||||
model_data_ids = mod_obj.search(cr, uid,[('model', '=', 'ir.ui.view'), ('name', '=', 'module_create_form_view')], context=context)
|
||||
resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
|
||||
context.update(res)
|
||||
|
||||
return {
|
||||
'name': _('Message'),
|
||||
'context': {
|
||||
'default_module_filename': tools.ustr(res['module_filename']),
|
||||
'default_module_file': tools.ustr(res['module_file']),
|
||||
},
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'res_model': 'base.module.record.objects',
|
||||
'views': [(resource_id, 'form')],
|
||||
'type': 'ir.actions.act_window',
|
||||
'target': 'new',
|
||||
}
|
||||
|
||||
_columns = {
|
||||
'name': fields.char('Module Name', size=64, required=True),
|
||||
'directory_name': fields.char('Directory Name', size=32, required=True),
|
||||
'version': fields.char('Version', size=16, required=True),
|
||||
'author': fields.char('Author', size=64, required=True),
|
||||
'category': fields.char('Category', size=64, required=True),
|
||||
'website': fields.char('Documentation URL', size=64, required=True),
|
||||
'description': fields.text('Full Description', required=True),
|
||||
'data_kind': fields.selection([('demo', 'Demo Data'), ('update', 'Normal Data')], 'Type of Data', required=True),
|
||||
'module_file': fields.binary('Module .zip File', filename="module_filename"),
|
||||
'module_filename': fields.char('Filename', size=64),
|
||||
'yaml_file': fields.binary('Module .zip File'),
|
||||
}
|
||||
_defaults = {
|
||||
'author': 'OpenERP SA',
|
||||
'category': 'Vertical Modules/Parametrization',
|
||||
'website': 'http://www.openerp.com',
|
||||
'data_kind': 'update'
|
||||
}
|
||||
|
||||
base_module_record_objects()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
@ -20,105 +20,14 @@
|
|||
##############################################################################
|
||||
|
||||
import wizard
|
||||
import osv
|
||||
import pooler
|
||||
from tools.translate import _
|
||||
|
||||
info = '''<?xml version="1.0"?>
|
||||
<form string="Module Recording">
|
||||
<label string="Thanks For using Module Recorder" colspan="4" align="0.0"/>
|
||||
</form>'''
|
||||
|
||||
info_start_form = '''<?xml version="1.0"?>
|
||||
<form string="Module Recording">
|
||||
<separator string="Recording Information" colspan="4"/>
|
||||
<field name="info_status"/>
|
||||
<field name="info_text" colspan="4" nolabel="1"/>
|
||||
<field name="info_yaml" colspan="4"/>
|
||||
</form>'''
|
||||
|
||||
info_start_fields = {
|
||||
'info_text': {'string':'Information', 'type':'text', 'readonly':True},
|
||||
'info_status': {'string':'Status','type':'selection', 'selection':[('no','Not Recording'),('record','Recording')], 'readonly':True},
|
||||
'info_yaml': {'string':'YAML','type':'boolean'}
|
||||
}
|
||||
|
||||
|
||||
|
||||
intro_start_form = '''<?xml version="1.0"?>
|
||||
<form string="Module Recording">
|
||||
<separator string="Module Information" colspan="4"/>
|
||||
<field name="name"/>
|
||||
<field name="directory_name"/>
|
||||
<field name="version"/>
|
||||
<field name="author"/>
|
||||
<field name="website" colspan="4"/>
|
||||
<field name="category" colspan="4"/>
|
||||
<field name="data_kind"/>
|
||||
<newline/>
|
||||
<field name="description" colspan="4"/>
|
||||
</form>'''
|
||||
|
||||
intro_start_fields = {
|
||||
'name': {'string':'Module Name', 'type':'char', 'size':64, 'required':True},
|
||||
'directory_name': {'string':'Directory Name', 'type':'char', 'size':32, 'required':True},
|
||||
'version': {'string':'Version', 'type':'char', 'size':16, 'required':True},
|
||||
'author': {'string':'Author', 'type':'char', 'size':64, 'default': lambda *args: 'OpenERP SA', 'required':True},
|
||||
'category': {'string':'Category', 'type':'char', 'size':64, 'default': lambda *args: 'Vertical Modules/Parametrization', 'required':True},
|
||||
'website': {'string':'Documentation URL', 'type':'char', 'size':64, 'default': lambda *args: 'http://www.openerp.com', 'required':True},
|
||||
'description': {'string':'Full Description', 'type':'text', 'required':True},
|
||||
'data_kind': {'string':'Type of Data', 'type':'selection', 'selection':[('demo','Demo Data'),('update','Normal Data')], 'required':True, 'default': lambda *args:'update'},
|
||||
}
|
||||
|
||||
intro_save_form = '''<?xml version="1.0"?>
|
||||
<form string="Module Recording">
|
||||
<separator string="Module successfully created !" colspan="4"/>
|
||||
<field name="module_filename"/>
|
||||
<newline/>
|
||||
<field name="module_file" filename="module_filename"/>
|
||||
<separator string="Information" colspan="4"/>
|
||||
<label string="If you think your module could interest other people, we'd like you to publish it on http://www.openerp.com, in the 'Modules' section. You can do it through the website or using features of the 'base_module_publish' module." colspan="4" align="0.0"/>
|
||||
<label string="Thanks in advance for your contribution." colspan="4" align="0.0"/>
|
||||
</form>'''
|
||||
|
||||
intro_save_fields = {
|
||||
'module_file': {'string': 'Module .zip File', 'type':'binary', 'readonly':True},
|
||||
'module_filename': {'string': 'Filename', 'type':'char', 'size': 64, 'readonly':True},
|
||||
}
|
||||
|
||||
yaml_save_form = '''<?xml version="1.0"?>
|
||||
<form string="Module Recording">
|
||||
<separator string="YAML file successfully created !" colspan="4"/>
|
||||
<newline/>
|
||||
<field name="yaml_file" filename="module_filename"/>
|
||||
</form>'''
|
||||
|
||||
yaml_save_fields = {
|
||||
'yaml_file': {'string': 'Module .zip File', 'type':'binary'},
|
||||
}
|
||||
|
||||
import tools
|
||||
import zipfile
|
||||
import StringIO
|
||||
import base64
|
||||
from tools.translate import _
|
||||
from osv import osv, fields
|
||||
|
||||
def _info_default(self, cr, uid, data, context):
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
mod = pool.get('ir.module.record')
|
||||
result = {}
|
||||
info = "Details of "+str(len(mod.recording_data))+" Operation(s):\n\n"
|
||||
|
||||
for line in mod.recording_data:
|
||||
result.setdefault(line[0],{})
|
||||
result[line[0]].setdefault(line[1][3], {})
|
||||
result[line[0]][line[1][3]].setdefault(line[1][3], 0)
|
||||
result[line[0]][line[1][3]][line[1][3]]+=1
|
||||
for key1,val1 in result.items():
|
||||
info+=key1+"\n"
|
||||
for key2,val2 in val1.items():
|
||||
info+="\t"+key2+"\n"
|
||||
for key3,val3 in val2.items():
|
||||
info+="\t\t"+key3+" : "+str(val3)+"\n"
|
||||
return {'info_text': info, 'info_status':mod.recording and 'record' or 'no'}
|
||||
|
||||
def _create_yaml(self, cr, uid, data, context):
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
|
@ -131,21 +40,21 @@ def _create_yaml(self, cr, uid, data, context):
|
|||
'yaml_file': base64.encodestring(res_xml),
|
||||
}
|
||||
|
||||
def _create_module(self, cr, uid, data, context):
|
||||
def _create_module(self, cr, uid, ids, context):
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
mod = pool.get('ir.module.record')
|
||||
res_xml = mod.generate_xml(cr, uid)
|
||||
|
||||
data = self.read(cr, uid, ids, [], context=context)[0]
|
||||
s=StringIO.StringIO()
|
||||
zip = zipfile.ZipFile(s, 'w')
|
||||
dname = data['form']['directory_name']
|
||||
data['form']['update_name'] = ''
|
||||
data['form']['demo_name'] = ''
|
||||
if data['form']['data_kind'] =='demo':
|
||||
data['form']['demo_name'] = '"%(directory_name)s_data.xml"' % data['form']
|
||||
dname = data['directory_name']
|
||||
data['update_name'] = ''
|
||||
data['demo_name'] = ''
|
||||
if ['data_kind'] =='demo':
|
||||
data['demo_name'] = '"%(directory_name)s_data.xml"' % data
|
||||
else:
|
||||
data['form']['update_name'] = '"%(directory_name)s_data.xml"' % data['form']
|
||||
data['form']['depends'] = ','.join(map(lambda x: '"'+x+'"',mod.depends.keys()))
|
||||
data['update_name'] = '"%(directory_name)s_data.xml"' % data
|
||||
data['depends'] = ','.join(map(lambda x: '"'+x+'"', mod.depends.keys()))
|
||||
_terp = """{
|
||||
"name" : "%(name)s",
|
||||
"version" : "%(version)s",
|
||||
|
@ -158,7 +67,7 @@ def _create_module(self, cr, uid, data, context):
|
|||
"demo_xml" : [ %(demo_name)s],
|
||||
"update_xml" : [%(update_name)s],
|
||||
"installable": True
|
||||
} """ % data['form']
|
||||
} """ % data
|
||||
filewrite = {
|
||||
'__init__.py':'#\n# Generated by the OpenERP module recorder !\n#\n',
|
||||
'__openerp__.py':_terp,
|
||||
|
@ -174,78 +83,93 @@ def _create_module(self, cr, uid, data, context):
|
|||
zip.close()
|
||||
return {
|
||||
'module_file': base64.encodestring(s.getvalue()),
|
||||
'module_filename': data['form']['directory_name']+'-'+data['form']['version']+'.zip'
|
||||
'module_filename': data['directory_name']+'-'+data['version']+'.zip'
|
||||
}
|
||||
def _check(self, cr, uid, data, context):
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
mod = pool.get('ir.module.record')
|
||||
if len(mod.recording_data):
|
||||
if data['form']['info_yaml']:
|
||||
return 'save_yaml'
|
||||
else:
|
||||
return 'info'
|
||||
else:
|
||||
return 'end'
|
||||
|
||||
class base_module_publish(wizard.interface):
|
||||
states = {
|
||||
'init': {
|
||||
'actions': [_info_default],
|
||||
'result': {
|
||||
'type':'form',
|
||||
'arch':info_start_form,
|
||||
'fields': info_start_fields,
|
||||
'state':[
|
||||
('end', 'Cancel', 'gtk-cancel'),
|
||||
('check', 'Continue', 'gtk-ok'),
|
||||
]
|
||||
}
|
||||
},
|
||||
'check': {
|
||||
'actions': [],
|
||||
'result': {'type':'choice','next_state':_check}
|
||||
},
|
||||
'info': {
|
||||
'actions': [],
|
||||
'result': {
|
||||
'type':'form',
|
||||
'arch':intro_start_form,
|
||||
'fields': intro_start_fields,
|
||||
'state':[
|
||||
('end', 'Cancel', 'gtk-cancel'),
|
||||
('save', 'Continue', 'gtk-ok'),
|
||||
]
|
||||
}
|
||||
},
|
||||
'save': {
|
||||
'actions': [_create_module],
|
||||
'result': {
|
||||
'type':'form',
|
||||
'arch':intro_save_form,
|
||||
'fields': intro_save_fields,
|
||||
'state':[
|
||||
('end', 'Close', 'gtk-ok'),
|
||||
]
|
||||
}
|
||||
},
|
||||
'save_yaml': {
|
||||
'actions': [_create_yaml],
|
||||
'result': {
|
||||
'type':'form',
|
||||
'arch':yaml_save_form,
|
||||
'fields': yaml_save_fields,
|
||||
'state':[
|
||||
('end', 'Close', 'gtk-ok'),
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
'end': {
|
||||
'actions': [],
|
||||
'result': {'type':'form', 'arch':info, 'fields':{}, 'state':[('end','OK')]}
|
||||
},
|
||||
class base_module_save(osv.osv_memory):
|
||||
_name = 'base.module.save'
|
||||
_description = "Base Module Save"
|
||||
|
||||
def default_get(self, cr, uid, fields, context):
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
mod = pool.get('ir.module.record')
|
||||
result = {}
|
||||
info = "Details of "+str(len(mod.recording_data))+" Operation(s):\n\n"
|
||||
res = super(base_module_save, self).default_get(cr, uid, fields, context=context)
|
||||
for line in mod.recording_data:
|
||||
result.setdefault(line[0],{})
|
||||
result[line[0]].setdefault(line[1][3], {})
|
||||
result[line[0]][line[1][3]].setdefault(line[1][3], 0)
|
||||
result[line[0]][line[1][3]][line[1][3]]+=1
|
||||
for key1,val1 in result.items():
|
||||
info+=key1+"\n"
|
||||
for key2,val2 in val1.items():
|
||||
info+="\t"+key2+"\n"
|
||||
for key3,val3 in val2.items():
|
||||
info+="\t\t"+key3+" : "+str(val3)+"\n"
|
||||
if 'info_text' in fields:
|
||||
res.update({'info_text': info})
|
||||
if 'info_status' in fields:
|
||||
info_status = mod.recording and 'record' or 'no'
|
||||
res.update({'info_status': info_status})
|
||||
return res
|
||||
|
||||
_columns = {
|
||||
'info_text': fields.text('Information', readonly=True),
|
||||
'info_status': fields.selection([('no', 'Not Recording'),('record', 'Recording')], 'Status', readonly=True),
|
||||
'info_yaml': fields.boolean('YAML'),
|
||||
}
|
||||
base_module_publish('base_module_record.module_save')
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
def record_save(self, cr, uid, ids, context):
|
||||
data = self.read(cr, uid, ids, [], context=context)[0]
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
mod = pool.get('ir.module.record')
|
||||
mod_obj = self.pool.get('ir.model.data')
|
||||
if len(mod.recording_data):
|
||||
if data['info_yaml']:
|
||||
pool = pooler.get_pool(cr.dbname)
|
||||
mod = pool.get('ir.module.record')
|
||||
res=_create_yaml(self, cr, uid, data, context)
|
||||
model_data_ids = mod_obj.search(cr, uid,[('model', '=', 'ir.ui.view'), ('name', '=', 'yml_save_form_view')], context=context)
|
||||
resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
|
||||
return {
|
||||
'name': _('Message'),
|
||||
'context': {
|
||||
'default_yaml_file': tools.ustr(res['yaml_file']),
|
||||
},
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'res_model': 'base.module.record.objects',
|
||||
'views': [(resource_id, 'form')],
|
||||
'type': 'ir.actions.act_window',
|
||||
'target': 'new',
|
||||
}
|
||||
else:
|
||||
model_data_ids = mod_obj.search(cr, uid,[('model', '=', 'ir.ui.view'), ('name', '=', 'info_start_form_view')], context=context)
|
||||
resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
|
||||
return {
|
||||
'name': _('Message'),
|
||||
'context': context,
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'res_model': 'base.module.record.objects',
|
||||
'views': [(resource_id, 'form')],
|
||||
'type': 'ir.actions.act_window',
|
||||
'target': 'new',
|
||||
}
|
||||
model_data_ids = mod_obj.search(cr, uid,[('model', '=', 'ir.ui.view'), ('name', '=', 'module_recording_message_view')], context=context)
|
||||
resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
|
||||
|
||||
return {
|
||||
'name': _('Message'),
|
||||
'context': context,
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'res_model': 'base.module.record.objects',
|
||||
'views': [(resource_id, 'form')],
|
||||
'type': 'ir.actions.act_window',
|
||||
'target': 'new',
|
||||
}
|
||||
base_module_save()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
Loading…
Reference in New Issue