← Back to team overview

c2c-oerpscenario team mailing list archive

[Bug 753286] Re: [5.0] Copy of ir_attachment

 

Hello Azazahmed,

This is the piece of code where I'm doing the copy of the attachment:

attachment_obj = self.pool.get('ir.attachment')

attachment_id = attachment_obj.search(cr, uid, [('res_model','=','mrp.procurement'),('res_id','=',procurement.id)])
if attachment_id:
    logger.notifyChannel('mrp',level,'browse')
    attachment = attachment_obj.browse(cr, uid, attachment_id)[0]

    defaults = {}
    defaults = {
        'res_model':"purchase.order",
        'res_id':purchase_id,
    }

    logger.notifyChannel('mrp',level,'copy')
    attachment_obj.copy(cr, uid, attachment_id, defaults, context)

I'm copying all the attachments associated with the procurement so
sometimes it will be a list of attachments and sometimes it will be just
one attachment.

I finally fixed my problem modifying the document/document.py file:

def copy(self, cr, uid, id, default=None, context=None):
    if not default:
        default ={}
    if isinstance(id, (int, long)):
        id = [id]
    name = self.read(cr, uid, id)[0]['name']
    default.update({'name': name+ " (copy)"})
    return super(document_file,self).copy(cr,uid,id,default,context)

Basically I added the isinstance(id, (int, long)) check before
bracketing the ids, before that change it was always being bracketed
even if it was already a list

It well could be a problem in the way I pass the arguments but I haven't
been able to spot it. If that is the case please tell me, I am much
happier changing my code than modifying base classes

Kind regards,

Ignacio

-- 
You received this bug notification because you are a member of C2C
OERPScenario, which is subscribed to the OpenERP Project Group.
https://bugs.launchpad.net/bugs/753286

Title:
  [5.0] Copy of ir_attachment

Status in OpenERP Server:
  Incomplete

Bug description:
  An error is thrown when duplicating an attachment using
  self.pool.get('ir.attachment').copy( ... )

  Reason being the list of ids passed to the method gets "over
  bracketed" and therefore the select query throws an exception

  I attach some logs I added to the code for debuggin purposes

  First I list some logs I get when calling to self.pool.get('ir.attachment').search (this method works fine)
   [2011-04-07 10:12:57,002] ESC[32mESC[49mINFOESC[0m:ir_attachment.read:[3, 7]
   [2011-04-07 10:12:57,003] ESC[32mESC[49mINFOESC[0m:ir_attachment.check:begin
   [2011-04-07 10:12:57,003] ESC[32mESC[49mINFOESC[0m:ir_attachment.check:3,7
   [2011-04-07 10:12:57,004] ESC[32mESC[49mINFOESC[0m:ir_attachment.check:end

  Now the logs I get when making a call to the copy method (exception thrown)
   [2011-04-07 10:12:57,006] ESC[32mESC[49mINFOESC[0m:ir_attachment.read:[[3, 7]]
   [2011-04-07 10:12:57,006] ESC[32mESC[49mINFOESC[0m:ir_attachment.check:begin
   [2011-04-07 10:12:57,006] ESC[32mESC[49mINFOESC[0m:ir_attachment.check:[3, 7]
   ...
   [2011-04-07 10:12:57,308] ESC[31mESC[49mERRORESC[0m:web-services:[74]: PrNEA 1: ...t distinct res_model from ir_attachment where id in ([3, 7])

  I'm using openERP 5.0.10 on Ubuntu

  Kind Regards



References