Source code for odoo_xmlrpc_twisted.support.support_save_picture
"""Supporting program to test the module :func:`odoo_xmlrpc_twisted.functions.save_picture`."""importsysimportosimportioimportbase64fromPILimportImage# Add functions directory to path for importing custom modulessys.path.append(os.path.join(os.path.dirname(__file__),'..','functions'))fromsave_pictureimportsave_picture
[docs]defsupport_save_picture(custom_product_id,custom_perspective,custom_image_name):""" Function to test the module "save_picture" A picture stored in the current directory will be captured to a stream and will be saved in the Odoo Database with the function "save_picture" from that module. Returns: int: The ID of the created attachment in Odoo (ir.attachment), or None if creation failed """# for the capturing of the image to a BytesIO streamstream=io.BytesIO()# Construct path to test directory where the image is locatedrepo_root=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))test_dir=os.path.join(repo_root,'test')image_path=os.path.join(test_dir,custom_image_name)image=Image.open(image_path)image.save(stream,format="JPEG")# convert PIL image to base64 stringimg_str=base64.b64encode(stream.getvalue())custom_datas=img_str.decode('ascii')# call the function save_picture to save the image in the Odoo database custom_id=save_picture(custom_product_id,custom_perspective,custom_datas)return(custom_id)