Skip to content

Odooinjector

flowtask.components.OdooInjector

OdooInjector

OdooInjector(loop=None, job=None, stat=None, **kwargs)

Bases: HTTPService, FlowComponent

OdooInjector

Overview

    The OdooInjector class is a component for injecting data into an Odoo server using a provided API key.
    This component takes data from a Pandas DataFrame, formats it as payload, and sends it to an Odoo endpoint
    specified in the credentials, facilitating seamless integration with Odoo’s API.

.. table:: Properties
:widths: auto

    +----------------+----------+-----------+---------------------------------------------------------------+
    | Name           | Required | Summary                                                                |
    +----------------+----------+-----------+---------------------------------------------------------------+
    | credentials    |   Yes    | A dictionary containing connection details for the Odoo server:        |
    |                |          | "HOST", "PORT", "APIKEY", and "INJECTOR_URL".                          |
    +----------------+----------+-----------+---------------------------------------------------------------+
    | model          |   Yes    | The Odoo model into which data will be injected.                       |
    +----------------+----------+-----------+---------------------------------------------------------------+
    | headers        |   No     | Optional headers to include with the API request. Defaults to API key.  |
    +----------------+----------+-----------+---------------------------------------------------------------+
    | data           |   Yes    | The data to inject, formatted as a list of dictionaries from DataFrame. |
    +----------------+----------+-----------+---------------------------------------------------------------+

Returns

    This component returns a Boolean indicating whether the data injection was successful.
    In case of errors, detailed logging is provided, and an exception is raised with the error message.
    Additionally, the component tracks successful API interactions and logs any unsuccessful payload deliveries
    for debugging and tracking.


Example:

```yaml
OdooInjector:
  credentials:
    APIKEY: ODOO_APIKEY
    HOST: ODOO_HOST
    PORT: ODOO_PORT
    INJECTOR_URL: ODOO_INJECTOR_URL
  model: fsm.location
  chunk_size: 10
```

split_chunk_df

split_chunk_df(df, chunk_size)

Splits a DataFrame into chunks of a specified size.

Parameters: df (pd.DataFrame): The DataFrame to be split. chunk_size (int): The maximum number of rows per chunk.

list: A list of DataFrame chunks. If the DataFrame is empty, returns an empty list.