Wednesday, December 10, 2014

How to use xmlrpc to upload an image into the partner ?

Hi SME Odooer , the formal openerper , how is things ? Hope you are benefited from this powerful framework of Odoo , the formal OpenERP of Malaysia ,

today , i would like to share how to use xmlrpc to upload into partners ,
so the object to use are res.partner and ir.attachment ,

and you will need to use to upload some image and then click the
encode button

After you got the download file , copy the strings inside the file.

Here as usual, do your usual import
import xmlrpclib
          dbname  = 'somedb'
          usr = 'someusr'
          pwd ='somepass'
erp_client = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/common')
uid = erp_client.login(dbname ,usr ,pwd)
erp_client = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/object')
          base64str_file  = <use the copied strings , paste here !>
          partner_id = <code to get the partner id >
values = {'name':'some.jpg',
                        'res_id': partner_id  ,
                        'partner_id' : partner_id  ,
                        'datas' : base64str_file  }
new_id = erp_client.execute(dbname, uid, pwd, 'ir.attachment', 'create', values )
after executed , we should expect a new attachment at this selected Partner  !
Hope this help , till next update,cheers!

1 comment:

  1. Hello
    i have only use binary field
    image_medium = fields.Binary('Image')

    so how can i upload image on that field
    using xmlrpc from excel file


Note: Only a member of this blog may post a comment.