Source code for odoo_xmlrpc_twisted.support.support_create_product

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


import io
import base64
from PIL import Image


import sys
import os

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


[docs] def support_create_product(custom_partner_id, custom_image_name): """ Function to test the module "create_product" A picture stored in the current directory will be captured to a stream and will be handled over to the function "create_product" from that module. Returns: int: The ID of the created product in Odoo, or None if creation failed """ # initialize the list to store the image result with the perspective object_images = [] # set the perspective corresponding to the image perspective = 'front' # 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()) object_image = img_str.decode('ascii') # append the tuple of perspective and image to the list of the images object_images.append((perspective, object_image)) # set dummy volume and weight object_volume = '' object_weight = '' # create the product with the parameter in the odoo database custom_product_id = create_product(custom_partner_id, object_images, object_volume, object_weight) return(custom_product_id)