summaryrefslogtreecommitdiff
path: root/addons/document/document.py
diff options
context:
space:
mode:
authorFabien Pinckaers <fp@tinyerp.com>2009-02-05 17:58:46 +0100
committerFabien Pinckaers <fp@tinyerp.com>2009-02-05 17:58:46 +0100
commit801cc3605274c458d716bbcc8d9581fd87d51255 (patch)
tree07e5c96a78e8a17e67881a4331832a313afb8f09 /addons/document/document.py
parent47faac97372f09bc4b2f4da13f4dfc2a85e47df8 (diff)
parent76f327da8e5a4df8166c9354bc543d3102ce65ac (diff)
modifs
bzr revid: fp@tinyerp.com-20090205165846-fcpzyp4c0t2z6e42
Diffstat (limited to 'addons/document/document.py')
-rw-r--r--addons/document/document.py41
1 files changed, 22 insertions, 19 deletions
diff --git a/addons/document/document.py b/addons/document/document.py
index 6cc2e7fd7e3..84a13af5564 100644
--- a/addons/document/document.py
+++ b/addons/document/document.py
@@ -510,24 +510,27 @@ class document_file(osv.osv):
if not value:
return True
#if (not context) or context.get('store_method','fs')=='fs':
- path = self._get_filestore(cr)
- if not os.path.isdir(path):
- os.makedirs(path)
- flag = None
- # This can be improved
- for dirs in os.listdir(path):
- if os.path.isdir(os.path.join(path,dirs)) and len(os.listdir(os.path.join(path,dirs)))<4000:
- flag = dirs
- break
- flag = flag or create_directory(path)
- filename = random_name()
- fname = os.path.join(path, flag, filename)
- fp = file(fname,'wb')
- v = base64.decodestring(value)
- fp.write(v)
- filesize = os.stat(fname).st_size
- cr.execute('update ir_attachment set store_fname=%s,store_method=%s,file_size=%s where id=%s', (os.path.join(flag,filename),'fs',len(v),id))
- return True
+ try:
+ path = self._get_filestore(cr)
+ if not os.path.isdir(path):
+ os.makedirs(path)
+ flag = None
+ # This can be improved
+ for dirs in os.listdir(path):
+ if os.path.isdir(os.path.join(path,dirs)) and len(os.listdir(os.path.join(path,dirs)))<4000:
+ flag = dirs
+ break
+ flag = flag or create_directory(path)
+ filename = random_name()
+ fname = os.path.join(path, flag, filename)
+ fp = file(fname,'wb')
+ v = base64.decodestring(value)
+ fp.write(v)
+ filesize = os.stat(fname).st_size
+ cr.execute('update ir_attachment set store_fname=%s,store_method=%s,file_size=%s where id=%s', (os.path.join(flag,filename),'fs',len(v),id))
+ return True
+ except Exception,e :
+ raise except_orm('Error!', str(e))
_columns = {
'user_id': fields.many2one('res.users', 'Owner', select=1),
@@ -609,7 +612,7 @@ class document_file(osv.osv):
def create(self, cr, uid, vals, context={}):
vals['title']=vals['name']
- vals['parent_id'] = context.get('parent_id',False)
+ vals['parent_id'] = context.get('parent_id',False) or vals.get('parent_id',False)
if not vals.get('res_id', False) and context.get('default_res_id',False):
vals['res_id']=context.get('default_res_id',False)
if not vals.get('res_model', False) and context.get('default_res_model',False):