|
| 1 | +import dolibarr from "../../dolibarr.app.mjs"; |
| 2 | +import { parseObject } from "../../common/utils.mjs"; |
| 3 | + |
| 4 | +export default { |
| 5 | + key: "dolibarr-create-order", |
| 6 | + name: "Create Order", |
| 7 | + description: "Create a new order in Dolibarr.", |
| 8 | + version: "0.0.1", |
| 9 | + type: "action", |
| 10 | + props: { |
| 11 | + dolibarr, |
| 12 | + thirdPartyId: { |
| 13 | + propDefinition: [ |
| 14 | + dolibarr, |
| 15 | + "thirdPartyId", |
| 16 | + ], |
| 17 | + }, |
| 18 | + date: { |
| 19 | + type: "string", |
| 20 | + label: "Date", |
| 21 | + description: "The date of the order in YYYY-MM-DD format", |
| 22 | + }, |
| 23 | + deliveryDate: { |
| 24 | + type: "string", |
| 25 | + label: "Delivery Date", |
| 26 | + description: "The expecteddelivery date of the order in YYYY-MM-DD format", |
| 27 | + optional: true, |
| 28 | + }, |
| 29 | + paymentMethodCode: { |
| 30 | + propDefinition: [ |
| 31 | + dolibarr, |
| 32 | + "paymentMethodCode", |
| 33 | + ], |
| 34 | + }, |
| 35 | + paymentTermCode: { |
| 36 | + propDefinition: [ |
| 37 | + dolibarr, |
| 38 | + "paymentTermCode", |
| 39 | + ], |
| 40 | + }, |
| 41 | + notePublic: { |
| 42 | + type: "string", |
| 43 | + label: "Note Public", |
| 44 | + description: "A public note to add to the order", |
| 45 | + optional: true, |
| 46 | + }, |
| 47 | + notePrivate: { |
| 48 | + type: "string", |
| 49 | + label: "Note Private", |
| 50 | + description: "A private note to add to the order", |
| 51 | + optional: true, |
| 52 | + }, |
| 53 | + additionalProperties: { |
| 54 | + propDefinition: [ |
| 55 | + dolibarr, |
| 56 | + "additionalProperties", |
| 57 | + ], |
| 58 | + }, |
| 59 | + }, |
| 60 | + async run({ $ }) { |
| 61 | + const response = await this.dolibarr.createOrder({ |
| 62 | + $, |
| 63 | + data: { |
| 64 | + socid: this.thirdPartyId, |
| 65 | + date: Date.parse(this.date) / 1000, |
| 66 | + deliverydate: this.deliveryDate |
| 67 | + ? Date.parse(this.deliveryDate) / 1000 |
| 68 | + : undefined, |
| 69 | + mode_reglement_code: this.paymentMethodCode, |
| 70 | + cond_reglement_code: this.paymentTermCode, |
| 71 | + note_public: this.notePublic, |
| 72 | + note_private: this.notePrivate, |
| 73 | + ...parseObject(this.additionalProperties), |
| 74 | + }, |
| 75 | + }); |
| 76 | + $.export("$summary", `Successfully created order ${response}`); |
| 77 | + return response; |
| 78 | + }, |
| 79 | +}; |
0 commit comments