Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
79 changes: 79 additions & 0 deletions components/dolibarr/actions/create-order/create-order.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import dolibarr from "../../dolibarr.app.mjs";
import { parseObject } from "../../common/utils.mjs";

export default {
key: "dolibarr-create-order",
name: "Create Order",
description: "Create a new order in Dolibarr.",
version: "0.0.1",
type: "action",
props: {
dolibarr,
thirdPartyId: {
propDefinition: [
dolibarr,
"thirdPartyId",
],
},
date: {
type: "string",
label: "Date",
description: "The date of the order in YYYY-MM-DD format",
},
deliveryDate: {
type: "string",
label: "Delivery Date",
description: "The expecteddelivery date of the order in YYYY-MM-DD format",
optional: true,
},
paymentMethodCode: {
propDefinition: [
dolibarr,
"paymentMethodCode",
],
},
paymentTermCode: {
propDefinition: [
dolibarr,
"paymentTermCode",
],
},
notePublic: {
type: "string",
label: "Note Public",
description: "A public note to add to the order",
optional: true,
},
notePrivate: {
type: "string",
label: "Note Private",
description: "A private note to add to the order",
optional: true,
},
additionalProperties: {
propDefinition: [
dolibarr,
"additionalProperties",
],
},
},
async run({ $ }) {
const response = await this.dolibarr.createOrder({
$,
data: {
socid: this.thirdPartyId,
date: Date.parse(this.date) / 1000,
deliverydate: this.deliveryDate
? Date.parse(this.deliveryDate) / 1000
: undefined,
mode_reglement_code: this.paymentMethodCode,
cond_reglement_code: this.paymentTermCode,
note_public: this.notePublic,
note_private: this.notePrivate,
...parseObject(this.additionalProperties),
},
});
$.export("$summary", `Successfully created order ${response}`);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import dolibarr from "../../dolibarr.app.mjs";
import { parseObject } from "../../common/utils.mjs";

export default {
key: "dolibarr-create-thirdparty",
name: "Create Third Party",
description: "Create a new third party in Dolibarr.",
version: "0.0.1",
type: "action",
props: {
dolibarr,
name: {
type: "string",
label: "Name",
description: "The name of the third party",
},
email: {
type: "string",
label: "Email",
description: "The email address of the third party",
optional: true,
},
phone: {
type: "string",
label: "Phone",
description: "The phone number of the third party",
optional: true,
},
streetAddress: {
type: "string",
label: "Street Address",
description: "The street address of the third party",
optional: true,
},
zip: {
type: "string",
label: "Zip",
description: "The zip code of the third party",
optional: true,
},
town: {
type: "string",
label: "Town",
description: "The city or town of the third party",
optional: true,
},
additionalProperties: {
propDefinition: [
dolibarr,
"additionalProperties",
],
},
},
async run({ $ }) {
const response = await this.dolibarr.createThirdParty({
$,
data: {
name: this.name,
email: this.email,
phone: this.phone,
address: this.streetAddress,
zip: this.zip,
town: this.town,
...parseObject(this.additionalProperties),
},
});
$.export("$summary", `Successfully created third party with ID${response}`);
return response;
},
};
105 changes: 105 additions & 0 deletions components/dolibarr/actions/create-user/create-user.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import dolibarr from "../../dolibarr.app.mjs";
import { parseObject } from "../../common/utils.mjs";

export default {
key: "dolibarr-create-user",
name: "Create User",
description: "Create a new user in Dolibarr.",
version: "0.0.1",
type: "action",
props: {
dolibarr,
firstName: {
type: "string",
label: "First Name",
description: "The first name of the user",
optional: true,
},
lastName: {
type: "string",
label: "Last Name",
description: "The last name of the user",
},
login: {
type: "string",
label: "Login",
description: "The login name of the user. Must be unique.",
},
password: {
type: "string",
label: "Password",
description: "The password of the user",
},
email: {
type: "string",
label: "Email",
description: "The email address of the user",
optional: true,
},
officePhone: {
type: "string",
label: "Office Phone",
description: "The office phone number of the user",
optional: true,
},
jobPosition: {
type: "string",
label: "Job Position",
description: "The job position of the user",
optional: true,
},
isAdmin: {
type: "boolean",
label: "Is Admin",
description: "Whether the user is an administrator",
optional: true,
},
streetAddress: {
type: "string",
label: "Street Address",
description: "The street address of the user",
optional: true,
},
zip: {
type: "string",
label: "Zip",
description: "The zip code of the user",
optional: true,
},
town: {
type: "string",
label: "Town",
description: "The city or town of the user",
optional: true,
},
additionalProperties: {
propDefinition: [
dolibarr,
"additionalProperties",
],
},
},
async run({ $ }) {
const response = await this.dolibarr.createUser({
$,
data: {
firstname: this.firstName,
lastname: this.lastName,
login: this.login,
password: this.password,
email: this.email,
office_phone: this.officePhone,
job: this.jobPosition,
admin: this.isAdmin
? 1
: 0,
address: this.streetAddress,
zip: this.zip,
town: this.town,
...parseObject(this.additionalProperties),
},
});
$.export("$summary", `Successfully created user ${response}`);
return response;
},
};
27 changes: 27 additions & 0 deletions components/dolibarr/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export function parseObject(obj) {
if (!obj) {
return {};
}
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;
}
Loading
Loading