Using `odoo_call_kw` to Read/Update Odoo Models
The odoo_call_kw
function allows you to interact with Odoo models using various supported methods, including:
read
write
name_get
load_views
has_group
Implementation of odoo_call_kw
async function odoo_call_kw(params) {
return new Promise((resolve, reject) => {
fetch(`${odoo_url_api}/call_kw`, {
method: "POST",
headers: {
"Authorization": token,
"Content-Type": "application/json"
},
body: JSON.stringify(params)
})
.then(result => result.json())
.then(data => {
if (data.error?.code)
reject(data);
else
resolve(data);
})
.catch(error => reject(error));
});
}
How to Use It
- Open the Network tab in the browser's developer tools.
- Check the requests of type call_kw.
- Switch to the Payload tab and copy the
params
object. - Paste the copied object into the
odoo_call_kw
function.
Example Usage
let res = await odoo_call_kw(
{
"model": "simple.model",
"domain": [],
"fields": [
"name",
"date_start",
"description"
],
"limit": 80,
"sort": "",
"context": {
"lang": "en_US",
"tz": "Asia/Bangkok",
"uid": 6,
"allowed_company_ids": [
1
],
"params": {
"menu_id": 425,
"action": 616,
"model": "simple.model",
"view_type": "list",
"cids": 1
},
"bin_size": true
}
}
);
Conclusion
By using odoo_call_kw
, you can efficiently interact with Odoo models, perform read and write operations, and manage access permissions.
odoo_call_kw;rest api
Like
Reply