OptimaAI Logo

Data Exports

How to export datasets from Odoo for ML training

Data Exports

This page explains how to export the required datasets from Odoo for ML training.

Revenue Dataset

File: data/amazon_revenue_forecasting.csv

How to export from Odoo:

  1. Go to Sales → Orders → Orders
  2. Set the filter to confirmed orders (state = sale)
  3. Click Action → Export
  4. Select the fields listed below
  5. Export as CSV

Required fields:

Odoo FieldCSV ColumnDescription
sale.order.line.product_uom_qtyquantity_soldUnits sold per line
sale.order.line.price_unitpriceUnit selling price
sale.order.line.discountdiscount_percentLine discount %
sale.order.date_ordermonth, quarterOrder date (parsed)
sale.order.line.margin / price_subtotalgross_margin_pctMargin ratio
(computed)seasonal_indexSeasonal index from date
sale.order.line.price_subtotalnet_revenueTarget variable

Churn Dataset

File: data/amazon_churn_prediction.csv

How to export from Odoo:

  1. Go to Sales → Orders → Customers or CRM → Customers
  2. Use a pivot/analysis view or custom report
  3. The dataset requires per-customer aggregation — Odoo's built-in export may need to be supplemented with a custom report or Python script using the XML-RPC API

Required fields:

CSV ColumnDescriptionSource
days_since_last_orderDays since most recent orderComputed from date_order
total_ordersLifetime order countCOUNT(sale.order) per partner
avg_days_between_ordersAverage order cadenceComputed
churn_risk_scorePre-computed risk signalFrom CRM or custom field
total_spentLifetime revenueSUM(amount_total)
avg_order_valueAverage order sizeAVG(amount_total)
churnedTarget variable (0/1)Manual label or inferred from inactivity

Churn label convention: A customer is marked as churned (churned = 1) if they have had no orders in the last 90 days.


Growth Dataset

File: data/amazon_growth_projection.csv

How to export from Odoo:

  1. Go to Sales → Reporting → Sales Analysis
  2. Group by month or quarter
  3. Export revenue totals per period

Required fields:

CSV ColumnDescription
periodMonth or quarter label
total_revenueRevenue for the period
order_countNumber of orders
new_customersNew partners acquired
avg_order_valueAverage order value for the period
revenue_growth_3mTarget variable — 3-month forward revenue

Automating Exports (Python + XML-RPC)

For automated, scheduled exports, use the Odoo XML-RPC API:

import xmlrpc.client
import pandas as pd
from datetime import datetime, timedelta
 
URL     = "https://your-odoo.com"
DB      = "your_db"
USER    = "admin@company.com"
API_KEY = "your_key"
 
common  = xmlrpc.client.ServerProxy(f"{URL}/xmlrpc/2/common")
uid     = common.authenticate(DB, USER, API_KEY, {})
models  = xmlrpc.client.ServerProxy(f"{URL}/xmlrpc/2/object")
 
# Pull all confirmed order lines from the last 2 years
cutoff  = (datetime.now() - timedelta(days=730)).strftime("%Y-%m-%d")
lines   = models.execute_kw(
    DB, uid, API_KEY,
    'sale.order.line', 'search_read',
    [[['order_id.state', '=', 'sale'],
      ['order_id.date_order', '>=', cutoff]]],
    {
        'fields': [
            'product_uom_qty', 'price_unit', 'discount',
            'price_subtotal', 'order_id'
        ],
        'limit': 50000
    }
)
 
df = pd.DataFrame(lines)
df.to_csv("data/amazon_revenue_forecasting.csv", index=False)
print(f"Exported {len(df)} order lines.")

On this page