Skip to content

Commit b1911be

Browse files
committed
create-purchase-order updates
1 parent 34a9c2b commit b1911be

File tree

3 files changed

+28
-51
lines changed

3 files changed

+28
-51
lines changed

components/quickbooks/actions/create-purchase-order/create-purchase-order.mjs

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,22 @@ export default {
1414
props: {
1515
quickbooks,
1616
accountId: {
17-
propDefinition: [
18-
quickbooks,
19-
"accountIds",
20-
],
2117
type: "string",
2218
label: "Account ID",
2319
description: "The ID of the account to use for the purchase order",
20+
async options() {
21+
const { QueryResponse: queryResponse } = await this.quickbooks.query({
22+
params: {
23+
query: "select * from Account where Classification = 'Liability' AND AccountSubType = 'AccountsPayable'",
24+
},
25+
});
26+
return queryResponse.Account.map(({
27+
Id, Name,
28+
}) => ({
29+
value: Id,
30+
label: Name,
31+
}));
32+
},
2433
},
2534
vendorRefValue: {
2635
propDefinition: [
@@ -102,7 +111,7 @@ export default {
102111
props.lineItems = {
103112
type: "string[]",
104113
label: "Line Items",
105-
description: "Line items of a purchase order. Set DetailType to `ItemBasedExpenseLineDetail` or `AccountBasedExpenseLineDetail`. Example: `{ \"DetailType\": \"ItemBasedExpenseLineDetail\", \"Amount\": 100.0, \"ItemBasedExpenseLineDetail\": { \"ItemRef\": { \"name\": \"Services\", \"value\": \"1\" } } }` [See the documentation](https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/purchaseorder#create-a-purchaseorder) for more information.",
114+
description: "Line items of a purchase order. DetailType is `ItemBasedExpenseLineDetail`. Example: `{ \"DetailType\": \"ItemBasedExpenseLineDetail\", \"Amount\": 100.0, \"ItemBasedExpenseLineDetail\": { \"ItemRef\": { \"name\": \"Services\", \"value\": \"1\" } } }` [See the documentation](https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/purchaseorder#create-a-purchaseorder) for more information.",
106115
};
107116
return props;
108117
}
@@ -116,35 +125,26 @@ export default {
116125
return props;
117126
}
118127
for (let i = 1; i <= this.numLineItems; i++) {
119-
props[`detailType_${i}`] = {
120-
type: "string",
121-
label: `Line ${i} - Detail Type`,
122-
options: [
123-
{
124-
label: "Item Based Expense",
125-
value: "ItemBasedExpenseLineDetail",
126-
},
127-
{
128-
label: "Account Based Expense",
129-
value: "AccountBasedExpenseLineDetail",
130-
},
131-
],
132-
default: "ItemBasedExpenseLineDetail",
133-
};
134128
props[`item_${i}`] = {
135129
type: "string",
136130
label: `Line ${i} - Item/Account ID`,
137131
options: async ({ page }) => {
138-
return this.quickbooks.getPropOptions({
132+
const options = await this.quickbooks.getPropOptions({
139133
page,
140134
resource: "Item",
141135
mapper: ({
142-
Id: value, Name: label,
143-
}) => ({
144-
value,
145-
label,
146-
}),
136+
Id: value, Name: label, ExpenseAccountRef,
137+
}) => {
138+
if (ExpenseAccountRef) {
139+
return {
140+
value,
141+
label,
142+
};
143+
}
144+
return null;
145+
},
147146
});
147+
return options.filter((option) => option !== null);
148148
},
149149
};
150150
props[`amount_${i}`] = {
@@ -180,12 +180,6 @@ export default {
180180
throw new ConfigurationError("No valid line items were provided.");
181181
}
182182

183-
lines.forEach((line, index) => {
184-
if (line.DetailType !== "ItemBasedExpenseLineDetail" && line.DetailType !== "AccountBasedExpenseLineDetail") {
185-
throw new ConfigurationError(`Line Item at index ${index + 1} has invalid DetailType '${line.DetailType}'. Must be 'ItemBasedExpenseLineDetail' or 'AccountBasedExpenseLineDetail'`);
186-
}
187-
});
188-
189183
const hasShippingAddress = this.shippingStreetAddress
190184
|| this.shippingCity
191185
|| this.shippingState

components/quickbooks/common/utils.mjs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -171,26 +171,9 @@ export function buildPurchaseLineItems(numLineItems, context) {
171171
throw new ConfigurationError(`Invalid amount values for: ${invalidAmounts.join(", ")}. Amounts must be valid numbers.`);
172172
}
173173

174-
// Validate detailType values if provided
175-
const validDetailTypes = [
176-
"ItemBasedExpenseLineDetail",
177-
"AccountBasedExpenseLineDetail",
178-
];
179-
const invalidDetailTypes = [];
180-
for (let i = 1; i <= numLineItems; i++) {
181-
const detailType = context[`detailType_${i}`];
182-
if (detailType && !validDetailTypes.includes(detailType)) {
183-
invalidDetailTypes.push(`detailType_${i}: ${detailType}`);
184-
}
185-
}
186-
187-
if (invalidDetailTypes.length > 0) {
188-
throw new ConfigurationError(`Invalid detailType values for: ${invalidDetailTypes.join(", ")}. Valid types are: ${validDetailTypes.join(", ")}`);
189-
}
190-
191174
const lineItems = [];
192175
for (let i = 1; i <= numLineItems; i++) {
193-
const detailType = context[`detailType_${i}`] || "ItemBasedExpenseLineDetail";
176+
const detailType = "ItemBasedExpenseLineDetail";
194177

195178
// Extract conditional logic into clear variables
196179
const isItemBased = detailType === "ItemBasedExpenseLineDetail";

components/quickbooks/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/quickbooks",
3-
"version": "0.6.0",
3+
"version": "0.6.1",
44
"description": "Pipedream Quickbooks Components",
55
"main": "quickbooks.app.mjs",
66
"keywords": [

0 commit comments

Comments
 (0)