Source code for odoo_xmlrpc_twisted.functions.get_picture_string
"""Get the picture in form of a data string from a specific productto display it on the dasboard of the user."""# call the function "get_settings_odoo" to get the parameters# for the logging of the model on the "odoo Webservice API"try:from.get_settings_odooimportget_settings_odooexceptImportError:fromget_settings_odooimportget_settings_odooresult=get_settings_odoo()db=result[0]uid=result[1]password=result[3]models=result[4]
[docs]defget_picture_string(product_id,res_field,name):""" Get a specific picture of a product from the odoo table 'ir.attachment' with the parameter: - name (for example 'image_128_front') - res_field (for example 'image_128') Return the picture as a string. """custom_str=''ifproduct_id!='':# find the corresponding product_template_id of the productcustom_product_tmpl=models.execute_kw(db,uid,password,'product.product','search_read',[[['id','=',product_id]]],{'fields':['product_tmpl_id']})# if the array is not empty# get the value for 'product_tmpl_id'ifcustom_product_tmpl:forkey,valueinlist(custom_product_tmpl[0].items()):ifkey=="product_tmpl_id":custom_product_tmpl_id=value[0]ifcustom_product_tmpl_id:# get the "datas" value (= picture) from the odoo databasecustom_picture=models.execute_kw(db,uid,password,'ir.attachment','search_read',[[['res_id','=',custom_product_tmpl_id],['name','=',name],['res_field','=',res_field],['res_model','=','product.template']]],{'fields':['datas']})# get the "datas" value from the array "custom_picture" to get the picture dataifcustom_picture:forkey,valueinlist(custom_picture[0].items()):ifkey=="datas":custom_str=valueelse:passreturn(custom_str)