fixed the following bugs in ModuleRecorder: It generates an error when the MR tries to set an ID more then 64 char to a record.
* It only record on create, it doesn't record the duplicated records * I trying to put the '€' sign in a text box and got an Utf8 error * When creating an object from a one2many it add an non necessary line that causes an error at loading * When clicking on save without filling any field, it record an empty record that causes an error at loading bzr revid: nch@tinyerp.com-20081112115010-yoayy0ti3uh6xzf5
This commit is contained in:
parent
e83832b09e
commit
ff0a10ed5a
|
@ -1,7 +1,7 @@
|
|||
# -*- encoding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
|
||||
# $Id$
|
||||
#
|
||||
|
@ -26,6 +26,7 @@ import netsvc
|
|||
import pooler
|
||||
import string
|
||||
|
||||
|
||||
class base_module_record(osv.osv):
|
||||
_name = "ir.module.record"
|
||||
_columns = {
|
||||
|
@ -55,6 +56,8 @@ class base_module_record(osv.osv):
|
|||
return val
|
||||
|
||||
def _get_id(self, cr, uid, model, id):
|
||||
# if type(id)==type(()):
|
||||
# id=id[0]
|
||||
if (model,id) in self.ids:
|
||||
return self.ids[(model,id)], False
|
||||
dt = self.pool.get('ir.model.data')
|
||||
|
@ -66,14 +69,16 @@ class base_module_record(osv.osv):
|
|||
return obj.module+'.'+obj.name, obj.noupdate
|
||||
|
||||
def _create_record(self, cr, uid, doc, model, data, record_id, noupdate=False):
|
||||
record = doc.createElement('record')
|
||||
record.setAttribute("id", record_id)
|
||||
record.setAttribute("model", model)
|
||||
record_list=[]
|
||||
if record_id not in self.ids.values():
|
||||
record = doc.createElement('record')
|
||||
record.setAttribute("id", record_id)
|
||||
record.setAttribute("model", model)
|
||||
record_list = [record]
|
||||
lids = self.pool.get('ir.model.data').search(cr, uid, [('model','=',model)])
|
||||
res = self.pool.get('ir.model.data').read(cr, uid, lids[:1], ['module'])
|
||||
if res:
|
||||
self.depends[res[0]['module']]=True
|
||||
record_list = [record]
|
||||
fields = self.pool.get(model).fields_get(cr, uid)
|
||||
for key,val in data.items():
|
||||
if not (val or (fields[key]['type']=='boolean')):
|
||||
|
@ -142,16 +147,63 @@ class base_module_record(osv.osv):
|
|||
|
||||
val = val and ('"""%s"""' % val.replace('\\', '\\\\').replace('"', '\"')) or 'False'
|
||||
if isinstance(val, basestring):
|
||||
val=val.encode('utf8')
|
||||
val = val.decode('utf8')
|
||||
|
||||
field.setAttribute(u"eval", val)
|
||||
record.appendChild(field)
|
||||
return record_list, noupdate
|
||||
|
||||
def get_o2m_list(self,cr,uid,model,id):
|
||||
result={}
|
||||
data=self.pool.get(model).read(cr, uid,id)
|
||||
del data['id']
|
||||
fields = self.pool.get(model).fields_get(cr, uid)
|
||||
res=[0,0]
|
||||
for key,val in data.items():
|
||||
if fields[key]['type'] == 'many2one':
|
||||
result[key]=data[key][0]
|
||||
else:
|
||||
result[key]=data[key]
|
||||
res.append(result)
|
||||
return res
|
||||
|
||||
|
||||
def get_copy_data(self, cr, uid,model,id):
|
||||
result={}
|
||||
res = []
|
||||
data=self.pool.get(model).read(cr, uid,id)
|
||||
del data['id']
|
||||
fields = self.pool.get(model).fields_get(cr, uid)
|
||||
|
||||
for key,val in data.items():
|
||||
if fields[key]['type'] == 'many2one':
|
||||
if type(data[key])==type(True):
|
||||
result[key]=data[key]
|
||||
else:
|
||||
result[key]=data[key][0]
|
||||
|
||||
elif fields[key]['type'] in ('one2many',):
|
||||
rel = fields[key]['relation']
|
||||
if len(data[key]):
|
||||
for rel_id in data[key]:
|
||||
res.append((self.get_o2m_list(cr, uid,rel,rel_id)))
|
||||
result[key]=res
|
||||
else:
|
||||
result[key]=data[key]
|
||||
|
||||
elif fields[key]['type'] == 'many2many':
|
||||
result[key]=[(6,0,data[key])]
|
||||
|
||||
else:
|
||||
result[key]=data[key]
|
||||
for k,v in self.pool.get(model)._inherits.items():
|
||||
del result[v]
|
||||
return result
|
||||
|
||||
def _generate_object_xml(self, cr, uid, rec, recv, doc, result=None):
|
||||
record_list = []
|
||||
noupdate = False
|
||||
if rec[4]=='write':
|
||||
if rec[4]=='write' :
|
||||
for id in rec[5]:
|
||||
id,update = self._get_id(cr, uid, rec[3], id)
|
||||
noupdate = noupdate or update
|
||||
|
@ -160,47 +212,62 @@ class base_module_record(osv.osv):
|
|||
record,update = self._create_record(cr, uid, doc, rec[3], rec[6], id)
|
||||
noupdate = noupdate or update
|
||||
record_list += record
|
||||
|
||||
elif rec[4]=='create':
|
||||
id = self._create_id(cr, uid, rec[3],rec[5])
|
||||
record,noupdate = self._create_record(cr, uid, doc, rec[3], rec[5], id)
|
||||
self.ids[(rec[3],result)] = id
|
||||
record_list += record
|
||||
|
||||
elif rec[4]=='copy':
|
||||
data=self.get_copy_data(cr,uid,rec[3],rec[5])
|
||||
copy_rec=(rec[0],rec[1],rec[2],rec[3],rec[4],rec[5],data,rec[7])
|
||||
rec=copy_rec
|
||||
rec_data=[(self.recording_data[0][0],rec,self.recording_data[0][2],self.recording_data[0][3])]
|
||||
self.recording_data=rec_data
|
||||
id = self._create_id(cr, uid, rec[3],rec[6])
|
||||
record,noupdate = self._create_record(cr, uid, doc, rec[3], rec[6], id)
|
||||
self.ids[(rec[3],result)] = id
|
||||
record_list += record
|
||||
|
||||
return record_list,noupdate
|
||||
|
||||
def _generate_assert_xml(self, rec, doc):
|
||||
pass
|
||||
def generate_xml(self, cr, uid):
|
||||
# Create the minidom document
|
||||
self.ids = {}
|
||||
doc = minidom.Document()
|
||||
terp = doc.createElement("openerp")
|
||||
doc.appendChild(terp)
|
||||
for rec in self.recording_data:
|
||||
if rec[0]=='workflow':
|
||||
rec_id,noupdate = self._get_id(cr, uid, rec[1][3], rec[1][5])
|
||||
if not rec_id:
|
||||
continue
|
||||
data = doc.createElement("data")
|
||||
terp.appendChild(data)
|
||||
wkf = doc.createElement('workflow')
|
||||
data.appendChild(wkf)
|
||||
wkf.setAttribute("model", rec[1][3])
|
||||
wkf.setAttribute("action", rec[1][4])
|
||||
if noupdate:
|
||||
data.setAttribute("noupdate", "1")
|
||||
wkf.setAttribute("ref", rec_id)
|
||||
if rec[0]=='query':
|
||||
res_list,noupdate = self._generate_object_xml(cr, uid, rec[1], rec[2], doc, rec[3])
|
||||
data = doc.createElement("data")
|
||||
if noupdate:
|
||||
data.setAttribute("noupdate", "1")
|
||||
if res_list:
|
||||
if len(self.recording_data):
|
||||
self.ids = {}
|
||||
doc = minidom.Document()
|
||||
terp = doc.createElement("openerp")
|
||||
doc.appendChild(terp)
|
||||
for rec in self.recording_data:
|
||||
if rec[0]=='workflow':
|
||||
rec_id,noupdate = self._get_id(cr, uid, rec[1][3], rec[1][5])
|
||||
if not rec_id:
|
||||
continue
|
||||
data = doc.createElement("data")
|
||||
terp.appendChild(data)
|
||||
for res in res_list:
|
||||
data.appendChild(res)
|
||||
elif rec[0]=='assert':
|
||||
pass
|
||||
res = doc.toprettyxml(indent="\t")
|
||||
return doc.toprettyxml(indent="\t").encode('utf8')
|
||||
wkf = doc.createElement('workflow')
|
||||
data.appendChild(wkf)
|
||||
wkf.setAttribute("model", rec[1][3])
|
||||
wkf.setAttribute("action", rec[1][4])
|
||||
if noupdate:
|
||||
data.setAttribute("noupdate", "1")
|
||||
wkf.setAttribute("ref", rec_id)
|
||||
if rec[0]=='query':
|
||||
res_list,noupdate = self._generate_object_xml(cr, uid, rec[1], rec[2], doc, rec[3])
|
||||
data = doc.createElement("data")
|
||||
if noupdate:
|
||||
data.setAttribute("noupdate", "1")
|
||||
if res_list:
|
||||
terp.appendChild(data)
|
||||
for res in res_list:
|
||||
data.appendChild(res)
|
||||
elif rec[0]=='assert':
|
||||
pass
|
||||
res = doc.toprettyxml(indent="\t")
|
||||
return doc.toprettyxml(indent="\t").encode('utf8')
|
||||
base_module_record()
|
||||
|
||||
def fnct_call(fnct):
|
||||
|
@ -209,6 +276,7 @@ def fnct_call(fnct):
|
|||
_old_args = args[5].copy()
|
||||
else:
|
||||
_old_args = None
|
||||
db=args[0]
|
||||
res = fnct(*args, **argv)
|
||||
pool = pooler.get_pool(args[0])
|
||||
mod = pool.get('ir.module.record')
|
||||
|
@ -216,7 +284,8 @@ def fnct_call(fnct):
|
|||
if args[4] not in ('default_get','read','fields_view_get','fields_get','search','search_count','name_search','name_get','get','request_get', 'get_sc'):
|
||||
if _old_args is not None:
|
||||
args[5].update(_old_args)
|
||||
mod.recording_data.append(('query', args, argv,res))
|
||||
if args[5]:
|
||||
mod.recording_data.append(('query', args, argv,res))
|
||||
return res
|
||||
return execute
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# -*- encoding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
|
||||
# $Id$
|
||||
#
|
||||
|
@ -24,6 +24,11 @@ import wizard
|
|||
import osv
|
||||
import pooler
|
||||
|
||||
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"/>
|
||||
|
@ -88,6 +93,7 @@ def _info_default(self, cr, uid, data, context):
|
|||
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], {})
|
||||
|
@ -144,6 +150,13 @@ def _create_module(self, cr, uid, data, context):
|
|||
'module_file': base64.encodestring(s.getvalue()),
|
||||
'module_filename': data['form']['directory_name']+'-'+data['form']['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):
|
||||
return 'info'
|
||||
else:
|
||||
return 'end'
|
||||
|
||||
class base_module_publish(wizard.interface):
|
||||
states = {
|
||||
|
@ -155,10 +168,14 @@ class base_module_publish(wizard.interface):
|
|||
'fields': info_start_fields,
|
||||
'state':[
|
||||
('end', 'Cancel', 'gtk-cancel'),
|
||||
('info', 'Continue', 'gtk-ok'),
|
||||
('check', 'Continue', 'gtk-ok'),
|
||||
]
|
||||
}
|
||||
},
|
||||
'check': {
|
||||
'actions': [],
|
||||
'result': {'type':'choice','next_state':_check}
|
||||
},
|
||||
'info': {
|
||||
'actions': [],
|
||||
'result': {
|
||||
|
@ -181,7 +198,11 @@ class base_module_publish(wizard.interface):
|
|||
('end', 'Close', 'gtk-ok'),
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
'end': {
|
||||
'actions': [],
|
||||
'result': {'type':'form', 'arch':info, 'fields':{}, 'state':[('end','OK')]}
|
||||
},
|
||||
}
|
||||
base_module_publish('base_module_record.module_save')
|
||||
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue