openerp 产品图片的批量写入

时间:2023-03-09 00:23:28
openerp 产品图片的批量写入
  • Write a short python script which loops over the image files, encode with base64 and write to OpenERP with XMLRPC

1 产品图片是需要转为 base64编码的

2:如果需要批量导入,可以吧图片名字和 产品编码关联,然后代码批量写入即可以

下面是一个写入产品图片的例子,最好由xmlrpc方法写入,直接写入数据库,不会触发中图和小图的计算

=================

  • #!/usr/bin/env python
    # -*- coding: utf-8 -*-

    import psycopg2
    import sys
    import base64
    import oerplib

    oerp = oerplib.OERP('localhost', protocol='xmlrpc', port=8069)
    oerp.login('user', 'passwprd', 'dbname')
    pp = oerp.get('product.product')

    picture_file='/tmp/yks_logo.png'
    product_id=113
    f = open(picture_file, 'rb')
    binary = f.read()
    image = base64.encodestring(binary)

    pp.write(product_id, {'image': image} )