bugfix_lp_331245

bzr revid: fp@tinyerp.com-20090226201745-ot01ir2gy89n18xm
This commit is contained in:
Fabien Pinckaers 2009-02-26 21:17:45 +01:00
parent b30ff04829
commit e3bcb6b8be
6 changed files with 38 additions and 60 deletions

View File

@ -1,3 +1,3 @@
./bin/addons/*
./bin/filestore*
*.pyc
.*.swp
.bzrignore

View File

@ -163,10 +163,6 @@ class res_partner(osv.osv):
'customer': lambda *a: 1,
'category_id': _default_category,
}
_sql_constraints = [
('name_uniq', 'unique (name)', 'The name of the partner must be unique !')
]
def copy(self, cr, uid, id, default=None, context={}):
name = self.read(cr, uid, [id], ['name'])[0]['name']
default.update({'name': name+' (copy)'})

View File

@ -30,7 +30,7 @@ email_send_form = '''<?xml version="1.0"?>
<newline/>
<field name="subject"/>
<newline/>
<field name="text"/>
<field name="text" widget="text_html"/>
</form>'''
email_send_fields = {

View File

@ -2285,60 +2285,42 @@ class orm(orm_template):
self.pool._init_parent[self._name]=True
else:
for id in ids:
# Find Position of the element
if vals[self._parent_name]:
cr.execute('select parent_left,parent_right,id from '+self._table+' where '+self._parent_name+'=%s order by '+(self._parent_order or self._order), (vals[self._parent_name],))
pleft_old = pright_old = None
result_p = cr.fetchall()
for (pleft,pright,pid) in result_p:
if pid == id:
break
pleft_old = pleft
pright_old = pright
if not pleft_old:
cr.execute('select parent_left,parent_right from '+self._table+' where id=%s', (vals[self._parent_name],))
pleft_old,pright_old = cr.fetchone()
res = (pleft_old, pright_old)
else:
cr.execute('SELECT parent_left,parent_right FROM '+self._table+' WHERE id IS NULL')
res = cr.fetchone()
if res:
pleft,pright = res
else:
cr.execute('select max(parent_right),max(parent_right)+1 from '+self._table)
pleft,pright = cr.fetchone()
cr.execute('select parent_left,parent_right,id from '+self._table+' where id in ('+','.join(map(lambda x:'%s',ids))+')', ids)
dest = pleft + 1
for cleft,cright,cid in cr.fetchall():
if cleft > pleft:
treeshift = pleft - cleft + 1
leftbound = pleft+1
rightbound = cleft-1
cwidth = cright-cleft+1
leftrange = cright
rightrange = pleft
cr.execute('select parent_left,parent_right,id from '+self._table+' where '+self._parent_name+' is null order by '+(self._parent_order or self._order))
result_p = cr.fetchall()
position = None
for (pleft,pright,pid) in result_p:
if pid == id:
break
position = pright+1
# It's the first node of the parent: position = parent_left+1
if not position:
if not vals[self._parent_name]:
position = 1
else:
treeshift = pleft - cright
leftbound = cright + 1
rightbound = pleft
cwidth = cleft-cright-1
leftrange = pleft+1
rightrange = cleft
cr.execute('UPDATE '+self._table+'''
SET
parent_left = CASE
WHEN parent_left BETWEEN %s AND %s THEN parent_left + %s
WHEN parent_left BETWEEN %s AND %s THEN parent_left + %s
ELSE parent_left
END,
parent_right = CASE
WHEN parent_right BETWEEN %s AND %s THEN parent_right + %s
WHEN parent_right BETWEEN %s AND %s THEN parent_right + %s
ELSE parent_right
END
WHERE
parent_left<%s OR parent_right>%s;
''', (leftbound,rightbound,cwidth,cleft,cright,treeshift,leftbound,rightbound,
cwidth,cleft,cright,treeshift,leftrange,rightrange))
cr.execute('select parent_left from '+self._table+' where id=%s', (vals[self._parent_name],))
position = cr.fetchone()[0]+1
# We have the new position !
cr.execute('select parent_left,parent_right from '+self._table+' where id=%s', (id,))
pleft,pright = cr.fetchone()
distance = pright - pleft + 1
if position>pleft and position<=pright:
raise except_orm(_('UserError'), _('Recursivity Detected.'))
if pleft<position:
cr.execute('update '+self._table+' set parent_left=parent_left+%s where parent_left>=%s', (distance, position))
cr.execute('update '+self._table+' set parent_right=parent_right+%s where parent_right>=%s', (distance, position))
cr.execute('update '+self._table+' set parent_left=parent_left+%s, parent_right=parent_right+%s where parent_left>=%s and parent_left<%s', (position-pleft,position-pleft, pleft, pright))
else:
cr.execute('update '+self._table+' set parent_left=parent_left+%s where parent_left>=%s', (distance, position))
cr.execute('update '+self._table+' set parent_right=parent_right+%s where parent_right>=%s', (distance, position))
cr.execute('update '+self._table+' set parent_left=parent_left-%s, parent_right=parent_right-%s where parent_left>=%s and parent_left<%s', (pleft-position+distance,pleft-position+distance, pleft+distance, pright+distance))
result = self._store_get_values(cr, user, ids, vals.keys(), context)
for order, object, ids, fields in result:

View File

@ -40,11 +40,10 @@ def check_super(passwd):
return True
else:
raise Exception('AccessDenied')
def check(db, uid, passwd):
if _uid_cache.get(db, {}).get(uid) == passwd:
return True
cr = pooler.get_db(db).cursor()
cr.execute('select count(*) from res_users where id=%s and password=%s', (int(uid), passwd))
res = cr.fetchone()[0]

View File

@ -304,6 +304,7 @@ def reverse_enumerate(l):
#----------------------------------------------------------
def email_send(email_from, email_to, subject, body, email_cc=None, email_bcc=None, reply_to=False, attach=None, tinycrm=False, ssl=False, debug=False, subtype='plain'):
"""Send an email."""
print 'sending', email_from, email_to, subject, body
import smtplib
from email.MIMEText import MIMEText
from email.MIMEBase import MIMEBase