Arnaud Pineux (OpenERP) has proposed merging 
lp:~openerp-dev/openobject-addons/trunk-bug-1062258-api into 
lp:openobject-addons.

Requested reviews:
  OpenERP Core Team (openerp)
Related bugs:
  Bug #1062258 in OpenERP Addons: "[Trunk/6.1] External file storage not 
working"
  https://bugs.launchpad.net/openobject-addons/+bug/1062258

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-1062258-api/+merge/133915
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-1062258-api/+merge/133915
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-bug-1062258-api.
=== modified file 'base_report_designer/plugin/openerp_report_designer/bin/script/AddAttachment.py'
--- base_report_designer/plugin/openerp_report_designer/bin/script/AddAttachment.py	2012-10-02 11:12:31 +0000
+++ base_report_designer/plugin/openerp_report_designer/bin/script/AddAttachment.py	2012-11-12 13:14:24 +0000
@@ -60,6 +60,7 @@
     uid = 3
 
 class AddAttachment(unohelper.Base, XJobExecutor ):
+    print "Add Attachment"
     Kind = {
         'PDF' : 'pdf',
         'OpenOffice': 'sxw',

=== modified file 'document/document.py'
--- document/document.py	2012-10-25 13:09:30 +0000
+++ document/document.py	2012-11-12 13:14:24 +0000
@@ -283,6 +283,7 @@
         return False
 
     def unlink(self, cr, uid, ids, context=None):
+        attachment_ref = self.pool.get('ir.attachment')
         stor = self.pool.get('document.storage')
         unres = []
         # We have to do the unlink in 2 stages: prepare a list of actual
@@ -290,6 +291,8 @@
         # rolled back) and then unlink the files. The list wouldn't exist
         # after we discard the objects
         ids = self.search(cr, uid, [('id','in',ids)])
+        canUnlink = 0   #If canUnlink is bigger than 1 it means that the document has more than 1 attachement.
+                        #We therefore cannot unlink that document.
         for f in self.browse(cr, uid, ids, context=context):
             # TODO: update the node cache
             par = f.parent_id
@@ -299,16 +302,23 @@
                     storage_id = par.storage_id
                     break
                 par = par.parent_id
+            #We get the ids of attachement that correspond to the document
+            attachment_ids = attachment_ref.search(cr, uid, [('store_fname', '=', f.store_fname), ('parent_id.name', '=', f.parent_id.name)], context=context)
+            #If we have more than 1 attachment for a same file, we will not unlink it.
+            for att in attachment_ref.browse(cr,uid,attachment_ids,context=context):
+                canUnlink += 1
             #assert storage_id, "Strange, found file #%s w/o storage!" % f.id #TOCHECK: after run yml, it's fail
-            if storage_id:
-                r = stor.prepare_unlink(cr, uid, storage_id, f)
-                if r:
-                    unres.append(r)
-            else:
-                self.loggerdoc.warning("Unlinking attachment #%s %s that has no storage.",
-                                                f.id, f.name)
+            if canUnlink == 1:
+                if storage_id:
+                    r = stor.prepare_unlink(cr, uid, storage_id, f)
+                    if r:
+                        unres.append(r)
+                else:
+                    self.loggerdoc.warning("Unlinking attachment #%s %s that has no storage.",
+                                                    f.id, f.name)
         res = super(document_file, self).unlink(cr, uid, ids, context)
-        stor.do_unlink(cr, uid, unres)
+        if canUnlink == 1: 
+            stor.do_unlink(cr, uid, unres)
         return res
 
 document_file()

=== modified file 'document/document_storage.py'
--- document/document_storage.py	2012-10-25 13:09:30 +0000
+++ document/document_storage.py	2012-11-12 13:14:24 +0000
@@ -516,6 +516,8 @@
                     _logger.warning("ir.attachment #%d does not have a filename, trying the name." %ira.id)
                 # sfname = ira.name
             fpath = os.path.join(boo.path,ira.store_fname or ira.name)
+            print fpath
+            print os.path.exists(fpath)
             if os.path.exists(fpath):
                 return file(fpath,'rb').read()
             elif not ira.store_fname:

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to