import copy
import datetime
import logging
+import warnings
import operator
import pickle
import re
lines = []
data = map(lambda x: '', range(len(fields)))
+ done = []
for fpos in range(len(fields)):
- done = []
f = fields[fpos]
if f:
r = row
fields2 = map(lambda x: (x[:i+1]==f[:i+1] and x[i+1:]) \
or [], fields)
if fields2 in done:
- break
+ if [x for x in fields2 if x]:
+ break
done.append(fields2)
for row2 in r:
lines2 = self.__export_row(cr, uid, row2, fields2,
for key in self.pool._sql_error.keys():
if key in e[0]:
msg = self.pool._sql_error[key]
+ if hasattr(msg, '__call__'):
+ msg = msg(cr, uid, [res_id,], context=context)
break
return (-1, res, 'Line ' + str(counter) +' : ' + msg, '')
if isinstance(e, osv.orm.except_orm):
# Check presence of __call__ directly instead of using
# callable() because it will be deprecated as of Python 3.0
if hasattr(msg, '__call__'):
- txt_msg, params = msg(self, cr, uid, ids)
- tmp_msg = trans._get_source(cr, uid, self._name, 'constraint', lng, source=txt_msg) or txt_msg
- translated_msg = tmp_msg % params
+ tmp_msg = msg(self, cr, uid, ids, context=context)
+ # Why translate something that has been generated dynamically?
+ # tmp_msg = trans._get_source(cr, uid, self._name, 'constraint', lng, source=txt_msg) or txt_msg
+ if isinstance(tmp_msg, tuple):
+ tmp_msg, params = tmp_msg
+ translated_msg = tmp_msg % params
+ else:
+ translated_msg = tmp_msg
else:
translated_msg = trans._get_source(cr, uid, self._name, 'constraint', lng, source=msg) or msg
error_msgs.append(
else:
default['state'] = self._defaults['state']
- context_wo_lang = context
+ context_wo_lang = context.copy()
if 'lang' in context:
del context_wo_lang['lang']
- data = self.read(cr, uid, [id], context=context_wo_lang)[0]
+ data = self.read(cr, uid, [id,], context=context_wo_lang)
+ if data:
+ data = data[0]
+ else:
+ raise IndexError( _("Record #%d of %s not found, cannot copy!") %( id, self._name))
fields = self.fields_get(cr, uid, context=context)
for f in fields:
return cr.fetchone()[0] == len(ids)
def check_recursion(self, cr, uid, ids, parent=None):
+ warnings.warn("You are using deprecated %s.check_recursion(). Please use the '_check_recursion()' instead!" % \
+ self._name, DeprecationWarning, stacklevel=3)
+ assert ' ' not in (parent or '')
+ return self._check_recursion(cr, uid, ids, parent)
+
+ def _check_recursion(self, cr, uid, ids, parent=None):
"""
Verifies that there is no loop in a hierarchical structure of records,
by following the parent relationship using the **parent** field until a loop