Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions components/odoo/actions/create-record/create-record.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,33 @@ export default {
key: "odoo-create-record",
name: "Create Record",
description: "Create a new record in Odoo. [See the documentation](https://www.odoo.com/documentation/18.0/developer/reference/external_api.html#create-records)",
version: "0.0.2",
version: "0.0.3",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: false,
},
type: "action",
props: {
odoo: {
...odoo,
odoo,
modelName: {
propDefinition: [
odoo,
"modelName",
],
reloadProps: true,
},
},
Comment thread
e11man marked this conversation as resolved.
async additionalProps() {
return await this.odoo.getFieldProps();
return await this.odoo.getFieldProps(this.modelName);
},
async run({ $ }) {
const {
odoo,
modelName,
...data
} = this;
const response = await odoo.createRecord([
const response = await odoo.createRecord(modelName, [
data,
]);
$.export("$summary", `Successfully created record with ID: ${response}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default {
key: "odoo-search-read-records",
name: "Search and Read Records",
description: "Search and read records from Odoo. [See the documentation](https://www.odoo.com/documentation/18.0/developer/reference/external_api.html#search-and-read)",
version: "0.0.2",
version: "0.0.3",
annotations: {
destructiveHint: false,
openWorldHint: true,
Expand All @@ -14,6 +14,13 @@ export default {
type: "action",
props: {
odoo,
modelName: {
propDefinition: [
odoo,
"modelName",
],
reloadProps: true,
},
filter: {
type: "string",
label: "Search Filter",
Expand All @@ -24,6 +31,9 @@ export default {
propDefinition: [
odoo,
"fields",
({ modelName }) => ({
modelName,
}),
],
},
},
Expand All @@ -33,7 +43,11 @@ export default {
fields: this.fields,
}
: {};
const response = await this.odoo.searchAndReadRecords(parseObject(this.filter), args);
const response = await this.odoo.searchAndReadRecords(
this.modelName,
parseObject(this.filter),
args,
);
$.export("$summary", `Successfully retrieved ${response.length} record${response.length === 1
? ""
: "s"}`);
Expand Down
17 changes: 11 additions & 6 deletions components/odoo/actions/update-record/update-record.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,25 @@ export default {
key: "odoo-update-record",
name: "Update Record",
description: "Update an existing record in Odoo. [See the documentation](https://www.odoo.com/documentation/18.0/developer/reference/external_api.html#update-records)",
version: "0.0.2",
version: "0.0.3",
annotations: {
destructiveHint: true,
openWorldHint: true,
readOnlyHint: false,
},
type: "action",
props: {
odoo: {
...odoo,
odoo,
modelName: {
propDefinition: [
odoo,
"modelName",
],
reloadProps: true,
},
},
async additionalProps() {
const fieldProps = await this.odoo.getFieldProps({
const fieldProps = await this.odoo.getFieldProps(this.modelName, {
update: true,
});
const recordId = {
Expand All @@ -35,7 +39,7 @@ export default {
},
methods: {
async getRecordIdOptions(page) {
const records = await this.odoo.searchAndReadRecords([], {
const records = await this.odoo.searchAndReadRecords(this.modelName, [], {
limit: DEFAULT_LIMIT,
offset: page * DEFAULT_LIMIT,
});
Expand All @@ -52,10 +56,11 @@ export default {
odoo,
// eslint-disable-next-line no-unused-vars
getRecordIdOptions,
modelName,
recordId,
...data
} = this;
const response = await odoo.updateRecord([
const response = await odoo.updateRecord(modelName, [
[
recordId,
],
Expand Down
47 changes: 28 additions & 19 deletions components/odoo/odoo.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,25 @@ export default {
type: "app",
app: "odoo",
propDefinitions: {
modelName: {
type: "string",
label: "Model Name",
description: "The technical name of the Odoo model to interact with (e.g. `res.partner`, `helpdesk.ticket`, `sale.order`, `crm.lead`).",
default: "res.partner",
options: [
"res.partner",
"helpdesk.ticket",
"sale.order",
"crm.lead",
],
},
Comment thread
e11man marked this conversation as resolved.
fields: {
type: "string[]",
label: "Fields",
description: "The fields to return in the results. If not provided, all fields will be returned.",
optional: true,
async options() {
const fields = await this.getFields([], {
async options({ modelName }) {
const fields = await this.getFields(modelName ?? "res.partner", [], {
attributes: [
"string",
],
Expand Down Expand Up @@ -39,12 +51,12 @@ export default {
{},
], (error, value) => {
if (error) reject(error);
resolve(value);
else resolve(value);
});
});
return uid;
},
async makeRequest(method, filter = [], args = {}) {
async makeRequest(model, method, filter = [], args = {}) {
const db = this.$auth.db;
const uid = await this.getUid();
const password = this.$auth.password;
Expand All @@ -54,20 +66,20 @@ export default {
db,
uid,
password,
"res.partner",
model,
method,
filter,
args,
], (error, value) => {
if (error) reject(error);
resolve(value);
else resolve(value);
});
});
return results;
},
async getFieldProps({ update = false } = {}) {
async getFieldProps(model, { update = false } = {}) {
const props = {};
const fields = await this.getFields();
const fields = await this.getFields(model, [], {});
Object.keys(fields).forEach((key) => {
if (fields[key].readonly === true) return;
props[key] = {
Expand All @@ -85,20 +97,17 @@ export default {
});
return props;
},
getFields(filter = [], args = {}) {
return this.makeRequest("fields_get", filter, args);
},
searchAndReadRecords(filter = [], args = {}) {
return this.makeRequest("search_read", filter, args);
getFields(model, filter = [], args = {}) {
return this.makeRequest(model, "fields_get", filter, args);
},
readRecord(data) {
return this.makeRequest("read", data);
searchAndReadRecords(model, filter = [], args = {}) {
return this.makeRequest(model, "search_read", filter, args);
},
createRecord(data) {
return this.makeRequest("create", data);
createRecord(model, data) {
return this.makeRequest(model, "create", data);
},
updateRecord(data) {
return this.makeRequest("write", data);
updateRecord(model, data) {
return this.makeRequest(model, "write", data);
},
},
};
2 changes: 1 addition & 1 deletion components/odoo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/odoo",
"version": "0.1.0",
"version": "0.2.0",
"description": "Pipedream Odoo Components",
"main": "odoo.app.mjs",
"keywords": [
Expand Down
Loading