Source code for odoo_xmlrpc_twisted.support.support_create_product
"""Supporting program to test the module :func:`odoo_xmlrpc_twisted.functions.create_product`."""importioimportbase64fromPILimportImageimportsysimportos# Add functions directory to path for importing custom modulessys.path.append(os.path.join(os.path.dirname(__file__),'..','functions'))fromcreate_productimportcreate_product
[docs]defsupport_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 perspectiveobject_images=[]# set the perspective corresponding to the imageperspective='front'# 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())object_image=img_str.decode('ascii')# append the tuple of perspective and image to the list of the imagesobject_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)