@openfn/language-odoo 1.0.0 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ast.json +40 -9
- package/dist/index.cjs +26 -12
- package/dist/index.js +26 -12
- package/package.json +1 -1
- package/types/Adaptor.d.ts +59 -8
package/ast.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"options"
|
|
9
9
|
],
|
|
10
10
|
"docs": {
|
|
11
|
-
"description": "Create a record in Odoo",
|
|
11
|
+
"description": "Create a record in Odoo.\nYou can pass an external ID to the options object to create a record with a specific ID.\nYou can also pass a downloadNewRecord option to download the whole created resource in the response.",
|
|
12
12
|
"tags": [
|
|
13
13
|
{
|
|
14
14
|
"title": "public",
|
|
@@ -17,7 +17,13 @@
|
|
|
17
17
|
},
|
|
18
18
|
{
|
|
19
19
|
"title": "example",
|
|
20
|
-
"description": "create(
|
|
20
|
+
"description": "create('res.partner', { name: 'Kool Keith' }, { externalId: 23 });",
|
|
21
|
+
"caption": "Create a partner record with an external Id"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"title": "example",
|
|
25
|
+
"description": "create('res.partner', { name: 'Kool Keith' }, { downloadNewRecord: true });",
|
|
26
|
+
"caption": "Create a partner record and download the whole record in the response"
|
|
21
27
|
},
|
|
22
28
|
{
|
|
23
29
|
"title": "function",
|
|
@@ -44,13 +50,17 @@
|
|
|
44
50
|
},
|
|
45
51
|
{
|
|
46
52
|
"title": "param",
|
|
47
|
-
"description": "
|
|
53
|
+
"description": "Options to send to the request.",
|
|
48
54
|
"type": {
|
|
49
55
|
"type": "NameExpression",
|
|
50
|
-
"name": "
|
|
56
|
+
"name": "CreateOptions"
|
|
51
57
|
},
|
|
52
58
|
"name": "options"
|
|
53
59
|
},
|
|
60
|
+
{
|
|
61
|
+
"title": "state",
|
|
62
|
+
"description": "{OdooState}"
|
|
63
|
+
},
|
|
54
64
|
{
|
|
55
65
|
"title": "returns",
|
|
56
66
|
"description": null,
|
|
@@ -80,7 +90,7 @@
|
|
|
80
90
|
},
|
|
81
91
|
{
|
|
82
92
|
"title": "example",
|
|
83
|
-
"description": "read(\"res.partner\", [1] , [name]);",
|
|
93
|
+
"description": "read(\"res.partner\", [1] , ['name']);",
|
|
84
94
|
"caption": "Download records with select fields"
|
|
85
95
|
},
|
|
86
96
|
{
|
|
@@ -113,13 +123,26 @@
|
|
|
113
123
|
},
|
|
114
124
|
{
|
|
115
125
|
"title": "param",
|
|
116
|
-
"description": "An optional array of
|
|
117
|
-
"type": {
|
|
118
|
-
"type": "
|
|
119
|
-
"
|
|
126
|
+
"description": "An optional array of field strings to read from the record.",
|
|
127
|
+
"type": {
|
|
128
|
+
"type": "TypeApplication",
|
|
129
|
+
"expression": {
|
|
130
|
+
"type": "NameExpression",
|
|
131
|
+
"name": "Array"
|
|
132
|
+
},
|
|
133
|
+
"applications": [
|
|
134
|
+
{
|
|
135
|
+
"type": "NameExpression",
|
|
136
|
+
"name": "string"
|
|
137
|
+
}
|
|
138
|
+
]
|
|
120
139
|
},
|
|
121
140
|
"name": "fields"
|
|
122
141
|
},
|
|
142
|
+
{
|
|
143
|
+
"title": "state",
|
|
144
|
+
"description": "{OdooState}"
|
|
145
|
+
},
|
|
123
146
|
{
|
|
124
147
|
"title": "returns",
|
|
125
148
|
"description": null,
|
|
@@ -183,6 +206,10 @@
|
|
|
183
206
|
},
|
|
184
207
|
"name": "data"
|
|
185
208
|
},
|
|
209
|
+
{
|
|
210
|
+
"title": "state",
|
|
211
|
+
"description": "{OdooState}"
|
|
212
|
+
},
|
|
186
213
|
{
|
|
187
214
|
"title": "returns",
|
|
188
215
|
"description": null,
|
|
@@ -236,6 +263,10 @@
|
|
|
236
263
|
},
|
|
237
264
|
"name": "recordId"
|
|
238
265
|
},
|
|
266
|
+
{
|
|
267
|
+
"title": "state",
|
|
268
|
+
"description": "{OdooState}"
|
|
269
|
+
},
|
|
239
270
|
{
|
|
240
271
|
"title": "returns",
|
|
241
272
|
"description": null,
|
package/dist/index.cjs
CHANGED
|
@@ -100,21 +100,35 @@ async function login(state) {
|
|
|
100
100
|
}
|
|
101
101
|
return state;
|
|
102
102
|
}
|
|
103
|
-
function create(model, data, options) {
|
|
103
|
+
function create(model, data, options = {}) {
|
|
104
104
|
return async (state) => {
|
|
105
|
+
const mergedOptions = { downloadNewRecord: false, ...options };
|
|
105
106
|
const [resolvedModel, resolvedData, resolvedOptions] = (0, import_util.expandReferences)(
|
|
106
107
|
state,
|
|
107
108
|
model,
|
|
108
109
|
data,
|
|
109
|
-
|
|
110
|
+
mergedOptions
|
|
110
111
|
);
|
|
111
|
-
console.log(resolvedModel
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
112
|
+
console.log(`Creating a ${resolvedModel} resource...`);
|
|
113
|
+
try {
|
|
114
|
+
let newRecordId = await odooConn.create(
|
|
115
|
+
resolvedModel,
|
|
116
|
+
resolvedData,
|
|
117
|
+
resolvedOptions == null ? void 0 : resolvedOptions.externalId
|
|
118
|
+
);
|
|
119
|
+
if (resolvedOptions.downloadNewRecord) {
|
|
120
|
+
console.log(
|
|
121
|
+
`Fetching ${resolvedModel} resource with id ${newRecordId}......`
|
|
122
|
+
);
|
|
123
|
+
const newRecord = await odooConn.read(resolvedModel, [newRecordId], []);
|
|
124
|
+
return (0, import_language_common.composeNextState)(state, newRecord);
|
|
125
|
+
} else {
|
|
126
|
+
return (0, import_language_common.composeNextState)(state, newRecordId);
|
|
127
|
+
}
|
|
128
|
+
} catch (e) {
|
|
129
|
+
console.error(`Error creating ${resolvedModel} resource: ${e}`);
|
|
130
|
+
throw e;
|
|
131
|
+
}
|
|
118
132
|
};
|
|
119
133
|
}
|
|
120
134
|
function read(model, recordId, fields2 = []) {
|
|
@@ -125,7 +139,7 @@ function read(model, recordId, fields2 = []) {
|
|
|
125
139
|
recordId,
|
|
126
140
|
fields2
|
|
127
141
|
);
|
|
128
|
-
console.log(resolvedModel
|
|
142
|
+
console.log(`Reading a ${resolvedModel} resource...`);
|
|
129
143
|
const response = await odooConn.read(
|
|
130
144
|
resolvedModel,
|
|
131
145
|
resolvedRecordId,
|
|
@@ -142,7 +156,7 @@ function update(model, recordId, data) {
|
|
|
142
156
|
recordId,
|
|
143
157
|
data
|
|
144
158
|
);
|
|
145
|
-
console.log(resolvedModel
|
|
159
|
+
console.log(`Updating a ${resolvedModel} resource...`);
|
|
146
160
|
const response = await odooConn.update(
|
|
147
161
|
resolvedModel,
|
|
148
162
|
resolvedRecordId,
|
|
@@ -158,7 +172,7 @@ function deleteRecord(model, recordId) {
|
|
|
158
172
|
model,
|
|
159
173
|
recordId
|
|
160
174
|
);
|
|
161
|
-
console.log(resolvedModel
|
|
175
|
+
console.log(`Deleting a ${resolvedModel} resource...`);
|
|
162
176
|
const response = await odooConn.delete(resolvedModel, resolvedRecordId);
|
|
163
177
|
return (0, import_language_common.composeNextState)(state, response);
|
|
164
178
|
};
|
package/dist/index.js
CHANGED
|
@@ -73,21 +73,35 @@ async function login(state) {
|
|
|
73
73
|
}
|
|
74
74
|
return state;
|
|
75
75
|
}
|
|
76
|
-
function create(model, data, options) {
|
|
76
|
+
function create(model, data, options = {}) {
|
|
77
77
|
return async (state) => {
|
|
78
|
+
const mergedOptions = { downloadNewRecord: false, ...options };
|
|
78
79
|
const [resolvedModel, resolvedData, resolvedOptions] = expandReferences(
|
|
79
80
|
state,
|
|
80
81
|
model,
|
|
81
82
|
data,
|
|
82
|
-
|
|
83
|
+
mergedOptions
|
|
83
84
|
);
|
|
84
|
-
console.log(resolvedModel
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
85
|
+
console.log(`Creating a ${resolvedModel} resource...`);
|
|
86
|
+
try {
|
|
87
|
+
let newRecordId = await odooConn.create(
|
|
88
|
+
resolvedModel,
|
|
89
|
+
resolvedData,
|
|
90
|
+
resolvedOptions == null ? void 0 : resolvedOptions.externalId
|
|
91
|
+
);
|
|
92
|
+
if (resolvedOptions.downloadNewRecord) {
|
|
93
|
+
console.log(
|
|
94
|
+
`Fetching ${resolvedModel} resource with id ${newRecordId}......`
|
|
95
|
+
);
|
|
96
|
+
const newRecord = await odooConn.read(resolvedModel, [newRecordId], []);
|
|
97
|
+
return composeNextState(state, newRecord);
|
|
98
|
+
} else {
|
|
99
|
+
return composeNextState(state, newRecordId);
|
|
100
|
+
}
|
|
101
|
+
} catch (e) {
|
|
102
|
+
console.error(`Error creating ${resolvedModel} resource: ${e}`);
|
|
103
|
+
throw e;
|
|
104
|
+
}
|
|
91
105
|
};
|
|
92
106
|
}
|
|
93
107
|
function read(model, recordId, fields2 = []) {
|
|
@@ -98,7 +112,7 @@ function read(model, recordId, fields2 = []) {
|
|
|
98
112
|
recordId,
|
|
99
113
|
fields2
|
|
100
114
|
);
|
|
101
|
-
console.log(resolvedModel
|
|
115
|
+
console.log(`Reading a ${resolvedModel} resource...`);
|
|
102
116
|
const response = await odooConn.read(
|
|
103
117
|
resolvedModel,
|
|
104
118
|
resolvedRecordId,
|
|
@@ -115,7 +129,7 @@ function update(model, recordId, data) {
|
|
|
115
129
|
recordId,
|
|
116
130
|
data
|
|
117
131
|
);
|
|
118
|
-
console.log(resolvedModel
|
|
132
|
+
console.log(`Updating a ${resolvedModel} resource...`);
|
|
119
133
|
const response = await odooConn.update(
|
|
120
134
|
resolvedModel,
|
|
121
135
|
resolvedRecordId,
|
|
@@ -131,7 +145,7 @@ function deleteRecord(model, recordId) {
|
|
|
131
145
|
model,
|
|
132
146
|
recordId
|
|
133
147
|
);
|
|
134
|
-
console.log(resolvedModel
|
|
148
|
+
console.log(`Deleting a ${resolvedModel} resource...`);
|
|
135
149
|
const response = await odooConn.delete(resolvedModel, resolvedRecordId);
|
|
136
150
|
return composeNextState(state, response);
|
|
137
151
|
};
|
package/package.json
CHANGED
package/types/Adaptor.d.ts
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* State object
|
|
3
|
+
* @typedef {Object} OdooState
|
|
4
|
+
* @property data - The response body (as JSON)
|
|
5
|
+
* @property response - The HTTP response from the Odoo server (excluding the body)
|
|
6
|
+
* @property references - An array of all previous data objects used in the Job
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Options object
|
|
10
|
+
* @typedef {Object} CreateOptions
|
|
11
|
+
* @property {number} externalId - An optional id to be used in the request
|
|
12
|
+
* @property {boolean} downloadNewRecord - An option defaulted to `false` incase a user intends to receive the whole created resource in the response. The collective response will be written in `state.data`.
|
|
13
|
+
*/
|
|
1
14
|
/**
|
|
2
15
|
* Execute a sequence of operations.
|
|
3
16
|
* Wraps `language-common/execute` to make working with this API easier.
|
|
@@ -13,31 +26,37 @@
|
|
|
13
26
|
export function execute(...operations: Operations): Operation;
|
|
14
27
|
export function setMockClient(mock: any): void;
|
|
15
28
|
/**
|
|
16
|
-
* Create a record in Odoo
|
|
29
|
+
* Create a record in Odoo.
|
|
30
|
+
* You can pass an external ID to the options object to create a record with a specific ID.
|
|
31
|
+
* You can also pass a downloadNewRecord option to download the whole created resource in the response.
|
|
17
32
|
* @public
|
|
18
|
-
* @example
|
|
19
|
-
* create(
|
|
33
|
+
* @example <caption> Create a partner record with an external Id </caption>
|
|
34
|
+
* create('res.partner', { name: 'Kool Keith' }, { externalId: 23 });
|
|
35
|
+
* @example <caption> Create a partner record and download the whole record in the response </caption>
|
|
36
|
+
* create('res.partner', { name: 'Kool Keith' }, { downloadNewRecord: true });
|
|
20
37
|
* @function
|
|
21
38
|
* @param {string} model - The specific record model i.e. "res.partner"
|
|
22
39
|
* @param {object} data - The data to be created in JSON.
|
|
23
|
-
* @param {
|
|
40
|
+
* @param {CreateOptions} options - Options to send to the request.
|
|
41
|
+
* @state {OdooState}
|
|
24
42
|
* @returns {Operation}
|
|
25
43
|
*/
|
|
26
|
-
export function create(model: string, data: object, options
|
|
44
|
+
export function create(model: string, data: object, options?: CreateOptions): Operation;
|
|
27
45
|
/**
|
|
28
46
|
* Get a record from Odoo. Returns all fields unless a field list is provided as a third argument
|
|
29
47
|
* @public
|
|
30
48
|
* @example <caption>Download records with select fields</caption>
|
|
31
|
-
* read("res.partner", [1] , [name]);
|
|
49
|
+
* read("res.partner", [1] , ['name']);
|
|
32
50
|
* @example <caption>Download a single record with all fields</caption>
|
|
33
51
|
* read("res.partner", $.recordIds);
|
|
34
52
|
* @function
|
|
35
53
|
* @param {string} model - The specific record model from i.e. "res.partner"
|
|
36
54
|
* @param {number} recordId - An array of record IDs to read.
|
|
37
|
-
* @param {string} fields - An optional array of
|
|
55
|
+
* @param {string[]} fields - An optional array of field strings to read from the record.
|
|
56
|
+
* @state {OdooState}
|
|
38
57
|
* @returns {Operation}
|
|
39
58
|
*/
|
|
40
|
-
export function read(model: string, recordId: number, fields?: string): Operation;
|
|
59
|
+
export function read(model: string, recordId: number, fields?: string[]): Operation;
|
|
41
60
|
/**
|
|
42
61
|
* Update a record in Odoo
|
|
43
62
|
* @public
|
|
@@ -47,6 +66,7 @@ export function read(model: string, recordId: number, fields?: string): Operatio
|
|
|
47
66
|
* @param {string} model - The specific record model i.e. "res.partner"
|
|
48
67
|
* @param {number} recordId - The specific recordId to be updated.
|
|
49
68
|
* @param {object} data - The data to be updated in JSON.
|
|
69
|
+
* @state {OdooState}
|
|
50
70
|
* @returns {Operation}
|
|
51
71
|
*/
|
|
52
72
|
export function update(model: string, recordId: number, data: object): Operation;
|
|
@@ -58,7 +78,38 @@ export function update(model: string, recordId: number, data: object): Operation
|
|
|
58
78
|
* @function
|
|
59
79
|
* @param {string} model - The specific record model i.e. "res.partner"
|
|
60
80
|
* @param {number} recordId - The specific recordId to be deleted.
|
|
81
|
+
* @state {OdooState}
|
|
61
82
|
* @returns {Operation}
|
|
62
83
|
*/
|
|
63
84
|
export function deleteRecord(model: string, recordId: number): Operation;
|
|
85
|
+
/**
|
|
86
|
+
* State object
|
|
87
|
+
*/
|
|
88
|
+
export type OdooState = {
|
|
89
|
+
/**
|
|
90
|
+
* - The response body (as JSON)
|
|
91
|
+
*/
|
|
92
|
+
data: any;
|
|
93
|
+
/**
|
|
94
|
+
* - The HTTP response from the Odoo server (excluding the body)
|
|
95
|
+
*/
|
|
96
|
+
response: any;
|
|
97
|
+
/**
|
|
98
|
+
* - An array of all previous data objects used in the Job
|
|
99
|
+
*/
|
|
100
|
+
references: any;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Options object
|
|
104
|
+
*/
|
|
105
|
+
export type CreateOptions = {
|
|
106
|
+
/**
|
|
107
|
+
* - An optional id to be used in the request
|
|
108
|
+
*/
|
|
109
|
+
externalId: number;
|
|
110
|
+
/**
|
|
111
|
+
* - An option defaulted to `false` incase a user intends to receive the whole created resource in the response. The collective response will be written in `state.data`.
|
|
112
|
+
*/
|
|
113
|
+
downloadNewRecord: boolean;
|
|
114
|
+
};
|
|
64
115
|
export { dataPath, dataValue, dateFns, each, field, fields, fn, http, lastReferenceValue, merge, sourceValue } from "@openfn/language-common";
|