パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v0.7.1

odoo_rpc

ストリームを介してセッションの変更をトラッキングするための、Dart用のOdoo RPCクライアントライブラリ。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
1630
いいね数
73
Pub ポイント
150

パッケージをインストール

flutter pub add odoo_rpc

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

odoo_rpc パッケージは、RPC(リモートプロシージャコール)を使用してOdoo ERPシステムとのシームレスな通信を可能にするDartライブラリです。ストリームを通じたリアルタイム追跡によるセッション管理をサポートしており、開発者が認証状態やセッションの変更を動的に監視できるようにしています。クロスプラットフォーム対応として設計されており、Android、iOS、Web、macOS、Windows、Linuxで動作します。Odooのバックエンドサービスとの統合を簡素化し、Odooデータやワークフローとやり取りするネイティブまたはWebアプリケーションの構築に最適です。

用途

  • FlutterアプリをOdoo ERPと統合する
  • エンタープライズアプリケーションにおけるリアルタイムセッションモニタリング
  • Odooバックエンドを使用したCRMまたは在庫ツールの構築
  • FlutterアプリとOdoo間でのデータ同期
  • モバイルクライアントからOdoo操作を自動化する

主な機能

  • ストリームベースのセッション変更のトラッキング
  • クロスプラットフォーム互換性
  • Odoo との安全な RPC 通信
  • 認証およびセッションの永続化に対応
  • Flutter pub add コマンドによる簡単なセットアップ

適している対象

  • ERP統合アプリを構築するFlutter開発者
  • Odooをバックエンドとして使用するエンタープライズアプリチーム
  • リアルタイムのセッション更新が必要な開発者
  • Odoo接続を必要とするモバイルおよびデスクトップアプリケーション
  • Odooを活用したビジネスソリューションに取り組んでいるチーム

注意事項

  • RPCが有効なアクティブなOdooサーバーが必要です
  • 認証の設定は慎重に処理する必要があります
  • 基本的な使用方法以外のドキュメントは限られている
  • Odooへの安定したネットワーク接続に依存しています
  • 非Odooバックエンド統合には適していません

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

Odoo RPC Client Library

Odoo RPC Client Library for Dart.

Features

  • Initialize client with previously stored Odoo Session.
  • Authenticate via database name, login and password.
  • Issue JSON-RPC requests to JSON controllers.
  • Execute public methods via CallKw.
  • Get Odoo Session updates via stream.
  • Terminate session (logout).
  • Catch exceptions when session expires.

Usage

To use this plugin, add odoo_rpc as a dependency in your pubspec.yaml file. For example:

dependencies:
  odoo_rpc: <latest_version>

Examples

Basic RPC-call

import 'dart:io';
import 'package:odoo_rpc/odoo_rpc.dart'

main() async {
  final client = OdooClient('https://my-db.odoo.com');
  try {
    await client.authenticate('my-db', 'admin', 'admin');
    final res = await client.callRPC('/web/session/modules', 'call', {});
    print('Installed modules: \n' + res.toString());
  } on OdooException catch (e) {
    print(e);
    client.close();
    exit(-1);
  }
  client.close();
}

RPC-Calls with tracking session changes. Odoo server will issue new session_id on each call.

import 'dart:io';
import 'package:odoo_rpc/odoo_rpc.dart'


sessionChanged(OdooSession sessionId) async {
  print('We got new session ID: ' + sessionId.id);
  store_session_somehow(sessionId);
}


main() async {
  var prev_session = restore_session_somehow();
  var client = OdooClient("https://my-db.odoo.com", sessionId: prev_session);

  // Subscribe to session changes to store most recent one
  var subscription = client.sessionStream.listen(sessionChanged);

  try {
    final session = await client.authenticate('my-db', 'admin', 'admin');
    var res = await client.callRPC('/web/session/modules', 'call', {});
    print('Installed modules: \n' + res.toString());

    // logout
    await client.destroySession();
  } on OdooException catch (e) {
    print(e);
    subscription.cancel();
    client.close();
    exit(-1);
  }

  try {
    await client.checkSession();
  } on OdooSessionExpiredException {
    print('Session expired');
  }

  subscription.cancel();
  client.close();
}

Flutter example using FutureBuilder.

import 'package:flutter/material.dart';
import 'package:odoo_rpc/odoo_rpc.dart';

final orpc = OdooClient('https://my-odoo-instance.com');
void main() async {
  await orpc.authenticate('odoo-db', 'admin', 'admin');
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: HomePage(),
    );
  }
}

class HomePage extends StatelessWidget {
  Future<dynamic> fetchContacts() {
    return orpc.callKw({
      'model': 'res.partner',
      'method': 'search_read',
      'args': [],
      'kwargs': {
        'context': {'bin_size': true},
        'domain': [],
        'fields': ['id', 'name', 'email', '__last_update', 'image_128'],
        'limit': 80,
      },
    });
  }

  Widget buildListItem(Map<String, dynamic> record) {
    var unique = record['__last_update'] as String;
    unique = unique.replaceAll(RegExp(r'[^0-9]'), '');
    final avatarUrl =
        '${orpc.baseURL}/web/image?model=res.partner&field=image_128&id=${record["id"]}&unique=$unique';
    return ListTile(
      leading: CircleAvatar(backgroundImage: NetworkImage(avatarUrl)),
      title: Text(record['name']),
      subtitle: Text(record['email'] is String ? record['email'] : ''),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Contacts'),
      ),
      body: Center(
        child: FutureBuilder(
            future: fetchContacts(),
            builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
              if (snapshot.hasData) {
                return ListView.builder(
                    itemCount: snapshot.data.length,
                    itemBuilder: (context, index) {
                      final record =
                          snapshot.data[index] as Map<String, dynamic>;
                      return buildListItem(record);
                    });
              } else {
                if (snapshot.hasError) return Text('Unable to fetch data');
                return CircularProgressIndicator();
              }
            }),
      ),
    );
  }
}

For more complex usage consider odoo_repository as abstraction layer between your flutter app and Odoo backend.

Web platform notice

This package intentionally uses http package instead of dart:io so web platform could be supported. However RPC calls via web client (dart js) that is hosted on separate domain will not work due to CORS requests currently are not correctly handled by Odoo. See https://github.com/odoo/odoo/pull/37853 for the details.

To make it work from different host we must follow the rules of CORS. Make sure your odoo server has these CORS headers:

Access-Control-Allow-Methods: GET, OPTIONS, PUT, POST
Access-Control-Allow-Headers: Content-Type
Access-Control-Allow-Origin: https://{YOUR_FLUTTER_APP_DOMAIN}
Access-Control-Allow-Credentials: true // This is super important

And for WebApp you must use BrowserClient or something similar. The withCredentials = true is crucial. It allows the httpClient to carry on cookies from Browser. On Web browser, it won't allow you to directly access set-cookie header. As it is a forbidden header: https://fetch.spec.whatwg.org/#forbidden-request-header But it will automatically add this cookie to the BrowserClient whenever you make rpc call to your odoo server once authenticated.

OdooClient(BASE_URL,
  sessionId: ODOO_SESSION,
  httpClient: BrowserClient()..withCredentials = true,
  isWebPlatform = true,
)

For Web always listen to loginStream stream in order to get if user logged in or logged out. As session_id will be unaccesible on Web platform.

Issues

Please file any issues, bugs or feature requests as an issue on our GitHub page.

Want to contribute

If you would like to contribute to the plugin (e.g. by improving the documentation, solving a bug or adding a cool new feature), please send us your pull request.

Author

Odoo RPC Client Library is developed by ERP Ukraine.

カテゴリー

依存関係

依存関係一覧 2 件

ソースリポジトリ

このパッケージを使用しているプロジェクト

データはまだありません。