Skip to content

Commit 88f157c

Browse files
committed
New actions and async options improvements
1 parent 123a9f0 commit 88f157c

File tree

5 files changed

+340
-81
lines changed

5 files changed

+340
-81
lines changed

components/sage_accounting/actions/create-contact/create-contact.mjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,10 @@ export default {
120120
defaultSalesLedgerAccountId: {
121121
propDefinition: [
122122
app,
123-
"defaultSalesLedgerAccountId",
123+
"ledgerAccountId",
124124
],
125+
label: "Default Sales Ledger Account ID",
126+
description: "The ID of the default sales ledger account for the contact",
125127
},
126128
defaultSalesTaxRateId: {
127129
propDefinition: [
@@ -132,8 +134,10 @@ export default {
132134
defaultPurchaseLedgerAccountId: {
133135
propDefinition: [
134136
app,
135-
"defaultPurchaseLedgerAccountId",
137+
"ledgerAccountId",
136138
],
139+
label: "Default Purchase Ledger Account ID",
140+
description: "The ID of the default purchase ledger account for the contact",
137141
},
138142
},
139143
async run({ $ }) {
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
import app from "../../sage_accounting.app.mjs";
2+
3+
export default {
4+
key: "sage_accounting-create-product",
5+
name: "Create Product",
6+
description: "Creates a new product in Sage Accounting. [See the documentation](https://developer.sage.com/accounting/reference/products/#tag/Products/operation/postProducts)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
description: {
12+
type: "string",
13+
label: "Description",
14+
description: "The product description",
15+
},
16+
salesLedgerAccountId: {
17+
propDefinition: [
18+
app,
19+
"ledgerAccountId",
20+
],
21+
label: "Sales Ledger Account ID",
22+
description: "The sales ledger account for the product",
23+
},
24+
purchaseLedgerAccountId: {
25+
propDefinition: [
26+
app,
27+
"ledgerAccountId",
28+
],
29+
label: "Purchase Ledger Account ID",
30+
description: "The purchase ledger account for the product",
31+
},
32+
itemCode: {
33+
type: "string",
34+
label: "Item Code",
35+
description: "The item code for the product",
36+
optional: true,
37+
},
38+
notes: {
39+
type: "string",
40+
label: "Notes",
41+
description: "The notes for the product",
42+
optional: true,
43+
},
44+
salesTaxRateId: {
45+
propDefinition: [
46+
app,
47+
"taxRateId",
48+
],
49+
label: "Sales Tax Rate ID",
50+
description: "The ID of the Sales Tax Rate",
51+
},
52+
usualSupplierId: {
53+
type: "string",
54+
label: "Usual Supplier ID",
55+
description: "The ID of the Usual Supplier",
56+
async options({ page }) {
57+
const suppliers = await this.app.listSuppliers({
58+
page,
59+
});
60+
return suppliers.map((supplier) => ({
61+
label: supplier.displayed_as,
62+
value: supplier.id,
63+
}));
64+
},
65+
optional: true,
66+
},
67+
purchaseTaxRateId: {
68+
propDefinition: [
69+
app,
70+
"taxRateId",
71+
],
72+
label: "Purchase Tax Rate ID",
73+
description: "The ID of the Purchase Tax Rate",
74+
},
75+
costPrice: {
76+
type: "string",
77+
label: "Cost Price",
78+
description: "The cost price of the product",
79+
optional: true,
80+
},
81+
sourceGuid: {
82+
type: "string",
83+
label: "Source GUID",
84+
description: "Used when importing products from external sources",
85+
optional: true,
86+
},
87+
purchaseDescription: {
88+
type: "string",
89+
label: "Purchase Description",
90+
description: "The product purchase description",
91+
optional: true,
92+
},
93+
active: {
94+
type: "boolean",
95+
label: "Active",
96+
description: "Indicates whether the product is active",
97+
optional: true,
98+
default: true,
99+
},
100+
catalogItemTypeId: {
101+
type: "string",
102+
label: "Catalog Item Type ID",
103+
description: "The ID of the Catalog Item Type",
104+
async options({ page }) {
105+
const catalogItemTypes = await this.app.listCatalogItemTypes({
106+
page,
107+
});
108+
return catalogItemTypes.map((type) => ({
109+
label: type.displayed_as,
110+
value: type.id,
111+
}));
112+
},
113+
optional: true,
114+
},
115+
},
116+
async run({ $ }) {
117+
118+
const response = await this.app.createProduct({
119+
$,
120+
data: {
121+
description: this.description,
122+
sales_ledger_account_id: this.salesLedgerAccountId,
123+
purchase_ledger_account_id: this.purchaseLedgerAccountId,
124+
item_code: this.itemCode,
125+
notes: this.notes,
126+
sales_tax_rate_id: this.salesTaxRateId,
127+
usual_supplier_id: this.usualSupplierId,
128+
purchase_tax_rate_id: this.purchaseTaxRateId,
129+
cost_price: this.costPrice,
130+
source_guid: this.sourceGuid,
131+
purchase_description: this.purchaseDescription,
132+
active: this.active,
133+
catalog_item_type_id: this.catalogItemTypeId,
134+
},
135+
});
136+
137+
$.export("$summary", `Successfully created product: ${response.description || response.displayed_as}`);
138+
return response;
139+
},
140+
};
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import app from "../../sage_accounting.app.mjs";
2+
3+
export default {
4+
key: "sage_accounting-get-ledger-accounts",
5+
name: "Get Ledger Accounts",
6+
description: "Retrieves a list of ledger accounts from Sage Accounting. [See the documentation](https://developer.sage.com/accounting/reference/accounting-setup/#tag/Ledger-Accounts/operation/getLedgerAccounts)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
app,
11+
itemsPerPage: {
12+
type: "integer",
13+
label: "Max Items",
14+
description: "Maximum number of items to return (1-200)",
15+
min: 1,
16+
max: 200,
17+
optional: true,
18+
default: 20,
19+
},
20+
page: {
21+
type: "integer",
22+
label: "Page",
23+
description: "Page number to retrieve (starts from 1)",
24+
min: 1,
25+
optional: true,
26+
default: 1,
27+
},
28+
},
29+
async run({ $ }) {
30+
const response = await this.app.listLedgerAccounts({
31+
$,
32+
page: this.page,
33+
params: {
34+
items_per_page: this.itemsPerPage,
35+
},
36+
});
37+
38+
const length = response.length;
39+
40+
$.export("$summary", `Successfully retrieved ${length} ledger account${length !== 1
41+
? "s"
42+
: ""}`);
43+
return response;
44+
},
45+
};

components/sage_accounting/actions/update-contact/update-contact.mjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ export default {
3838
defaultSalesLedgerAccountId: {
3939
propDefinition: [
4040
app,
41-
"defaultSalesLedgerAccountId",
41+
"ledgerAccountId",
4242
],
43+
label: "Default Sales Ledger Account ID",
44+
description: "The ID of the default sales ledger account for the contact",
4345
},
4446
defaultSalesTaxRateId: {
4547
propDefinition: [
@@ -50,8 +52,10 @@ export default {
5052
defaultPurchaseLedgerAccountId: {
5153
propDefinition: [
5254
app,
53-
"defaultPurchaseLedgerAccountId",
55+
"ledgerAccountId",
5456
],
57+
label: "Default Purchase Ledger Account ID",
58+
description: "The ID of the default purchase ledger account for the contact",
5559
},
5660
taxNumber: {
5761
propDefinition: [

0 commit comments

Comments
 (0)