1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//! Internal module to store macro_rules!() macros
// Import Value and Map so the doc comments render properly
use ;
/// Helper macro to build a [`Vec<Value>`]
///
/// This is useful when using any of the API methods that require a `Vec<Value>`,
/// as [`serde_json`] doesn't have a way to build these.
///
/// ## Example:
/// ```no_run
/// # #[cfg(not(feature = "types-only"))]
/// # fn test() -> odoo_api::client::error::Result<()> {
/// # use serde_json::{json, Value};
/// # use odoo_api::{jvec, jmap};
/// # use odoo_api::{OdooClient};
/// # let client = OdooClient::new_reqwest_blocking("https://demo.odoo.com")?;
/// # let mut client = client.authenticate_manual("", "", 1, "", None);
/// // Manually
/// let mut args = Vec::<Value>::new();
/// args.push(json!([1, 2, 3]));
/// args.push(json!(["id", "login"]));
///
/// let request = client.execute(
/// "res.users",
/// "read",
/// args,
/// ).send()?;
///
/// // With jvec![]:
/// let request = client.execute(
/// "res.users",
/// "read",
/// jvec![
/// [1, 2, 3],
/// ["id", "login"]
/// ]
/// ).send()?;
/// # Ok(())
/// # }
/// ```
};
=> ;
}
/// Helper macro to build a [`Map<String, Value>`]
///
/// This is useful when using any of the API methods that require a `Map<String, Value>`,
/// as [`serde_json`] doesn't have a way to build these.
///
/// ## Example:
/// ```no_run
/// # #[cfg(not(feature = "types-only"))]
/// # fn test() -> odoo_api::client::error::Result<()> {
/// # use serde_json::{json, Value, Map};
/// # use odoo_api::{jvec, jmap};
/// # use odoo_api::{OdooClient};
/// # let client = OdooClient::new_reqwest_blocking("https://demo.odoo.com")?;
/// # let mut client = client.authenticate_manual("", "", 1, "", None);
/// // Manually
/// let mut kwargs = Map::<String, Value>::new();
/// kwargs.insert("domain".into(), json!([["name", "ilike", "admin"]]));
/// kwargs.insert("fields".into(), json!(["id", "login"]));
///
/// let request = client.execute_kw(
/// "res.users",
/// "search_read",
/// jvec![],
/// kwargs,
/// ).send()?;
///
/// // With jmap!{}:
/// let request = client.execute_kw(
/// "res.users",
/// "search_read",
/// jvec![],
/// jmap!{
/// "domain": [["name", "ilike", "admin"]],
/// "fields": ["id", "login"]
/// }
/// ).send()?;
/// # Ok(())
/// # }
/// ```
=> ;
=> ;
}
/// Helper macro to build a [`Vec<String>`]
///
/// Quite a few ORM methods take [`Vec<String>`] as an argument. Using the built-in
/// `vec![]` macro requires that each element is converted into a `String`, which
/// is very cumbersome.
///
/// Using this macro, we can write:
/// ```
/// # #[cfg(not(feature = "types-only"))]
/// # fn test() {
/// # use odoo_api::svec;
/// let fields = svec!["string", "literals", "without", "to_string()"];
/// # }
/// ```
};
=> ;
}