-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New Components - odoo #17246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Components - odoo #17246
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import odoo from "../../odoo.app.mjs"; | ||
|
|
||
| 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.1", | ||
| type: "action", | ||
| props: { | ||
| odoo: { | ||
|
Check warning on line 10 in components/odoo/actions/create-record/create-record.mjs
|
||
| ...odoo, | ||
| reloadProps: true, | ||
| }, | ||
| }, | ||
| async additionalProps() { | ||
| return await this.odoo.getFieldProps(); | ||
| }, | ||
| async run({ $ }) { | ||
| const { | ||
| odoo, | ||
| ...data | ||
| } = this; | ||
| const response = await odoo.createRecord([ | ||
| data, | ||
| ]); | ||
| $.export("$summary", `Successfully created record with ID: ${response}`); | ||
| return response; | ||
| }, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import odoo from "../../odoo.app.mjs"; | ||
| import { parseObject } from "../../common/utils.mjs"; | ||
|
|
||
| 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.1", | ||
| type: "action", | ||
| props: { | ||
| odoo, | ||
| filter: { | ||
| type: "string", | ||
| label: "Search Filter", | ||
| description: "The criterion to search by. E.g. `[[[\"is_company\", \"=\", true]]]`. [See the documentation](https://www.odoo.com/documentation/18.0/developer/reference/backend/orm.html#search-domains) for information about constructing a search domain", | ||
| optional: true, | ||
| }, | ||
| fields: { | ||
| propDefinition: [ | ||
| odoo, | ||
| "fields", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const args = this.fields | ||
| ? { | ||
| fields: this.fields, | ||
| } | ||
| : {}; | ||
| const response = await this.odoo.searchAndReadRecords(parseObject(this.filter), args); | ||
| $.export("$summary", `Successfully retrieved ${response.length} record${response.length === 1 | ||
| ? "" | ||
| : "s"}`); | ||
| return response; | ||
| }, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import odoo from "../../odoo.app.mjs"; | ||
| const DEFAULT_LIMIT = 20; | ||
|
|
||
| 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.1", | ||
| type: "action", | ||
| props: { | ||
| odoo: { | ||
|
Check warning on line 11 in components/odoo/actions/update-record/update-record.mjs
|
||
| ...odoo, | ||
| reloadProps: true, | ||
| }, | ||
| }, | ||
| async additionalProps() { | ||
| const fieldProps = await this.odoo.getFieldProps({ | ||
| update: true, | ||
| }); | ||
| const recordId = { | ||
| type: "integer", | ||
| label: "Record ID", | ||
| description: "The ID of the record to update", | ||
| options: async ({ page }) => await this.getRecordIdOptions(page), | ||
| }; | ||
| return { | ||
| recordId, | ||
| ...fieldProps, | ||
| }; | ||
| }, | ||
| methods: { | ||
| async getRecordIdOptions(page) { | ||
| const records = await this.odoo.searchAndReadRecords([], { | ||
| limit: DEFAULT_LIMIT, | ||
| offset: page * DEFAULT_LIMIT, | ||
| }); | ||
| return records?.map(({ | ||
| id: value, display_name: label, | ||
| }) => ({ | ||
| value, | ||
| label, | ||
| })) || []; | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const { | ||
| odoo, | ||
| // eslint-disable-next-line no-unused-vars | ||
| getRecordIdOptions, | ||
| recordId, | ||
| ...data | ||
| } = this; | ||
| const response = await odoo.updateRecord([ | ||
| [ | ||
| recordId, | ||
| ], | ||
| data, | ||
| ]); | ||
| $.export("$summary", `Successfully updated record with ID: ${recordId}`); | ||
| return response; | ||
| }, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| export const parseObject = (obj) => { | ||
| if (!obj) { | ||
| return undefined; | ||
| } | ||
| if (typeof obj === "string") { | ||
| try { | ||
| return JSON.parse(obj); | ||
| } catch (e) { | ||
| return obj; | ||
| } | ||
| } | ||
| if (Array.isArray(obj)) { | ||
| return obj.map(parseObject); | ||
| } | ||
| if (typeof obj === "object") { | ||
| return Object.fromEntries(Object.entries(obj).map(([ | ||
| key, | ||
| value, | ||
| ]) => [ | ||
| key, | ||
| parseObject(value), | ||
| ])); | ||
| } | ||
| return obj; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,104 @@ | ||
| import xmlrpc from "xmlrpc"; | ||
|
|
||
| export default { | ||
| type: "app", | ||
| app: "odoo", | ||
| propDefinitions: {}, | ||
| propDefinitions: { | ||
| 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([], { | ||
| attributes: [ | ||
| "string", | ||
| ], | ||
| }); | ||
| return Object.keys(fields)?.map((key) => ({ | ||
| value: key, | ||
| label: fields[key].string, | ||
| })) || []; | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| }, | ||
| methods: { | ||
| // this.$auth contains connected account data | ||
| authKeys() { | ||
| console.log(Object.keys(this.$auth)); | ||
| getClient(type = "common") { | ||
| return xmlrpc.createSecureClient(`${this.$auth.server_url}/xmlrpc/2/${type}`); | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| async getUid() { | ||
| const db = this.$auth.db; | ||
| const username = this.$auth.username; | ||
| const password = this.$auth.password; | ||
| const common = this.getClient("common"); | ||
| const uid = await new Promise((resolve, reject) => { | ||
| common.methodCall("authenticate", [ | ||
| db, | ||
| username, | ||
| password, | ||
| {}, | ||
| ], (error, value) => { | ||
| if (error) reject(error); | ||
| resolve(value); | ||
| }); | ||
| }); | ||
| return uid; | ||
| }, | ||
| async makeRequest(method, filter = [], args = {}) { | ||
| const db = this.$auth.db; | ||
| const uid = await this.getUid(); | ||
| const password = this.$auth.password; | ||
| const models = this.getClient("object"); | ||
| const results = await new Promise((resolve, reject) => { | ||
| models.methodCall("execute_kw", [ | ||
| db, | ||
| uid, | ||
| password, | ||
| "res.partner", | ||
| method, | ||
| filter, | ||
| args, | ||
| ], (error, value) => { | ||
| if (error) reject(error); | ||
| resolve(value); | ||
| }); | ||
| }); | ||
| return results; | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| async getFieldProps({ update = false } = {}) { | ||
| const props = {}; | ||
| const fields = await this.getFields(); | ||
| Object.keys(fields).forEach((key) => { | ||
| if (fields[key].readonly === true) return; | ||
| props[key] = { | ||
| type: fields[key].type === "integer" || fields[key].type === "boolean" | ||
| ? fields[key].type | ||
| : fields[key].type.includes("id") | ||
| ? "integer" | ||
| : fields[key].type.includes("2many") | ||
| ? "string[]" | ||
| : "string", | ||
| label: fields[key].string, | ||
| description: `Value for "${key}"`, | ||
| optional: (key !== "name" || update) && fields[key].required === false, | ||
| }; | ||
| }); | ||
| return props; | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| getFields(filter = [], args = {}) { | ||
| return this.makeRequest("fields_get", filter, args); | ||
| }, | ||
| searchAndReadRecords(filter = [], args = {}) { | ||
| return this.makeRequest("search_read", filter, args); | ||
| }, | ||
| readRecord(data) { | ||
| return this.makeRequest("read", data); | ||
| }, | ||
| createRecord(data) { | ||
| return this.makeRequest("create", data); | ||
| }, | ||
| updateRecord(data) { | ||
| return this.makeRequest("write", data); | ||
| }, | ||
| }, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "name": "@pipedream/odoo", | ||
| "version": "0.0.1", | ||
| "version": "0.1.0", | ||
| "description": "Pipedream Odoo Components", | ||
| "main": "odoo.app.mjs", | ||
| "keywords": [ | ||
|
|
@@ -11,5 +11,8 @@ | |
| "author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "xmlrpc": "^1.3.2" | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.