Document: fix unlink, where storage_id is not at first parent.
authorP. Christeas <p_christ@hol.gr>
Fri, 27 Aug 2010 07:39:55 +0000 (10:39 +0300)
committerP. Christeas <p_christ@hol.gr>
Fri, 27 Aug 2010 07:39:55 +0000 (10:39 +0300)
The convention is that storage_id may exist at any level up the
parent folders, so we have to recursively search for it.

bzr revid: p_christ@hol.gr-20100827073955-eyja6mhhy7rt5peh

addons/document/document.py

index 46cf6d1..084d4bc 100644 (file)
@@ -240,7 +240,7 @@ class document_file(osv.osv):
             return bro.address_id.partner_id.id
         return False
 
-    def unlink(self, cr, uid, ids, context={}):
+    def unlink(self, cr, uid, ids, context=None):
         stor = self.pool.get('document.storage')
         unres = []
         # We have to do the unlink in 2 stages: prepare a list of actual
@@ -250,7 +250,15 @@ class document_file(osv.osv):
 
         for f in self.browse(cr, uid, ids, context):
             # TODO: update the node cache
-            r = stor.prepare_unlink(cr, uid, f.parent_id.storage_id, f)
+            par = f.parent_id
+            storage_id = None
+            while par:
+                if par.storage_id:
+                    storage_id = par.storage_id
+                    break
+                par = par.parent_id
+            assert storage_id, "Strange, found file #%s w/o storage!" % f.id
+            r = stor.prepare_unlink(cr, uid, storage_id, f)
             if r:
                 unres.append(r)
         res = super(document_file, self).unlink(cr, uid, ids, context)