Source code for odoo_xmlrpc_twisted.support.support_save_picture

"""
Supporting program to test the module :func:`odoo_xmlrpc_twisted.functions.save_picture`.
"""


import sys
import os
import io
import base64
from PIL import Image

# Add functions directory to path for importing custom modules
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'functions'))
from save_picture import save_picture



[docs] def support_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 stream stream = io.BytesIO() # Construct path to test directory where the image is located repo_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 string img_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)