2009-10-13 05:58:37 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2008-08-24 14:45:43 +00:00
|
|
|
##############################################################################
|
2009-11-30 10:35:59 +00:00
|
|
|
#
|
2008-11-12 11:50:10 +00:00
|
|
|
# OpenERP, Open Source Management Solution
|
2010-01-12 09:18:39 +00:00
|
|
|
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
2008-08-24 14:45:43 +00:00
|
|
|
#
|
2008-11-03 19:18:56 +00:00
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2009-10-14 11:15:34 +00:00
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
2008-08-24 14:45:43 +00:00
|
|
|
#
|
2008-11-03 19:18:56 +00:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2009-10-14 11:15:34 +00:00
|
|
|
# GNU Affero General Public License for more details.
|
2008-08-24 14:45:43 +00:00
|
|
|
#
|
2009-10-14 11:15:34 +00:00
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
2009-11-30 10:35:59 +00:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2008-08-24 14:45:43 +00:00
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
from xml.dom import minidom
|
|
|
|
from osv import fields,osv
|
|
|
|
import pooler
|
|
|
|
import string
|
2009-07-16 07:36:30 +00:00
|
|
|
import tools
|
2008-08-24 14:45:43 +00:00
|
|
|
|
2010-10-18 15:02:29 +00:00
|
|
|
|
2009-11-26 13:54:00 +00:00
|
|
|
class xElement(minidom.Element):
|
|
|
|
"""dom.Element with compact print
|
|
|
|
The Element in minidom has a problem: if printed, adds whitespace
|
|
|
|
around the text nodes. The standard will not ignore that whitespace.
|
|
|
|
This class simply prints the contained nodes in their compact form, w/o
|
|
|
|
added spaces.
|
|
|
|
"""
|
|
|
|
def writexml(self, writer, indent="", addindent="", newl=""):
|
|
|
|
writer.write(indent)
|
|
|
|
minidom.Element.writexml(self, writer, indent='', addindent='', newl='')
|
|
|
|
writer.write(newl)
|
|
|
|
|
|
|
|
def doc_createXElement(xdoc, tagName):
|
|
|
|
e = xElement(tagName)
|
|
|
|
e.ownerDocument = xdoc
|
|
|
|
return e
|
2008-11-12 11:50:10 +00:00
|
|
|
|
2010-03-23 07:57:48 +00:00
|
|
|
import yaml
|
2010-10-18 15:02:29 +00:00
|
|
|
from tools import yaml_tag # This import is not unused! Do not remove!
|
|
|
|
# Please do not override yaml_tag here: modify it in server bin/tools/yaml_tag.py
|
2010-03-23 07:57:48 +00:00
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
class base_module_record(osv.osv):
|
|
|
|
_name = "ir.module.record"
|
|
|
|
_columns = {
|
|
|
|
|
|
|
|
}
|
2009-07-14 16:15:47 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
2008-08-24 14:45:43 +00:00
|
|
|
self.recording = 0
|
|
|
|
self.recording_data = []
|
|
|
|
self.depends = {}
|
2009-07-14 16:15:47 +00:00
|
|
|
super(base_module_record, self).__init__(*args, **kwargs)
|
2008-08-24 14:45:43 +00:00
|
|
|
|
|
|
|
# To Be Improved
|
|
|
|
def _create_id(self, cr, uid, model, data):
|
|
|
|
i = 0
|
|
|
|
while True:
|
2008-10-18 17:17:09 +00:00
|
|
|
try:
|
|
|
|
name = filter(lambda x: x in string.letters, (data.get('name','') or '').lower())
|
|
|
|
except:
|
|
|
|
name=''
|
2010-04-27 07:50:30 +00:00
|
|
|
# name=data.get('name','') or ''.lower()
|
|
|
|
val = model.replace('.','_')+'_'+ name + str(i)
|
2008-08-24 14:45:43 +00:00
|
|
|
i+=1
|
|
|
|
if val not in self.ids.values():
|
|
|
|
break
|
|
|
|
return val
|
|
|
|
|
|
|
|
def _get_id(self, cr, uid, model, id):
|
2008-11-13 11:19:59 +00:00
|
|
|
if type(id)==type(()):
|
|
|
|
id=id[0]
|
2008-08-24 14:45:43 +00:00
|
|
|
if (model,id) in self.ids:
|
2010-04-30 14:08:06 +00:00
|
|
|
res_id = self.ids[(model,id)]
|
|
|
|
return res_id, False
|
2008-08-24 14:45:43 +00:00
|
|
|
dt = self.pool.get('ir.model.data')
|
|
|
|
dtids = dt.search(cr, uid, [('model','=',model), ('res_id','=',id)])
|
|
|
|
if not dtids:
|
2010-03-23 07:57:48 +00:00
|
|
|
return False, None
|
2008-08-24 14:45:43 +00:00
|
|
|
obj = dt.browse(cr, uid, dtids[0])
|
|
|
|
self.depends[obj.module] = True
|
|
|
|
return obj.module+'.'+obj.name, obj.noupdate
|
2010-04-19 13:37:31 +00:00
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
def _create_record(self, cr, uid, doc, model, data, record_id, noupdate=False):
|
2010-04-30 14:08:06 +00:00
|
|
|
data_pool = self.pool.get('ir.model.data')
|
2010-03-16 06:51:15 +00:00
|
|
|
model_pool = self.pool.get(model)
|
|
|
|
|
2008-11-20 05:02:38 +00:00
|
|
|
record = doc.createElement('record')
|
|
|
|
record.setAttribute("id", record_id)
|
|
|
|
record.setAttribute("model", model)
|
|
|
|
record_list = [record]
|
2010-04-30 14:08:06 +00:00
|
|
|
|
2010-03-16 06:51:15 +00:00
|
|
|
lids = data_pool.search(cr, uid, [('model','=',model)])
|
|
|
|
res = data_pool.read(cr, uid, lids[:1], ['module'])
|
2008-08-24 14:45:43 +00:00
|
|
|
if res:
|
|
|
|
self.depends[res[0]['module']]=True
|
2010-03-16 06:51:15 +00:00
|
|
|
fields = model_pool.fields_get(cr, uid)
|
2008-08-24 14:45:43 +00:00
|
|
|
for key,val in data.items():
|
|
|
|
if not (val or (fields[key]['type']=='boolean')):
|
|
|
|
continue
|
2011-09-29 10:08:02 +00:00
|
|
|
if (fields[key]['type'] in ('integer','float') or
|
|
|
|
fields[key]['type'] == 'selection' and isinstance(val, int)):
|
2008-08-24 14:45:43 +00:00
|
|
|
field = doc.createElement('field')
|
|
|
|
field.setAttribute("name", key)
|
|
|
|
field.setAttribute("eval", val and str(val) or 'False' )
|
|
|
|
record.appendChild(field)
|
|
|
|
elif fields[key]['type'] in ('boolean',):
|
|
|
|
field = doc.createElement('field')
|
|
|
|
field.setAttribute("name", key)
|
|
|
|
field.setAttribute("eval", val and '1' or '0' )
|
|
|
|
record.appendChild(field)
|
|
|
|
elif fields[key]['type'] in ('many2one',):
|
|
|
|
field = doc.createElement('field')
|
|
|
|
field.setAttribute("name", key)
|
|
|
|
if type(val) in (type(''),type(u'')):
|
|
|
|
id = val
|
|
|
|
else:
|
|
|
|
id,update = self._get_id(cr, uid, fields[key]['relation'], val)
|
|
|
|
noupdate = noupdate or update
|
|
|
|
if not id:
|
2010-03-16 06:51:15 +00:00
|
|
|
relation_pool = self.pool.get(fields[key]['relation'])
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
field.setAttribute("model", fields[key]['relation'])
|
2010-03-16 06:51:15 +00:00
|
|
|
fld_nm = relation_pool._rec_name
|
|
|
|
name = relation_pool.read(cr, uid, val,[fld_nm])[fld_nm] or False
|
2009-07-21 05:26:20 +00:00
|
|
|
field.setAttribute("search", str([(str(fld_nm) ,'=', name)]))
|
2008-08-24 14:45:43 +00:00
|
|
|
else:
|
|
|
|
field.setAttribute("ref", id)
|
|
|
|
record.appendChild(field)
|
|
|
|
elif fields[key]['type'] in ('one2many',):
|
|
|
|
for valitem in (val or []):
|
2008-11-20 10:55:11 +00:00
|
|
|
if valitem[0] in (0,1):
|
2010-03-16 06:51:15 +00:00
|
|
|
if key in model_pool._columns:
|
2010-10-18 14:40:50 +00:00
|
|
|
model_pool._columns[key]._fields_id
|
2008-10-18 14:44:10 +00:00
|
|
|
else:
|
2010-10-18 14:40:50 +00:00
|
|
|
model_pool._inherit_fields[key][2]._fields_id
|
2010-04-27 07:50:30 +00:00
|
|
|
if valitem[0] == 0:
|
2008-12-09 13:07:37 +00:00
|
|
|
newid = self._create_id(cr, uid, fields[key]['relation'], valitem[2])
|
2010-04-27 07:50:30 +00:00
|
|
|
valitem[1]=newid
|
|
|
|
else:
|
|
|
|
newid,update = self._get_id(cr, uid, fields[key]['relation'], valitem[1])
|
|
|
|
if not newid:
|
|
|
|
newid = self._create_id(cr, uid, fields[key]['relation'], valitem[2])
|
|
|
|
valitem[1]=newid
|
2009-09-03 13:06:49 +00:00
|
|
|
self.ids[(fields[key]['relation'], valitem[1])] = newid
|
2010-04-30 14:08:06 +00:00
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
childrecord, update = self._create_record(cr, uid, doc, fields[key]['relation'],valitem[2], newid)
|
|
|
|
noupdate = noupdate or update
|
|
|
|
record_list += childrecord
|
|
|
|
else:
|
|
|
|
pass
|
|
|
|
elif fields[key]['type'] in ('many2many',):
|
|
|
|
res = []
|
|
|
|
for valitem in (val or []):
|
|
|
|
if valitem[0]==6:
|
|
|
|
for id2 in valitem[2]:
|
|
|
|
id,update = self._get_id(cr, uid, fields[key]['relation'], id2)
|
2009-09-03 13:06:49 +00:00
|
|
|
self.ids[(fields[key]['relation'],id2)] = id
|
2008-08-24 14:45:43 +00:00
|
|
|
noupdate = noupdate or update
|
|
|
|
res.append(id)
|
|
|
|
field = doc.createElement('field')
|
|
|
|
field.setAttribute("name", key)
|
|
|
|
field.setAttribute("eval", "[(6,0,["+','.join(map(lambda x: "ref('%s')" % (x,), res))+'])]')
|
|
|
|
record.appendChild(field)
|
|
|
|
else:
|
2009-11-26 13:54:00 +00:00
|
|
|
field = doc_createXElement(doc, 'field')
|
2008-08-24 14:45:43 +00:00
|
|
|
field.setAttribute("name", key)
|
2009-11-26 13:54:00 +00:00
|
|
|
field.appendChild(doc.createTextNode(val))
|
2008-08-24 14:45:43 +00:00
|
|
|
record.appendChild(field)
|
2009-11-26 13:54:00 +00:00
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
return record_list, noupdate
|
|
|
|
|
2010-03-10 10:02:54 +00:00
|
|
|
def _create_yaml_record(self, cr, uid, model, data, record_id):
|
|
|
|
record={'model': model, 'id': str(record_id)}
|
2010-03-16 06:51:15 +00:00
|
|
|
|
|
|
|
model_pool = self.pool.get(model)
|
|
|
|
data_pool = self.pool.get('ir.model.data')
|
|
|
|
lids = data_pool.search(cr, uid, [('model','=',model)])
|
2010-04-30 14:08:06 +00:00
|
|
|
|
2010-03-16 06:51:15 +00:00
|
|
|
res = data_pool.read(cr, uid, lids[:1], ['module'])
|
2010-03-10 10:02:54 +00:00
|
|
|
attrs={}
|
|
|
|
if res:
|
|
|
|
self.depends[res[0]['module']]=True
|
2010-03-16 06:51:15 +00:00
|
|
|
fields = model_pool.fields_get(cr, uid)
|
2010-03-10 10:02:54 +00:00
|
|
|
defaults={}
|
2010-04-30 14:08:06 +00:00
|
|
|
try:
|
|
|
|
defaults[model] = model_pool.default_get(cr, uid, data)
|
|
|
|
except:
|
|
|
|
defaults[model]={}
|
2010-03-10 10:02:54 +00:00
|
|
|
for key,val in data.items():
|
|
|
|
if ((key in defaults[model]) and (val == defaults[model][key])) and not(fields[key].get('required',False)):
|
|
|
|
continue
|
2010-04-30 14:08:06 +00:00
|
|
|
if fields[key]['type'] in ('integer','float'):
|
|
|
|
if not val:
|
|
|
|
val=0.0
|
|
|
|
attrs[key] = val
|
|
|
|
elif not (val or (fields[key]['type']=='function')):
|
2010-03-10 10:02:54 +00:00
|
|
|
continue
|
|
|
|
elif fields[key]['type'] in ('boolean',):
|
|
|
|
if not val:
|
|
|
|
continue
|
|
|
|
attrs[key] = val
|
|
|
|
elif fields[key]['type'] in ('many2one',):
|
2010-03-16 06:51:15 +00:00
|
|
|
if type(val) in (type(''), type(u'')):
|
2010-03-10 10:02:54 +00:00
|
|
|
id = val
|
|
|
|
else:
|
2010-03-16 06:51:15 +00:00
|
|
|
id, update = self._get_id(cr, uid, fields[key]['relation'], val)
|
2010-03-10 10:02:54 +00:00
|
|
|
attrs[key] = str(id)
|
|
|
|
elif fields[key]['type'] in ('one2many',):
|
|
|
|
items=[[]]
|
|
|
|
for valitem in (val or []):
|
|
|
|
if valitem[0] in (0,1):
|
2010-03-16 06:51:15 +00:00
|
|
|
if key in model_pool._columns:
|
|
|
|
fname = model_pool._columns[key]._fields_id
|
2010-03-10 10:02:54 +00:00
|
|
|
else:
|
2010-03-16 06:51:15 +00:00
|
|
|
fname = model_pool._inherit_fields[key][2]._fields_id
|
2010-04-27 07:50:30 +00:00
|
|
|
del valitem[2][fname] #delete parent_field from child's fields list
|
|
|
|
|
|
|
|
childrecord = self._create_yaml_record(cr, uid, fields[key]['relation'],valitem[2], None)
|
2010-03-10 10:02:54 +00:00
|
|
|
items[0].append(childrecord['attrs'])
|
|
|
|
attrs[key] = items
|
|
|
|
elif fields[key]['type'] in ('many2many',):
|
|
|
|
if (key in defaults[model]) and (val[0][2] == defaults[model][key]):
|
|
|
|
continue
|
|
|
|
res = []
|
|
|
|
for valitem in (val or []):
|
|
|
|
if valitem[0]==6:
|
|
|
|
for id2 in valitem[2]:
|
|
|
|
id,update = self._get_id(cr, uid, fields[key]['relation'], id2)
|
|
|
|
self.ids[(fields[key]['relation'],id2)] = id
|
|
|
|
res.append(str(id))
|
|
|
|
m2m=[res]
|
|
|
|
if m2m[0]:
|
|
|
|
attrs[key] = m2m
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
attrs[key]=str(val)
|
|
|
|
except:
|
|
|
|
attrs[key]=tools.ustr(val)
|
2010-04-27 07:50:30 +00:00
|
|
|
attrs[key]=attrs[key].replace('"','\'')
|
2010-03-10 10:02:54 +00:00
|
|
|
record['attrs'] = attrs
|
|
|
|
return record
|
|
|
|
|
2009-04-16 09:40:59 +00:00
|
|
|
def get_copy_data(self, cr, uid, model, id, result):
|
2008-11-12 11:50:10 +00:00
|
|
|
res = []
|
2008-11-20 05:02:38 +00:00
|
|
|
obj=self.pool.get(model)
|
|
|
|
data=obj.read(cr, uid,[id])
|
|
|
|
if type(data)==type([]):
|
|
|
|
del data[0]['id']
|
|
|
|
data=data[0]
|
|
|
|
else:
|
|
|
|
del data['id']
|
|
|
|
|
2008-11-20 10:55:11 +00:00
|
|
|
mod_fields = obj.fields_get(cr, uid)
|
2008-11-20 05:02:38 +00:00
|
|
|
for f in filter(lambda a: isinstance(obj._columns[a], fields.function)\
|
|
|
|
and (not obj._columns[a].store),obj._columns):
|
|
|
|
del data[f]
|
2010-04-27 07:50:30 +00:00
|
|
|
|
2008-11-12 11:50:10 +00:00
|
|
|
for key,val in data.items():
|
2008-11-20 05:02:38 +00:00
|
|
|
if result.has_key(key):
|
|
|
|
continue
|
|
|
|
if mod_fields[key]['type'] == 'many2one':
|
|
|
|
if type(data[key])==type(True) or type(data[key])==type(1):
|
2008-11-12 11:50:10 +00:00
|
|
|
result[key]=data[key]
|
2009-09-24 10:46:21 +00:00
|
|
|
elif not data[key]:
|
2009-11-30 10:35:59 +00:00
|
|
|
result[key] = False
|
2008-11-12 11:50:10 +00:00
|
|
|
else:
|
|
|
|
result[key]=data[key][0]
|
|
|
|
|
2008-11-20 05:02:38 +00:00
|
|
|
elif mod_fields[key]['type'] in ('one2many',):
|
2010-03-10 10:02:54 +00:00
|
|
|
# continue # due to this start stop recording will not record one2many field
|
2008-11-20 05:02:38 +00:00
|
|
|
rel = mod_fields[key]['relation']
|
2008-11-12 11:50:10 +00:00
|
|
|
if len(data[key]):
|
2008-11-20 05:02:38 +00:00
|
|
|
res1=[]
|
2008-11-12 11:50:10 +00:00
|
|
|
for rel_id in data[key]:
|
2008-11-20 05:02:38 +00:00
|
|
|
res=[0,0]
|
|
|
|
res.append(self.get_copy_data(cr, uid,rel,rel_id,{}))
|
|
|
|
res1.append(res)
|
|
|
|
result[key]=res1
|
2008-11-12 11:50:10 +00:00
|
|
|
else:
|
|
|
|
result[key]=data[key]
|
|
|
|
|
2008-11-20 10:55:11 +00:00
|
|
|
elif mod_fields[key]['type'] == 'many2many':
|
2008-11-12 11:50:10 +00:00
|
|
|
result[key]=[(6,0,data[key])]
|
|
|
|
|
|
|
|
else:
|
|
|
|
result[key]=data[key]
|
2008-11-20 10:55:11 +00:00
|
|
|
for k,v in obj._inherits.items():
|
2008-11-12 11:50:10 +00:00
|
|
|
del result[v]
|
|
|
|
return result
|
|
|
|
|
2008-11-25 23:33:24 +00:00
|
|
|
def _create_function(self, cr, uid, doc, model, name, record_id):
|
|
|
|
record = doc.createElement('function')
|
|
|
|
record.setAttribute("name", name)
|
|
|
|
record.setAttribute("model", model)
|
|
|
|
record_list = [record]
|
|
|
|
|
|
|
|
value = doc.createElement('value')
|
|
|
|
value.setAttribute('eval', '[ref(\'%s\')]' % (record_id, ))
|
|
|
|
value.setAttribute('model', model)
|
|
|
|
|
|
|
|
record.appendChild(value)
|
|
|
|
return record_list, False
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
def _generate_object_xml(self, cr, uid, rec, recv, doc, result=None):
|
|
|
|
record_list = []
|
|
|
|
noupdate = False
|
2010-04-27 07:50:30 +00:00
|
|
|
if rec[3]=='write':
|
|
|
|
for id in rec[4]:
|
|
|
|
id,update = self._get_id(cr, uid, rec[2], id)
|
2008-08-24 14:45:43 +00:00
|
|
|
noupdate = noupdate or update
|
|
|
|
if not id:
|
|
|
|
continue
|
2010-04-27 07:50:30 +00:00
|
|
|
record,update = self._create_record(cr, uid, doc, rec[2], rec[5], id)
|
2008-08-24 14:45:43 +00:00
|
|
|
noupdate = noupdate or update
|
|
|
|
record_list += record
|
2010-04-27 07:50:30 +00:00
|
|
|
|
2008-11-25 23:33:24 +00:00
|
|
|
elif rec[4] in ('menu_create',):
|
|
|
|
for id in rec[5]:
|
|
|
|
id,update = self._get_id(cr, uid, rec[3], id)
|
|
|
|
noupdate = noupdate or update
|
|
|
|
if not id:
|
|
|
|
continue
|
|
|
|
record,update = self._create_function(cr, uid, doc, rec[3], rec[4], id)
|
|
|
|
noupdate = noupdate or update
|
|
|
|
record_list += record
|
|
|
|
|
2010-03-10 10:02:54 +00:00
|
|
|
elif rec[3]=='create':
|
|
|
|
id = self._create_id(cr, uid, rec[2],rec[4])
|
|
|
|
record,noupdate = self._create_record(cr, uid, doc, rec[2], rec[4], id)
|
2010-04-19 13:37:31 +00:00
|
|
|
self.ids[(rec[2], result)] = id
|
2008-08-24 14:45:43 +00:00
|
|
|
record_list += record
|
2008-11-12 11:50:10 +00:00
|
|
|
|
2010-03-10 10:02:54 +00:00
|
|
|
elif rec[3]=='copy':
|
|
|
|
data=self.get_copy_data(cr,uid,rec[2],rec[4],rec[5])
|
|
|
|
copy_rec=(rec[0],rec[1],rec[2],rec[3],rec[4],data,rec[5])
|
2008-11-12 11:50:10 +00:00
|
|
|
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
|
2010-03-10 10:02:54 +00:00
|
|
|
id = self._create_id(cr, uid, rec[2],rec[5])
|
|
|
|
record,noupdate = self._create_record(cr, uid, doc, rec[2], rec[5], id)
|
|
|
|
self.ids[(rec[2], result)] = id
|
2008-11-12 11:50:10 +00:00
|
|
|
record_list += record
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
return record_list,noupdate
|
2008-11-12 11:50:10 +00:00
|
|
|
|
2010-03-10 10:02:54 +00:00
|
|
|
def _generate_object_yaml(self, cr, uid, rec, result=None):
|
|
|
|
if self.mode=="create":
|
2010-04-30 14:08:06 +00:00
|
|
|
yml_id = self._create_id(cr, uid, rec[2],rec[4])
|
|
|
|
self.ids[(rec[2], result)] = yml_id
|
|
|
|
record = self._create_yaml_record(cr, uid, rec[2], rec[4], yml_id)
|
2010-03-10 10:02:54 +00:00
|
|
|
return record
|
2010-03-18 12:01:47 +00:00
|
|
|
if self.mode=="workflow":
|
|
|
|
id,update = self._get_id(cr, uid, rec[2], rec[4])
|
|
|
|
data = {}
|
|
|
|
data['model'] = rec[2]
|
|
|
|
data['action'] = rec[3]
|
|
|
|
data['ref'] = id
|
|
|
|
return data
|
2010-03-23 07:57:48 +00:00
|
|
|
if self.mode=="write":
|
|
|
|
id,update = self._get_id(cr, uid, rec[2],rec[4][0])
|
|
|
|
record = self._create_yaml_record(cr, uid, rec[2], rec[5], id)
|
|
|
|
return record
|
2010-03-10 10:02:54 +00:00
|
|
|
data=self.get_copy_data(cr,uid,rec[2],rec[4],rec[5])
|
|
|
|
copy_rec=(rec[0],rec[1],rec[2],rec[3],rec[4],data,rec[5])
|
|
|
|
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[2],rec[5])
|
|
|
|
record = self._create_yaml_record(cr, uid, str(rec[2]), rec[5], id)
|
|
|
|
self.ids[(rec[2], result)] = id
|
|
|
|
return record
|
|
|
|
|
2010-04-30 14:08:06 +00:00
|
|
|
def _generate_function_yaml(self, cr, uid, args):
|
|
|
|
db, uid, model, action, ids, context = args
|
|
|
|
temp_context = context.copy()
|
|
|
|
active_id = temp_context['active_id']
|
|
|
|
active_model = temp_context['active_model']
|
|
|
|
active_id, update = self._get_id(cr, uid, active_model, active_id)
|
|
|
|
if not active_id:
|
|
|
|
active_id = 1
|
|
|
|
rec_id, noupdate = self._get_id(cr, uid, model, ids[0])
|
|
|
|
temp_context['active_id'] = "ref('%s')"%unicode(active_id)
|
|
|
|
temp_context['active_ids'][0] = "ref('%s')"%str(active_id)
|
|
|
|
function={}
|
|
|
|
function['model'] = model
|
|
|
|
function['action'] = action
|
|
|
|
attrs = "self.%s(cr, uid, [ref('%s')], {" %(action, rec_id, )
|
|
|
|
for k, v in temp_context.iteritems():
|
|
|
|
if isinstance(v, str):
|
|
|
|
f= "'"+k+"': "+"'%s'"%v + ", "
|
|
|
|
else:
|
|
|
|
v=str(v).replace('"', '')
|
|
|
|
f= "'"+k+"': "+"%s"%v + ", "
|
|
|
|
attrs = attrs + f
|
|
|
|
attrs=str(attrs)+'})'
|
|
|
|
function['attrs'] = attrs
|
|
|
|
return function
|
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
def _generate_assert_xml(self, rec, doc):
|
|
|
|
pass
|
2008-12-09 13:22:04 +00:00
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
def generate_xml(self, cr, uid):
|
|
|
|
# Create the minidom document
|
2008-11-12 11:50:10 +00:00
|
|
|
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':
|
2010-03-18 12:01:47 +00:00
|
|
|
rec_id,noupdate = self._get_id(cr, uid, rec[1][2], rec[1][4])
|
2008-11-12 11:50:10 +00:00
|
|
|
if not rec_id:
|
|
|
|
continue
|
|
|
|
data = doc.createElement("data")
|
2008-08-24 14:45:43 +00:00
|
|
|
terp.appendChild(data)
|
2008-11-12 11:50:10 +00:00
|
|
|
wkf = doc.createElement('workflow')
|
|
|
|
data.appendChild(wkf)
|
2010-04-19 13:37:31 +00:00
|
|
|
wkf.setAttribute("model", rec[1][2])
|
|
|
|
wkf.setAttribute("action", rec[1][3])
|
2008-11-12 11:50:10 +00:00
|
|
|
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':
|
2008-11-20 10:55:11 +00:00
|
|
|
pass
|
2009-02-03 14:08:30 +00:00
|
|
|
return doc.toprettyxml(indent="\t").encode('utf-8')
|
2010-03-10 10:02:54 +00:00
|
|
|
|
|
|
|
def generate_yaml(self, cr, uid):
|
|
|
|
self.ids = {}
|
|
|
|
if len(self.recording_data):
|
2010-03-23 07:57:48 +00:00
|
|
|
yaml_file='''\n'''
|
2010-03-10 10:02:54 +00:00
|
|
|
|
|
|
|
for rec in self.recording_data:
|
|
|
|
if rec[1][3] == 'create':
|
|
|
|
self.mode="create"
|
2010-03-23 07:57:48 +00:00
|
|
|
elif rec[1][3] == 'write':
|
|
|
|
self.mode="write"
|
2010-03-10 10:02:54 +00:00
|
|
|
elif rec[1][3] == 'copy':
|
|
|
|
self.mode="copy"
|
2010-03-18 12:01:47 +00:00
|
|
|
elif rec[0] == 'workflow':
|
|
|
|
self.mode="workflow"
|
2010-04-30 14:08:06 +00:00
|
|
|
elif rec[0] == 'osv_memory_action':
|
|
|
|
self.mode='osv_memory_action'
|
2010-03-10 10:02:54 +00:00
|
|
|
else:
|
|
|
|
continue
|
2010-03-18 12:01:47 +00:00
|
|
|
if self.mode == "workflow":
|
2010-08-17 07:04:50 +00:00
|
|
|
record = self._generate_object_yaml(cr, uid, rec[1],rec[0])
|
|
|
|
yaml_file += "!comment Performing a workflow action %s on module %s"%(record['action'], record['model']) + '''\n'''
|
|
|
|
object = yaml.load(unicode('''\n !workflow %s \n'''%record,'iso-8859-1'))
|
2010-04-19 13:37:31 +00:00
|
|
|
yaml_file += str(object) + '''\n\n'''
|
2010-04-30 14:08:06 +00:00
|
|
|
elif self.mode == 'osv_memory_action':
|
2010-08-17 07:04:50 +00:00
|
|
|
osv_action = self._generate_function_yaml(cr, uid, rec[1])
|
|
|
|
yaml_file += "!comment Performing an osv_memory action %s on module %s"%(osv_action['action'], osv_action['model']) + '''\n'''
|
|
|
|
osv_action = yaml.load(unicode('''\n !python %s \n'''%osv_action,'iso-8859-1'))
|
2010-04-30 14:08:06 +00:00
|
|
|
yaml_file += str(osv_action) + '''\n'''
|
2010-08-17 07:04:50 +00:00
|
|
|
attrs = yaml.dump(osv_action.attrs, default_flow_style=False)
|
|
|
|
attrs = attrs.replace("''", '"')
|
|
|
|
attrs = attrs.replace("'", '')
|
2010-04-30 14:08:06 +00:00
|
|
|
yaml_file += attrs + '''\n\n'''
|
2010-03-18 12:01:47 +00:00
|
|
|
else:
|
2010-08-17 07:04:50 +00:00
|
|
|
record = self._generate_object_yaml(cr, uid, rec[1], rec[3])
|
2010-04-27 07:50:30 +00:00
|
|
|
if self.mode == "create" or self.mode == "copy":
|
2010-08-17 07:04:50 +00:00
|
|
|
yaml_file += "!comment Creating a %s record"%(record['model']) + '''\n'''
|
2010-04-27 07:50:30 +00:00
|
|
|
else:
|
2010-08-17 07:04:50 +00:00
|
|
|
yaml_file += "!comment Modifying a %s record"%(record['model']) + '''\n'''
|
|
|
|
object = yaml.load(unicode('''\n !record %s \n'''%record,'iso-8859-1'))
|
2010-03-23 07:57:48 +00:00
|
|
|
yaml_file += str(object) + '''\n'''
|
2010-08-17 07:04:50 +00:00
|
|
|
attrs = yaml.dump(object.attrs, default_flow_style=False)
|
2010-03-23 07:57:48 +00:00
|
|
|
yaml_file += attrs + '''\n\n'''
|
|
|
|
|
|
|
|
yaml_result=''''''
|
|
|
|
for line in yaml_file.split('\n'):
|
|
|
|
line=line.replace("''","'")
|
2010-04-30 14:08:06 +00:00
|
|
|
if (line.find('!record') == 0) or (line.find('!workflow') == 0) or (line.find('!python') == 0):
|
2010-04-19 13:37:31 +00:00
|
|
|
line = "- \n" + " " + line
|
|
|
|
elif line.find('!comment') == 0:
|
|
|
|
line=line.replace('!comment','- \n ')
|
2010-03-23 07:57:48 +00:00
|
|
|
elif line.find('- -') != -1:
|
|
|
|
line=line.replace('- -',' -')
|
|
|
|
line = " " + line
|
|
|
|
else:
|
|
|
|
line = " " + line
|
|
|
|
yaml_result += line + '''\n'''
|
|
|
|
|
|
|
|
return yaml_result
|
2010-03-10 10:02:54 +00:00
|
|
|
|
2008-08-24 14:45:43 +00:00
|
|
|
base_module_record()
|
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
|
|
|