alazzi-az/laraodoo-xmlrpc

Odoo-Xmlrpc PHP for Laravel is a supercharged PHP API client that allows you to interact with the Odoo XML-RPC API

v1.0.3 2023-07-22 20:03 UTC

This package is auto-updated.

Last update: 2024-05-22 18:13:20 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

The Odoo XML-RPC Client is a PHP package that provides a simple and easy-to-use interface for interacting with the Odoo XML-RPC API. Unlike other Odoo clients that require extensions or other dependencies, this client uses the laminas/laminas-xmlrpc package, which is a pure PHP implementation of the XML-RPC protocol.

Requirements

  • PHP 8.1 or later

Get Started

First, install laraodoo-xmlrpc via the Composer package manager:

composer require alazzi-az/laraodoo-xmlrpc

Next, publish the configuration file:

php artisan vendor:publish --provider="Alazzidev\LaraodooXmlrpc\ServiceProvider"

This will create a config/odoo-xmlrpc..php configuration file in your project, which you can modify to your needs using environment variables:

return [
    'url' => env('ODOO_URL', ''),
    'suffix' => 'xmlrpc/2',
    'db' => env('ODOO_DB', ''),
    'username' => env('ODOO_USERNAME', ''),
    'password' => env('ODOO_PASSWORD', ''),
];

Finally, you may use the Odoo facade to access the Odoo Xml API:

use Alazzidev\LaraodooXmlrpc\Facades\Odoo;

$result = Odoo::model('res.partner')->create([
            'test1'=>'test1-value',
            'test2'=>'test2-value'
            ]);

Usage

For usage examples, take a look at the alazzi-az/odoo-xmlrpc repository.

Use Case

For Create Invoice in Cummonity Version "account.move"

use Alazzidev\LaraodooXmlrpc\Facades\Odoo;

// Define invoice line
$line = [
    0,
    false,
    [
        'currency_id' => $currency_id,
        'discount' => $discountPercentage,
        'display_type' => 'product',
        'name' => $name,
        'price_unit' => $price_unit,
        'product_id' => $product_id,
        'quantity' => $quantity,
        'tax_ids' => $tax_ids,
    ]
];

$invoice_lines = [$line];

// Define invoice data
$invoice = [
    'partner_id' => $partner_id,
    'name' => $name,
    'invoice_date' => $invoice_date,
    'invoice_date_due' => $invoice_date_due,
    'payment_reference' => $payment_reference,
    'invoice_line_ids' => $invoice_lines,
    'currency_id' => $currency_id,
    'invoice_payment_term_id' => $payment_term_id,
    'state' => $state,
    'journal_id' => $journal_id,
    'move_type' => 'out_invoice',
];

// Create invoice using Odoo External API
$odoo = Odoo::model('account.move');
$odoo_invoice_id = $odoo->create($invoice);

Testing

The Odoo facade comes with a fake() method that allows you to fake the API responses.

The fake responses are returned in the order they are provided to the fake() method.

All responses are having a fake() method that allows you to easily create a response object by only providing the parameters relevant for your test case.

use Alazzidev\LaraodooXmlrpc\Facades\Odoo;

  Odoo::fake([
        'test1'=>'test1-value',
        'test2'=>'test2-value'
    ]);

    $response = Odoo::create('res.partner',[
        'test1'=>'test1-value',
        'test2'=>'test2-value'
    ]);

    expect($response['test1'])->toBe('test1-value');

And here You Can run test

composer test:unit

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.