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


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

// database.php
    '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'
                ],
            ],
        ],

    ],

use Sefirosweb\LaravelOdooConnector\Http\Models\ProductProduct;

class YourController extends Controller
{
    public function index()
    {
        $products = ProductProduct::where('name', 'like', '%product%')->with('mrp_bom')->get();
        return view('products.index', compact('products'));
    }
}

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

$product = ProductProduct::create([
    'name' => 'Product 1',
    'description' => 'Description of product 1',
    'list_price' => 100,
    // ...
]);

class YourCustomProductProduct extends Sefirosweb\LaravelOdooConnector\Http\Models\ProductProduct
{
    protected $table = 'product.product';

    public function your_custom_belongs(): BelongTo
    {
        return $this->belongsTo(YourCustomModel::class, 'your_field_id');
    }
}


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


use Sefirosweb\LaravelOdooConnector\Http\Traits\SoftDeleteOdoo;

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

use Sefirosweb\LaravelOdooConnector\Http\Models\OdooModel;

class YourMainOdooModel extends OdooModel
{
    protected $connection = 'other_odoo_connection';

    public function getConnection()
    {
        return app('db')->connection('other_odoo_connection');
    }
}

$products = ProductProduct::get_all('id', 'name', 100);

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

$args = [['id' => 1]];
SaleOrder::model_action('action_custom', $args);
bash
php artisan vendor:publish --provider="Sefirosweb\LaravelOdooConnector\LaravelOdooConnectorServiceProvider"  --tag=config --force