Source code for odoo_xmlrpc_twisted.functions.get_picture_string

"""
Get the picture in form of a data string from a specific product
to 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_odoo import get_settings_odoo
except ImportError:
    from get_settings_odoo import get_settings_odoo
result   = get_settings_odoo()
db       = result[0]
uid      = result[1]
password = result[3]
models   = result[4] 



[docs] def get_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 = '' if product_id != '': # find the corresponding product_template_id of the product custom_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' if custom_product_tmpl: for key, value in list(custom_product_tmpl[0].items()): if key == "product_tmpl_id": custom_product_tmpl_id = value[0] if custom_product_tmpl_id: # get the "datas" value (= picture) from the odoo database custom_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 data if custom_picture: for key, value in list(custom_picture[0].items()): if key == "datas": custom_str = value else: pass return(custom_str)