Struct odoo_api::OdooClient

source ·
pub struct OdooClient<S, I>where
    S: AuthState,
    I: RequestImpl,{ /* private fields */ }
Expand description

An Odoo API client

This is the main public interface for the odoo-api crate. It provides methods to authenticate with an Odoo instance, and to call JSON-RPC methods (execute, create_database, etc), “Web” methods (/web/session/authenticate, etc) and ORM methods (read_group, create, etc).

Usage:

use odoo_api::{OdooClient, jvec, jmap};

let url = "https://demo.odoo.com";
let mut client = OdooClient::new_reqwest_async(url)?
    .authenticate(
        "test-database",
        "admin",
        "password"
    ).await?;

let user_ids = client.execute(
    "res.users",
    "search",
    jvec![
        []
    ]
).send().await?;

println!("Found user IDs: {:?}", user_ids.data);

Implementations§

source§

impl<I: RequestImpl> OdooClient<Authed, I>

source

pub fn common_login(&mut self) -> OdooRequest<'_, Login, I>

Check the user credentials and return the user ID

See Login for more info.

source§

impl<I: RequestImpl> OdooClient<Authed, I>

source

pub fn common_authenticate( &mut self, user_agent_env: Map<String, Value> ) -> OdooRequest<'_, Authenticate, I>

Check the user credentials and return the user ID (web)

See Authenticate for more info.

source§

impl<I: RequestImpl, S: AuthState> OdooClient<S, I>

source

pub fn common_version(&mut self) -> OdooRequest<'_, Version, I>

Fetch detailed information about the Odoo version

See Version for more info.

source§

impl<I: RequestImpl, S: AuthState> OdooClient<S, I>

source

pub fn common_about(&mut self, extended: bool) -> OdooRequest<'_, About, I>

Fetch basic information about the Odoo version

See About for more info.

source§

impl<I: RequestImpl, S: AuthState> OdooClient<S, I>

source

pub fn db_create_database( &mut self, passwd: &str, db_name: &str, demo: bool, lang: &str, user_password: &str, login: &str, country_code: Option<String>, phone: Option<String> ) -> OdooRequest<'_, CreateDatabase, I>

Create and initialize a new database

See CreateDatabase for more info.

source§

impl<I: RequestImpl, S: AuthState> OdooClient<S, I>

source

pub fn db_duplicate_database( &mut self, passwd: &str, db_original_name: &str, db_name: &str ) -> OdooRequest<'_, DuplicateDatabase, I>

Duplicate a database

See DuplicateDatabase for more info.

source§

impl<I: RequestImpl, S: AuthState> OdooClient<S, I>

source

pub fn db_drop(&mut self, passwd: &str, db_name: &str) -> OdooRequest<'_, Drop, I>

Drop (delete) a database

See Drop for more info.

source§

impl<I: RequestImpl, S: AuthState> OdooClient<S, I>

source

pub fn db_dump( &mut self, passwd: &str, db_name: &str, format: DumpFormat ) -> OdooRequest<'_, Dump, I>

Dump (backup) a database, optionally including the filestore folder

See Dump for more info.

source§

impl<I: RequestImpl, S: AuthState> OdooClient<S, I>

source

pub fn db_restore( &mut self, passwd: &str, b64_data: &str, restore_type: RestoreType ) -> OdooRequest<'_, Restore, I>

Upload and restore an Odoo dump to a new database

See Restore for more info.

source§

impl<I: RequestImpl, S: AuthState> OdooClient<S, I>

source

pub fn db_rename( &mut self, passwd: &str, old_name: &str, new_name: &str ) -> OdooRequest<'_, Rename, I>

Rename a database

See Rename for more info.

source§

impl<I: RequestImpl, S: AuthState> OdooClient<S, I>

source

pub fn db_change_admin_password( &mut self, passwd: &str, new_passwd: &str ) -> OdooRequest<'_, ChangeAdminPassword, I>

Change the Odoo “master password”

See ChangeAdminPassword for more info.

source§

impl<I: RequestImpl, S: AuthState> OdooClient<S, I>

source

pub fn db_migrate_databases( &mut self, passwd: &str, databases: Vec<String> ) -> OdooRequest<'_, MigrateDatabases, I>

Perform a “database migration” (upgrade the base module)

See MigrateDatabases for more info.

source§

impl<I: RequestImpl, S: AuthState> OdooClient<S, I>

source

pub fn db_exist(&mut self, db_name: &str) -> OdooRequest<'_, DbExist, I>

Check if a database exists

See DbExist for more info.

source§

impl<I: RequestImpl, S: AuthState> OdooClient<S, I>

source

pub fn db_list(&mut self, document: bool) -> OdooRequest<'_, List, I>

List the databases currently available to Odoo

See List for more info.

source§

impl<I: RequestImpl, S: AuthState> OdooClient<S, I>

source

pub fn db_list_lang(&mut self) -> OdooRequest<'_, ListLang, I>

List the languages available to Odoo (ISO name + code)

See ListLang for more info.

source§

impl<I: RequestImpl, S: AuthState> OdooClient<S, I>

source

pub fn db_list_countries( &mut self, passwd: &str ) -> OdooRequest<'_, ListCountries, I>

List the countries available to Odoo (ISO name + code)

See ListCountries for more info.

source§

impl<I: RequestImpl, S: AuthState> OdooClient<S, I>

source

pub fn db_server_version(&mut self) -> OdooRequest<'_, ServerVersion, I>

Return the server version

See ServerVersion for more info.

source§

impl<I: RequestImpl> OdooClient<Authed, I>

source

pub fn execute( &mut self, model: &str, method: &str, args: Vec<Value> ) -> OdooRequest<'_, Execute, I>

Call a business-logic method on an Odoo model (positional args)

See Execute for more info.

source§

impl<I: RequestImpl> OdooClient<Authed, I>

source

pub fn execute_kw( &mut self, model: &str, method: &str, args: Vec<Value>, kwargs: Map<String, Value> ) -> OdooRequest<'_, ExecuteKw, I>

Call a business-logic method on an Odoo model (positional & keyword args)

See ExecuteKw for more info.

source§

impl<I: RequestImpl> OdooClient<Authed, I>

Create a new record (or set of records)

See Create for more info.

source

pub fn create<V: Into<CreateVals>>( &mut self, model: &str, values: V ) -> OdooRequest<'_, Create, I>

source§

impl<I: RequestImpl> OdooClient<Authed, I>

Read data from a record (or set of records)

See Read for more info.

source

pub fn read<ID: Into<OdooIds>>( &mut self, model: &str, ids: ID, fields: Vec<String> ) -> OdooRequest<'_, Read, I>

source§

impl<I: RequestImpl> OdooClient<Authed, I>

Write data to a record (or set of records)

See Write for more info.

source

pub fn write<ID: Into<OdooIds>>( &mut self, model: &str, ids: ID, values: Map<String, Value> ) -> OdooRequest<'_, Write, I>

source§

impl<I: RequestImpl> OdooClient<Authed, I>

Delete a record (or set of records)

See Unlink for more info.

source§

impl<I: RequestImpl> OdooClient<Authed, I>

Read some grouped data from a record (or set of records)

See ReadGroup for more info.

source

pub fn read_group( &mut self, model: &str, domain: Vec<Value>, fields: Vec<String>, groupby: Vec<String>, offset: Option<u32>, limit: Option<u32>, orderby: Option<String>, lazy: bool ) -> OdooRequest<'_, ReadGroup, I>

source§

impl<I: RequestImpl> OdooClient<Authed, I>

Perform a search and read in one call

See SearchRead for more info.

source

pub fn search_read( &mut self, model: &str, domain: Vec<Value>, fields: Vec<String>, offset: Option<u32>, limit: Option<u32>, order: Option<String> ) -> OdooRequest<'_, SearchRead, I>

source§

impl<I: RequestImpl> OdooClient<Authed, I>

Return the ids of records matching a domain

See Search for more info.

source

pub fn search( &mut self, model: &str, domain: Vec<Value>, offset: Option<u32>, limit: Option<u32>, order: Option<String> ) -> OdooRequest<'_, Search, I>

source§

impl<I: RequestImpl> OdooClient<Authed, I>

Return the count of records matching a domain

See SearchCount for more info.

source

pub fn search_count( &mut self, model: &str, domain: Vec<Value>, limit: Option<u32> ) -> OdooRequest<'_, SearchCount, I>

source§

impl<I: RequestImpl> OdooClient<Authed, I>

Copy a record

See Copy for more info.

source

pub fn copy( &mut self, model: &str, id: OdooId, default: Option<Map<String, Value>> ) -> OdooRequest<'_, Copy, I>

source§

impl<I: RequestImpl> OdooClient<Authed, I>

Check if the record(s) exist in the Odoo database

See Exists for more info.

source

pub fn exists<ID: Into<OdooIds>>( &mut self, model: &str, ids: ID ) -> OdooRequest<'_, Exists, I>

source§

impl<I: RequestImpl> OdooClient<Authed, I>

Check model access rights (according to ir.model.access)

See CheckAccessRights for more info.

source

pub fn check_access_rights( &mut self, model: &str, operation: AccessOperation, raise_exception: bool ) -> OdooRequest<'_, CheckAccessRights, I>

source§

impl<I: RequestImpl> OdooClient<Authed, I>

Check model access rules (according to ir.rule)

See CheckAccessRules for more info.

source

pub fn check_access_rules<ID: Into<OdooIds>>( &mut self, model: &str, ids: ID, operation: AccessOperation ) -> OdooRequest<'_, CheckAccessRules, I>

source§

impl<I: RequestImpl> OdooClient<Authed, I>

Check the user access rights on the given fields

See CheckFieldAccessRights for more info.

source

pub fn check_field_access_rights( &mut self, model: &str, operation: AccessOperation, fields: Vec<String> ) -> OdooRequest<'_, CheckFieldAccessRights, I>

source§

impl<I: RequestImpl> OdooClient<Authed, I>

Return some metadata about the given record(s)

See GetMetadata for more info.

source

pub fn get_metadata<ID: Into<OdooIds>>( &mut self, model: &str, ids: ID ) -> OdooRequest<'_, GetMetadata, I>

source§

impl<I: RequestImpl> OdooClient<Authed, I>

Fetch the XMLID for the given record(s)

See GetExternalId for more info.

source

pub fn get_external_id<ID: Into<OdooIds>>( &mut self, model: &str, ids: ID ) -> OdooRequest<'_, GetExternalId, I>

source§

impl<I: RequestImpl> OdooClient<Authed, I>

Fetch the XMLID for the given record(s)

See GetXmlId for more info.

source

pub fn get_xml_id<ID: Into<OdooIds>>( &mut self, model: &str, ids: ID ) -> OdooRequest<'_, GetXmlId, I>

source§

impl<I: RequestImpl> OdooClient<Authed, I>

Fetch the display_naame for the given record(s)

See NameGet for more info.

source

pub fn name_get<ID: Into<OdooIds>>( &mut self, model: &str, ids: ID ) -> OdooRequest<'_, NameGet, I>

source§

impl<I: RequestImpl> OdooClient<Authed, I>

Create a new record, passing only the name field

See NameCreate for more info.

source

pub fn name_create( &mut self, model: &str, name: &str ) -> OdooRequest<'_, NameCreate, I>

source§

impl<I: RequestImpl> OdooClient<Authed, I>

Search for records based on their name field

See NameSearch for more info.

source§

impl<I: RequestImpl, S: AuthState> OdooClient<S, I>

Authenticate to an Odoo database

See SessionAuthenticate for more info.

source

pub fn web_session_authenticate( &mut self, db: &str, login: &str, password: &str ) -> OdooRequest<'_, SessionAuthenticate, I>

source§

impl<I: RequestImpl, S: AuthState> OdooClient<S, I>

List the available databases

See DatabaseList for more info.

source

pub fn web_database_list(&mut self) -> OdooRequest<'_, DatabaseList, I>

source§

impl<I: RequestImpl, S: AuthState> OdooClient<S, I>

Fetch session information

See GetSessionInfo for more info.

source§

impl OdooClient<NotAuthed, ClosureAsync>

source

pub fn new_closure_async( url: &str, closure: impl 'static + Fn(String, Value, Option<String>) -> Pin<Box<dyn Future<Output = ClosureResult<(String, Option<String>)>>>> ) -> Self

source§

impl<S> OdooClient<S, ClosureAsync>where S: AuthState,

source

pub async fn authenticate( self, db: &str, login: &str, password: &str ) -> ClosureAuthResult<OdooClient<Authed, ClosureAsync>>

source§

impl OdooClient<NotAuthed, ClosureBlocking>

source

pub fn new_closure_blocking<F: Fn(&str, Value, Option<&str>) -> ClosureResult<(String, Option<String>)> + 'static>( url: &str, closure: F ) -> Self

source§

impl<S> OdooClient<S, ClosureBlocking>where S: AuthState,

source

pub fn authenticate( self, db: &str, login: &str, password: &str ) -> ClosureAuthResult<OdooClient<Authed, ClosureBlocking>>

source§

impl OdooClient<NotAuthed, ReqwestAsync>

source

pub fn new_reqwest_async(url: &str) -> Result<Self, Error>

source§

impl<S> OdooClient<S, ReqwestAsync>where S: AuthState,

source

pub async fn authenticate( self, db: &str, login: &str, password: &str ) -> ReqwestAuthResult<OdooClient<Authed, ReqwestAsync>>

source§

impl OdooClient<NotAuthed, ReqwestBlocking>

source

pub fn new_reqwest_blocking(url: &str) -> Result<Self, Error>

source§

impl<S> OdooClient<S, ReqwestBlocking>where S: AuthState,

source

pub fn authenticate( self, db: &str, login: &str, password: &str ) -> ReqwestAuthResult<OdooClient<Authed, ReqwestBlocking>>

source§

impl<S, I> OdooClient<S, I>where S: AuthState, I: RequestImpl,

source

pub fn session_id(&self) -> Option<&str>

source

pub fn authenticate_manual( self, db: &str, login: &str, uid: OdooId, password: &str, session_id: Option<String> ) -> OdooClient<Authed, I>

source

pub fn with_url(&mut self, url: &str) -> &mut Self

Update the URL for this client

Auto Trait Implementations§

§

impl<S, I> RefUnwindSafe for OdooClient<S, I>where I: RefUnwindSafe, S: RefUnwindSafe,

§

impl<S, I> Send for OdooClient<S, I>where I: Send, S: Send,

§

impl<S, I> Sync for OdooClient<S, I>where I: Sync, S: Sync,

§

impl<S, I> Unpin for OdooClient<S, I>where I: Unpin, S: Unpin,

§

impl<S, I> UnwindSafe for OdooClient<S, I>where I: UnwindSafe, S: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more