Connectors

Contact support

Odoo - Getting started in Peliqan

Odoo - Getting started in Peliqan

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

This article provides an overview to get started with the Odoo connector in Peliqan. Please contact support if you have any additional questions or remarks.

Contents

Connect Odoo

In Peliqan, go to Connections > Add Connection > Select Odoo in the list > Enter the details of your Odoo instance.

Sync custom models

You can include custom modules in the ETL pipeline, by adding a comma-separated list with the names of your custom models in the field “Custom models”. These models will now also be synced to the data warehouse as tables.

Sync custom fields

Custom fields will automatically be added as columns in the tables in the data warehouse. If you add new custom fields in Odoo, perform a “Full resync” to include them in the data warehouse.

Writeback to Odoo from Python scripts

Basic writeback functions

Example to add a Product to Odoo:

odoo_api = pq.connect('Odoo')

product = {
    'name': "My new product"
}
result = odoo_api.add('product', product)
st.json(result)

Example to update a Product in Odoo:

odoo_api = pq.connect('Odoo')

product = {
    'id': 123,
    'name': "My new product updated"
}
result = odoo_api.update('product', product)
st.json(result)

Generic functions

These functions can be used to work with any model in Odoo, a standard or custom model.

Add object from a given model:

odoo_api = pq.connect('Odoo')

object = {
    "model": "product.template", # this could be a custom model
    "payload": [
            {
                "name": "My new object"
            }
        ],
    "additional_params": {}
    }

#result = odoo_api.add('object', object)
#st.json(result)

Update object from a given model:

object = {
    "model": "product.template", # this could be a custom model
    "payload": [ 
            [123],               # id of the object to update
            {
                "name": "My new product updated",
            }
        ],
    "additional_params": {}
    }
result = odoo_api.update('object', object)
st.json(result)

Custom fields

Set value of a custom field:

odoo_api = pq.connect('Odoo')

product = {
    'name': "My new product",
    "x_my_custom_field": "Some value"
}
result = odoo_api.add('product', product)
st.json(result)

Fields of type Many2Many and One2Many

Examples of working with fields (basic or custom) of type many2many or one2many:

odoo_api = pq.connect('Odoo')

ADD_LINK = 4
REPLACE_LINKS = 6

# Add new product with one many2many field value
# Link this product to id 40
odoo_api = pq.connect('Odoo')
product = {
    'name': "My new product",
    "x_related_product": [[ADD_LINK, 40]]
}
result = odoo_api.add('product', product)
st.json(result)

# Update product with id=47, replace many2many field values
# Link this product to ids 41 and 42 
odoo_api = pq.connect('Odoo')
product = {
    'id': 47,
    'name': "My new product updated",
    "x_related_product": [[REPLACE_LINKS, 0, [41, 42]]]
}
result = odoo_api.update('product', product)
st.json(result)

For a many2many and one2many fields, following value format is required:

  • [[ 0, 0, { values } ]] link to a new record that needs to be created with the given values dictionary
  • [[ 1, ID, { values } ]]  update the linked record with id = ID (write values on it)
  • [[ 2, ID ]] remove and delete the linked record with id = ID (calls unlink on ID, that will delete the object completely, and the link to it as well)
  • [[ 3, ID ]] cut the link to the linked record with id = ID (delete the relationship between the two objects but does not delete the target object itself)
  • [[ 4, ID ]]  link to existing record with id = ID (adds a relationship)
  • [[ 5 ]]  unlink all
  • [[ 6, 0, [IDs] ]]  replace the list of linked IDs