Skip to content

Commit 69015ba

Browse files
authored
Merging pull request #18739
* new actions * pnpm-lock.yaml * pnpm-lock.yaml
1 parent 3633d06 commit 69015ba

File tree

12 files changed

+1025
-7
lines changed

12 files changed

+1025
-7
lines changed
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
import unleashedSoftware from "../../unleashed_software.app.mjs";
2+
3+
export default {
4+
key: "unleashed_software-create-purchase-order",
5+
name: "Create Purchase Order",
6+
description: "Create a purchase order. [See the documentation](https://apidocs.unleashedsoftware.com/Purchases)",
7+
version: "0.0.1",
8+
type: "action",
9+
annotations: {
10+
destructiveHint: false,
11+
openWorldHint: true,
12+
readOnlyHint: false,
13+
},
14+
props: {
15+
unleashedSoftware,
16+
orderStatus: {
17+
propDefinition: [
18+
unleashedSoftware,
19+
"purchaseOrderStatus",
20+
],
21+
},
22+
supplierId: {
23+
propDefinition: [
24+
unleashedSoftware,
25+
"supplierId",
26+
],
27+
},
28+
taxCode: {
29+
propDefinition: [
30+
unleashedSoftware,
31+
"taxCode",
32+
],
33+
},
34+
warehouseId: {
35+
propDefinition: [
36+
unleashedSoftware,
37+
"warehouseId",
38+
],
39+
optional: true,
40+
},
41+
exchangeRate: {
42+
propDefinition: [
43+
unleashedSoftware,
44+
"exchangeRate",
45+
],
46+
optional: true,
47+
},
48+
comments: {
49+
propDefinition: [
50+
unleashedSoftware,
51+
"comments",
52+
],
53+
},
54+
numLineItems: {
55+
type: "integer",
56+
label: "Number of Line Items",
57+
description: "The number of line items to enter",
58+
reloadProps: true,
59+
},
60+
},
61+
async additionalProps() {
62+
const props = {};
63+
if (!this.numLineItems) {
64+
return props;
65+
}
66+
for (let i = 1; i <= this.numLineItems; i++) {
67+
props[`line_${i}_productId`] = {
68+
type: "string",
69+
label: `Line Item ${i} - Product ID`,
70+
options: async ({ page }) => {
71+
const { Items: products } = await this.unleashedSoftware.listProducts({
72+
page: page + 1,
73+
});
74+
return products?.map(({
75+
Guid: value, ProductDescription: label,
76+
}) => ({
77+
value,
78+
label,
79+
})) || [];
80+
},
81+
};
82+
props[`line_${i}_quantity`] = {
83+
type: "string",
84+
label: `Line Item ${i} - Quantity`,
85+
};
86+
props[`line_${i}_unitPrice`] = {
87+
type: "string",
88+
label: `Line Item ${i} - Unit Price`,
89+
};
90+
}
91+
return props;
92+
},
93+
async run({ $ }) {
94+
const lineItems = [];
95+
let subtotal = 0, taxTotal = 0;
96+
const taxRate = await this.unleashedSoftware.getTaxRateFromCode({
97+
$,
98+
taxCode: this.taxCode,
99+
});
100+
101+
for (let i = 1; i <= this.numLineItems; i++) {
102+
const lineTotal = +this[`line_${i}_unitPrice`] * +this[`line_${i}_quantity`];
103+
const lineTax = lineTotal * (taxRate / 100);
104+
lineItems.push({
105+
Product: {
106+
Guid: this[`line_${i}_productId`],
107+
},
108+
OrderQuantity: +this[`line_${i}_quantity`],
109+
UnitPrice: +this[`line_${i}_unitPrice`],
110+
LineTotal: lineTotal,
111+
LineTax: lineTax,
112+
LineNumber: i,
113+
});
114+
subtotal += lineTotal;
115+
taxTotal += lineTax;
116+
}
117+
const response = await this.unleashedSoftware.createPurchaseOrder({
118+
$,
119+
data: {
120+
Supplier: {
121+
Guid: this.supplierId,
122+
},
123+
ExchangeRate: +this.exchangeRate,
124+
OrderStatus: this.orderStatus,
125+
Warehouse: {
126+
Guid: this.warehouseId,
127+
},
128+
Comments: this.comments,
129+
Subtotal: subtotal,
130+
Tax: {
131+
TaxCode: this.taxCode,
132+
},
133+
TaxRate: taxRate,
134+
TaxTotal: taxTotal,
135+
Total: subtotal + taxTotal,
136+
PurchaseOrderLines: lineItems,
137+
},
138+
});
139+
140+
$.export("$summary", "Successfully created purchase order");
141+
return response;
142+
},
143+
};
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
import unleashedSoftware from "../../unleashed_software.app.mjs";
2+
3+
export default {
4+
key: "unleashed_software-create-sales-order",
5+
name: "Create Sales Order",
6+
description: "Creates a new sales order. [See the documentation](https://apidocs.unleashedsoftware.com/SalesOrders)",
7+
version: "0.0.1",
8+
type: "action",
9+
annotations: {
10+
destructiveHint: false,
11+
openWorldHint: true,
12+
readOnlyHint: false,
13+
},
14+
props: {
15+
unleashedSoftware,
16+
customerId: {
17+
propDefinition: [
18+
unleashedSoftware,
19+
"customerId",
20+
],
21+
},
22+
exchangeRate: {
23+
propDefinition: [
24+
unleashedSoftware,
25+
"exchangeRate",
26+
],
27+
},
28+
orderStatus: {
29+
propDefinition: [
30+
unleashedSoftware,
31+
"salesOrderStatus",
32+
],
33+
},
34+
warehouseId: {
35+
propDefinition: [
36+
unleashedSoftware,
37+
"warehouseId",
38+
],
39+
},
40+
taxCode: {
41+
propDefinition: [
42+
unleashedSoftware,
43+
"taxCode",
44+
],
45+
},
46+
comments: {
47+
propDefinition: [
48+
unleashedSoftware,
49+
"comments",
50+
],
51+
},
52+
numLineItems: {
53+
type: "integer",
54+
label: "Number of Line Items",
55+
description: "The number of line items to enter",
56+
reloadProps: true,
57+
},
58+
},
59+
async additionalProps() {
60+
const props = {};
61+
if (!this.numLineItems) {
62+
return props;
63+
}
64+
for (let i = 1; i <= this.numLineItems; i++) {
65+
props[`line_${i}_productId`] = {
66+
type: "string",
67+
label: `Line Item ${i} - Product ID`,
68+
options: async ({ page }) => {
69+
const { Items: products } = await this.unleashedSoftware.listProducts({
70+
page: page + 1,
71+
});
72+
return products?.map(({
73+
Guid: value, ProductDescription: label,
74+
}) => ({
75+
value,
76+
label,
77+
})) || [];
78+
},
79+
};
80+
props[`line_${i}_quantity`] = {
81+
type: "string",
82+
label: `Line Item ${i} - Quantity`,
83+
};
84+
props[`line_${i}_unitPrice`] = {
85+
type: "string",
86+
label: `Line Item ${i} - Unit Price`,
87+
};
88+
}
89+
return props;
90+
},
91+
async run({ $ }) {
92+
const lineItems = [];
93+
let subtotal = 0, taxTotal = 0;
94+
const taxRate = await this.unleashedSoftware.getTaxRateFromCode({
95+
$,
96+
taxCode: this.taxCode,
97+
});
98+
99+
for (let i = 1; i <= this.numLineItems; i++) {
100+
const lineTotal = +this[`line_${i}_unitPrice`] * +this[`line_${i}_quantity`];
101+
const lineTax = lineTotal * (taxRate / 100);
102+
lineItems.push({
103+
Product: {
104+
Guid: this[`line_${i}_productId`],
105+
},
106+
OrderQuantity: +this[`line_${i}_quantity`],
107+
UnitPrice: +this[`line_${i}_unitPrice`],
108+
LineTotal: lineTotal,
109+
LineTax: lineTax,
110+
LineNumber: i,
111+
});
112+
subtotal += lineTotal;
113+
taxTotal += lineTax;
114+
}
115+
const response = await this.unleashedSoftware.createSalesOrder({
116+
$,
117+
data: {
118+
Customer: {
119+
Guid: this.customerId,
120+
},
121+
ExchangeRate: +this.exchangeRate,
122+
OrderStatus: this.orderStatus,
123+
Warehouse: {
124+
Guid: this.warehouseId,
125+
},
126+
Comments: this.comments,
127+
Subtotal: subtotal,
128+
Tax: {
129+
TaxCode: this.taxCode,
130+
},
131+
TaxRate: taxRate,
132+
TaxTotal: taxTotal,
133+
Total: subtotal + taxTotal,
134+
SalesOrderLines: lineItems,
135+
},
136+
});
137+
138+
$.export("$summary", "Successfully created sales order");
139+
return response;
140+
},
141+
};
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import unleashedSoftware from "../../unleashed_software.app.mjs";
2+
3+
export default {
4+
key: "unleashed_software-create-stock-adjustment",
5+
name: "Create Stock Adjustment",
6+
description: "Create a stock adjustment. [See the documentation](https://apidocs.unleashedsoftware.com/StockAdjustments)",
7+
version: "0.0.1",
8+
type: "action",
9+
annotations: {
10+
destructiveHint: false,
11+
openWorldHint: true,
12+
readOnlyHint: false,
13+
},
14+
props: {
15+
unleashedSoftware,
16+
adjustmentReason: {
17+
type: "string",
18+
label: "Adjustment Reason",
19+
description: "The reason for the stock adjustment",
20+
options: [
21+
"End of Season",
22+
"Samples",
23+
"Stolen",
24+
],
25+
},
26+
warehouseId: {
27+
propDefinition: [
28+
unleashedSoftware,
29+
"warehouseId",
30+
],
31+
},
32+
productId: {
33+
propDefinition: [
34+
unleashedSoftware,
35+
"productId",
36+
],
37+
},
38+
newQuantity: {
39+
type: "string",
40+
label: "New Quantity",
41+
description: "The new quantity of the product",
42+
},
43+
newActualValue: {
44+
type: "string",
45+
label: "New Actual Value",
46+
description: "The new actual value of the product",
47+
},
48+
},
49+
async run({ $ }) {
50+
const response = await this.unleashedSoftware.createStockAdjustment({
51+
$,
52+
data: {
53+
AdjustmentReason: this.adjustmentReason,
54+
Warehouse: {
55+
Guid: this.warehouseId,
56+
},
57+
StockAdjustmentLines: [
58+
{
59+
Product: {
60+
Guid: this.productId,
61+
},
62+
NewQuantity: +this.newQuantity,
63+
NewActualValue: +this.newActualValue,
64+
},
65+
],
66+
},
67+
});
68+
69+
$.export("$summary", "Successfully created stock adjustment");
70+
return response;
71+
},
72+
};

0 commit comments

Comments
 (0)