@openfn/language-odoo 1.0.1 → 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 +25 -4
- package/dist/index.cjs +21 -7
- package/dist/index.js +21 -7
- package/package.json +1 -1
- package/types/Adaptor.d.ts +56 -5
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,9 +17,14 @@
|
|
|
17
17
|
},
|
|
18
18
|
{
|
|
19
19
|
"title": "example",
|
|
20
|
-
"description": "create(
|
|
20
|
+
"description": "create('res.partner', { name: 'Kool Keith' }, { externalId: 23 });",
|
|
21
21
|
"caption": "Create a partner record with an external Id"
|
|
22
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"
|
|
27
|
+
},
|
|
23
28
|
{
|
|
24
29
|
"title": "function",
|
|
25
30
|
"description": null,
|
|
@@ -45,13 +50,17 @@
|
|
|
45
50
|
},
|
|
46
51
|
{
|
|
47
52
|
"title": "param",
|
|
48
|
-
"description": "Options to send to the request.
|
|
53
|
+
"description": "Options to send to the request.",
|
|
49
54
|
"type": {
|
|
50
55
|
"type": "NameExpression",
|
|
51
|
-
"name": "
|
|
56
|
+
"name": "CreateOptions"
|
|
52
57
|
},
|
|
53
58
|
"name": "options"
|
|
54
59
|
},
|
|
60
|
+
{
|
|
61
|
+
"title": "state",
|
|
62
|
+
"description": "{OdooState}"
|
|
63
|
+
},
|
|
55
64
|
{
|
|
56
65
|
"title": "returns",
|
|
57
66
|
"description": null,
|
|
@@ -130,6 +139,10 @@
|
|
|
130
139
|
},
|
|
131
140
|
"name": "fields"
|
|
132
141
|
},
|
|
142
|
+
{
|
|
143
|
+
"title": "state",
|
|
144
|
+
"description": "{OdooState}"
|
|
145
|
+
},
|
|
133
146
|
{
|
|
134
147
|
"title": "returns",
|
|
135
148
|
"description": null,
|
|
@@ -193,6 +206,10 @@
|
|
|
193
206
|
},
|
|
194
207
|
"name": "data"
|
|
195
208
|
},
|
|
209
|
+
{
|
|
210
|
+
"title": "state",
|
|
211
|
+
"description": "{OdooState}"
|
|
212
|
+
},
|
|
196
213
|
{
|
|
197
214
|
"title": "returns",
|
|
198
215
|
"description": null,
|
|
@@ -246,6 +263,10 @@
|
|
|
246
263
|
},
|
|
247
264
|
"name": "recordId"
|
|
248
265
|
},
|
|
266
|
+
{
|
|
267
|
+
"title": "state",
|
|
268
|
+
"description": "{OdooState}"
|
|
269
|
+
},
|
|
249
270
|
{
|
|
250
271
|
"title": "returns",
|
|
251
272
|
"description": null,
|
package/dist/index.cjs
CHANGED
|
@@ -102,19 +102,33 @@ async function login(state) {
|
|
|
102
102
|
}
|
|
103
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
112
|
console.log(`Creating a ${resolvedModel} resource...`);
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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 = []) {
|
package/dist/index.js
CHANGED
|
@@ -75,19 +75,33 @@ async function login(state) {
|
|
|
75
75
|
}
|
|
76
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
85
|
console.log(`Creating a ${resolvedModel} resource...`);
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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 = []) {
|
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,17 +26,22 @@
|
|
|
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 <caption> Create a partner record with an external Id</caption>
|
|
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
|
|
@@ -35,6 +53,7 @@ export function create(model: string, data: object, options?: object): Operation
|
|
|
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
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
59
|
export function read(model: string, recordId: number, fields?: string[]): Operation;
|
|
@@ -47,6 +66,7 @@ export function read(model: string, recordId: number, fields?: string[]): Operat
|
|
|
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";
|