odoo_api/jsonrpc/
mod.rs

1//! The base JSON-RPC types
2//!
3//! This module exposes type structs, traits, and helper methods to build valid
4//! Odoo JSON-RPC requests.
5//!
6//! As a crate user, you shouldn't need to interact with these directly. Instead, see [`crate::client`].
7
8pub mod request;
9pub mod response;
10
11use serde::{Deserialize, Serialize};
12use std::fmt::Debug;
13
14pub use request::{
15    JsonRpcParams, JsonRpcRequest, OdooApiContainer, OdooApiMethod, OdooOrmContainer,
16    OdooOrmMethod, OdooWebContainer, OdooWebMethod,
17};
18pub use response::JsonRpcResponse;
19
20/// A JSON-RPC request id
21pub type JsonRpcId = u32;
22
23/// An Odoo record id
24///
25/// Note that this *is* signed, as some Odoo models (e.g. the `PurchaseBillUnion`)
26/// use positive ids to represent one model (`purchase.order`), and negative ids
27/// to represent another (`account.move`).
28pub type OdooId = i32;
29
30/// A vec of [`OdooId`].
31///
32/// This type also implements `From<OdooId>`, which allows for flexible function
33/// args, e.g.:
34/// ```
35/// use odoo_api::jsonrpc::OdooIds;
36/// fn my_function<I: Into<OdooIds>>(ids: I) {
37///     // ...
38/// }
39///
40/// // call with a list of ids...
41/// my_function(vec![1, 2, 3]);
42///
43/// // ... or with a single id
44/// my_function(1);
45/// ```
46#[derive(Debug, Serialize, Deserialize)]
47pub struct OdooIds(Vec<OdooId>);
48
49impl From<OdooId> for OdooIds {
50    fn from(value: OdooId) -> Self {
51        OdooIds(vec![value])
52    }
53}
54impl From<Vec<OdooId>> for OdooIds {
55    fn from(value: Vec<OdooId>) -> Self {
56        Self(value)
57    }
58}
59
60/// A string representing the JSON-RPC version
61///
62/// At the time of writing, this is always set to "2.0"
63#[derive(Debug, Serialize, Deserialize)]
64pub enum JsonRpcVersion {
65    /// Odoo JSON-RCP API version 2.0
66    #[serde(rename = "2.0")]
67    V2,
68}
69
70/// A string representing the JSON-RPC "method"
71///
72/// At the time of writing, this is always set to "call"
73#[derive(Debug, Serialize, Deserialize)]
74pub enum JsonRpcMethod {
75    #[serde(rename = "call")]
76    Call,
77}