[FIX] Delete and function tag should respect ref(XML_ID). Maintenance Case 262

lp bug: https://launchpad.net/bugs/675906 fixed

bzr revid: jvo@tinyerp.com-20101116215359-qcnfefkqhxsa2uym
This commit is contained in:
Jay (OpenERP) 2010-11-17 03:23:59 +05:30
parent 5afd1eaa8a
commit 1dde0f53da
1 changed files with 78 additions and 68 deletions

View File

@ -68,6 +68,18 @@ def _obj(pool, cr, uid, model_str, context=None):
model = pool.get(model_str) model = pool.get(model_str)
return lambda x: model.browse(cr, uid, x, context=context) return lambda x: model.browse(cr, uid, x, context=context)
def _get_idref(self, cr, uid, model_str, context, idref):
idref2 = dict(idref,
time=time,
DateTime=datetime,
timedelta=timedelta,
version=release.major_version,
ref=_ref(self, cr),
pytz=pytz)
if len(model_str):
idref2['obj'] = _obj(self.pool, cr, uid, model_str, context=context)
return idref2
def _fix_multiple_roots(node): def _fix_multiple_roots(node):
""" """
Surround the children of the ``node`` element of an XML field with a Surround the children of the ``node`` element of an XML field with a
@ -90,72 +102,68 @@ def _eval_xml(self, node, pool, cr, uid, idref, context=None):
if context is None: if context is None:
context = {} context = {}
if node.tag in ('field','value'): if node.tag in ('field','value'):
t = node.get('type','char') t = node.get('type','char')
f_model = node.get('model', '').encode('utf-8') f_model = node.get('model', '').encode('utf-8')
if node.get('search'): if node.get('search'):
f_search = node.get("search",'').encode('utf-8') f_search = node.get("search",'').encode('utf-8')
f_use = node.get("use",'id').encode('utf-8') f_use = node.get("use",'id').encode('utf-8')
f_name = node.get("name",'').encode('utf-8') f_name = node.get("name",'').encode('utf-8')
q = unsafe_eval(f_search, idref) idref2 = {}
ids = pool.get(f_model).search(cr, uid, q) if f_search:
if f_use != 'id': idref2 = _get_idref(self, cr, uid, f_model, context, idref)
ids = map(lambda x: x[f_use], pool.get(f_model).read(cr, uid, ids, [f_use])) q = unsafe_eval(f_search, idref2)
_cols = pool.get(f_model)._columns ids = pool.get(f_model).search(cr, uid, q)
if (f_name in _cols) and _cols[f_name]._type=='many2many': if f_use != 'id':
return ids ids = map(lambda x: x[f_use], pool.get(f_model).read(cr, uid, ids, [f_use]))
f_val = False _cols = pool.get(f_model)._columns
if len(ids): if (f_name in _cols) and _cols[f_name]._type=='many2many':
f_val = ids[0] return ids
if isinstance(f_val, tuple): f_val = False
f_val = f_val[0] if len(ids):
return f_val f_val = ids[0]
a_eval = node.get('eval','') if isinstance(f_val, tuple):
if a_eval: f_val = f_val[0]
idref2 = dict(idref, return f_val
time=time, a_eval = node.get('eval','')
DateTime=datetime, idref2 = {}
timedelta=timedelta, if a_eval:
version=release.major_version, idref2 = _get_idref(self, cr, uid, f_model, context, idref)
ref=lambda x: self.id_get(cr, False, x), try:
pytz=pytz) return unsafe_eval(a_eval, idref2)
if len(f_model): except Exception:
idref2['obj'] = _obj(self.pool, cr, uid, f_model, context=context) logger = logging.getLogger('init')
try: logger.warning('could not eval(%s) for %s in %s' % (a_eval, node.get('name'), context), exc_info=True)
return unsafe_eval(a_eval, idref2) return ""
except Exception: if t == 'xml':
logger = logging.getLogger('init') def _process(s, idref):
logger.warning('could not eval(%s) for %s in %s' % (a_eval, node.get('name'), context), exc_info=True) m = re.findall('[^%]%\((.*?)\)[ds]', s)
return "" for id in m:
if t == 'xml': if not id in idref:
def _process(s, idref): idref[id]=self.id_get(cr, False, id)
m = re.findall('[^%]%\((.*?)\)[ds]', s) return s % idref
for id in m: _fix_multiple_roots(node)
if not id in idref: return '<?xml version="1.0"?>\n'\
idref[id]=self.id_get(cr, False, id) +_process("".join([etree.tostring(n, encoding='utf-8')
return s % idref for n in node]),
_fix_multiple_roots(node) idref)
return '<?xml version="1.0"?>\n'\ if t in ('char', 'int', 'float'):
+_process("".join([etree.tostring(n, encoding='utf-8') d = node.text
for n in node]), if t == 'int':
idref) d = d.strip()
if t in ('char', 'int', 'float'): if d == 'None':
d = node.text return None
if t == 'int': else:
d = d.strip() return int(d.strip())
if d == 'None': elif t == 'float':
return None return float(d.strip())
else: return d
return int(d.strip()) elif t in ('list','tuple'):
elif t == 'float': res=[]
return float(d.strip()) for n in node.findall('./value'):
return d res.append(_eval_xml(self,n,pool,cr,uid,idref))
elif t in ('list','tuple'): if t=='tuple':
res=[] return tuple(res)
for n in node.findall('./value'): return res
res.append(_eval_xml(self,n,pool,cr,uid,idref))
if t=='tuple':
return tuple(res)
return res
elif node.tag == "getitem": elif node.tag == "getitem":
for n in node: for n in node:
res=_eval_xml(self,n,pool,cr,uid,idref) res=_eval_xml(self,n,pool,cr,uid,idref)
@ -273,11 +281,13 @@ form: module.record_id""" % (xml_id,)
def _tag_delete(self, cr, rec, data_node=None): def _tag_delete(self, cr, rec, data_node=None):
d_model = rec.get("model",'') d_model = rec.get("model",'')
d_search = rec.get("search",'') d_search = rec.get("search",'').encode('utf-8')
d_id = rec.get("id",'') d_id = rec.get("id",'')
ids = [] ids = []
if d_search: if d_search:
ids = self.pool.get(d_model).search(cr, self.uid, unsafe_eval(d_search)) idref = _get_idref(self, cr, self.uid, d_model, context={}, idref={})
ids = self.pool.get(d_model).search(cr, self.uid, unsafe_eval(d_search, idref))
if d_id: if d_id:
try: try:
ids.append(self.id_get(cr, d_model, d_id)) ids.append(self.id_get(cr, d_model, d_id))