Source code for odoo_xmlrpc_twisted.functions.create_product
"""Create a new product with the details."""# Definition of the initial parametercustom_description=''# Initial valuecustom_volume=''# Initial valuecustom_weight=''# Initial valuecustom_name=''# Initial valueimportosimportconfigparsertry:from.crop_hintsimportcrop_hintsfrom.remove_backgroundimportremove_backgroundfrom.get_labelimportget_labelfrom.save_pictureimportsave_pictureexceptImportError:fromcrop_hintsimportcrop_hintsfromremove_backgroundimportremove_backgroundfromget_labelimportget_labelfromsave_pictureimportsave_picture# ------- begin of the initialisation -------# 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_odooimportget_settings_odooexceptImportError:fromget_settings_odooimportget_settings_odooresult=get_settings_odoo()db=result[0]uid=result[1]password=result[3]models=result[4]# get all the parameters from the file "parameter_inventory.ini"# Name and full path of the "ini" filefilename="parameter_inventory.ini"path_name=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))# Go up to repo rootconfig_path=os.path.join(path_name,'config')fullpath=os.path.join(config_path,filename)config=configparser.ConfigParser()config.read(fullpath)# Value for the product category idcustom_categ_id=config.get('create_product','categ_id')# Value for the product typecustom_type=config.get('create_product','type')# Value for product is activecustom_active=int(config.get('create_product','active'))# Value for product can be soldcustom_sale_ok=int(config.get('create_product','sale_ok'))# Value for product can be purchasedcustom_purchase_ok=int(config.get('create_product','purchase_ok'))# Value for the list price of the productcustom_list_price=int(config.get('create_product','list_price'))# Value for the initial place of the productcustom_x_place=config.get('create_product','x_init_place')# ------- end of the initialisation -------
[docs]defcreate_product(partner_id,images,volume,weight):""" Create a new product in the Odoo database for the dedicated customer. The product will be saved including the images, the description, volume and weight. """ifpartner_id!='':# set default values for the label values of the productcustom_name=''custom_desc=''# create the new product record in the odoo tables "product_product" and "product_template" custom_product_id=models.execute_kw(db,uid,password,'product.product','create',[{'active':custom_active,'categ_id':custom_categ_id,'description':custom_desc,'list_price':custom_list_price,'name':custom_name,'x_partner_id':partner_id,'sale_ok':custom_sale_ok,'purchase_ok':custom_purchase_ok,'type':custom_type,'volume':volume,'weight':weight,'x_place':custom_x_place,}])# If images exit to append to the productiflen(images)>0:# Iterate over the list of the object images and access the elements# perspective and object_image (= custom_image)forcustom_perspective,custom_imageinimages:# crop the image with the "crop_hints" function custom_image=crop_hints(custom_image)# Remove_background with the "remove_background" functioncustom_image=remove_background(custom_image)# save the image of the new product in the odoo databasesave_picture(custom_product_id,custom_perspective,custom_image)ifcustom_perspective=='front':# Get the name and description from the front image with the "get_label" functioncustom_label=get_label(partner_id,custom_image)custom_name=custom_label[0]custom_desc=custom_label[1]# update the new product record with the name and description from the front imagemodels.execute_kw(db,uid,password,'product.product','write',[[custom_product_id],{'name':custom_name,'description':custom_desc}])result=custom_product_idelse:result=''return(result)