PHP code example of sefirosweb / laravel-odoo-connector

1. Go to this page and download the library: Download sefirosweb/laravel-odoo-connector library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sefirosweb / laravel-odoo-connector example snippets


$saleOrder = SaleOrder::find(1);
$saleOrder->action('action_confirm');
// Triggers the "Confirm" button on sale.order — see Odoo's sale/models/sale_order.py

'connections' => [
    // ...
    'odoo' => [
        'driver'   => 'odoo',
        'host'     => env('ODOO_HOST',     'https://your-odoo-host.com'),
        'database' => env('ODOO_DB',       'db_name'),
        'username' => env('ODOO_USERNAME', 'user'),
        'password' => env('ODOO_PASSWORD', 'api_key'),
        'defaultOptions' => [
            'timeout' => 20,
            'context' => [
                'lang' => 'es_ES',
            ],
        ],
    ],
],

return [
    'ProductProduct'  => App\Odoo\CustomProductProduct::class,
    'ProductTemplate' => Sefirosweb\LaravelOdooConnector\Http\Models\ProductTemplate::class,
    'ResLang'         => Sefirosweb\LaravelOdooConnector\Http\Models\ResLang::class,
    // ...
];

use Sefirosweb\LaravelOdooConnector\Http\Models\ProductProduct;

$products = ProductProduct::where('name', 'like', '%widget%')
    ->with('mrp_bom')
    ->get();

$product = ProductProduct::find(1);
$product->name = 'New name';
$product->save();

$created = ProductProduct::create([
    'name'        => 'Product X',
    'description' => 'Flagship SKU',
    'list_price'  => 100,
]);

  // ❌ Will throw OdooUnsupportedOperationException
  $orders = SaleOrder::whereHas('sale_order_lines')->get();

  // ✅ Two-step pattern that works
  $orderIds = SaleOrderLine::select('order_id')->pluck('order_id');
  $orders   = SaleOrder::whereIn('id', $orderIds)->get();
  

  $line = SaleOrderLine::first();
  $orderId = is_array($line->order_id) ? $line->order_id[0] : $line->order_id;
  

namespace App\Odoo;

use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Sefirosweb\LaravelOdooConnector\Http\Models\ProductProduct as BaseProductProduct;

class CustomProductProduct extends BaseProductProduct
{
    protected $table = 'product.product';

    public function our_custom_belongs(): BelongsTo
    {
        return $this->belongsTo(OurCustomModel::class, 'our_field_id');
    }
}

use Sefirosweb\LaravelOdooConnector\Http\Models\OdooModel;
use Sefirosweb\LaravelOdooConnector\Http\Traits\SoftDeleteOdoo;

class MyModel extends OdooModel
{
    use SoftDeleteOdoo;
    // ...
}

$products = ProductProduct::get_all('id', 'name', 100);
// Behaves like ::all() but paginates under the hood.

$saleOrder = SaleOrder::find(1);
$saleOrder->action('action_confirm');

$args = [[['id' => 1]]];
SaleOrder::model_action('action_custom', $args);

use Sefirosweb\LaravelOdooConnector\Http\Models\OdooModel;

class SecondaryOdooModel extends OdooModel
{
    protected $connection = 'other_odoo';
}

ProductProduct::on('other_odoo')->where(...)->get();
bash
php artisan vendor:publish --provider="Sefirosweb\LaravelOdooConnector\LaravelOdooConnectorServiceProvider" --tag=config --force
bash
php artisan test:odoo