Source code for odoo_xmlrpc_twisted.functions.create_product

"""
Create a new product with the details.
"""

# Definition of the initial parameter
custom_description = ''                                 # Initial value
custom_volume = ''                                      # Initial value
custom_weight = ''                                      # Initial value
custom_name = ''                                        # Initial value
                                      

import os
import configparser

try:
    from .crop_hints import crop_hints
    from .remove_background import remove_background
    from .get_label import get_label
    from .save_picture import save_picture
except ImportError:
    from crop_hints import crop_hints
    from remove_background import remove_background
    from get_label import get_label
    from save_picture import save_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_odoo import get_settings_odoo
except ImportError:
    from get_settings_odoo import get_settings_odoo
result   = 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" file
filename  = "parameter_inventory.ini"
path_name = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))  # Go up to repo root
config_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 id
custom_categ_id = config.get('create_product', 'categ_id')

# Value for the product type
custom_type = config.get('create_product', 'type')

# Value for product is active
custom_active = int(config.get('create_product', 'active'))

# Value for product can be sold
custom_sale_ok = int(config.get('create_product', 'sale_ok'))

# Value for product can be purchased
custom_purchase_ok = int(config.get('create_product', 'purchase_ok'))

# Value for the list price of the product
custom_list_price = int(config.get('create_product', 'list_price'))

# Value for the initial place of the product
custom_x_place = config.get('create_product', 'x_init_place')

# ------- end of the initialisation ------- 


    
[docs] def create_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. """ if partner_id != '': # set default values for the label values of the product custom_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 product if len(images) > 0: # Iterate over the list of the object images and access the elements # perspective and object_image (= custom_image) for custom_perspective, custom_image in images: # crop the image with the "crop_hints" function custom_image = crop_hints(custom_image) # Remove_background with the "remove_background" function custom_image = remove_background(custom_image) # save the image of the new product in the odoo database save_picture(custom_product_id, custom_perspective, custom_image) if custom_perspective == 'front': # Get the name and description from the front image with the "get_label" function custom_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 image models.execute_kw(db,uid, password, 'product.product', 'write', [[custom_product_id], {'name': custom_name, 'description': custom_desc}]) result = custom_product_id else: result = '' return(result)