Skip to content

Commit 5d7c9a9

Browse files
committed
updates
1 parent 6d1a25f commit 5d7c9a9

File tree

14 files changed

+111
-124
lines changed

14 files changed

+111
-124
lines changed

components/quickbooks/actions/create-bill/create-bill.mjs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ConfigurationError } from "@pipedream/platform";
22
import quickbooks from "../../quickbooks.app.mjs";
3+
import { parseLineItems } from "../../common/utils.mjs";
34

45
export default {
56
key: "quickbooks-create-bill",
@@ -97,24 +98,14 @@ export default {
9798
throw new ConfigurationError("Must provide vendorRefValue, and lineItems parameters.");
9899
}
99100

100-
if (this.lineItemsAsObjects) {
101-
try {
102-
this.lineItems = this.lineItems.map((lineItem) => typeof lineItem === "string"
103-
? JSON.parse(lineItem)
104-
: lineItem);
105-
} catch (error) {
106-
throw new ConfigurationError(`We got an error trying to parse the LineItems. Error: ${error}`);
107-
}
108-
}
109-
110101
const response = await this.quickbooks.createBill({
111102
$,
112103
data: {
113104
VendorRef: {
114105
value: this.vendorRefValue,
115106
},
116107
Line: this.lineItemsAsObjects
117-
? this.lineItems
108+
? parseLineItems(this.lineItems)
118109
: this.buildLineItems(),
119110
CurrencyRef: {
120111
value: this.currencyRefValue,

components/quickbooks/actions/create-invoice/create-invoice.mjs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ConfigurationError } from "@pipedream/platform";
22
import quickbooks from "../../quickbooks.app.mjs";
3+
import { parseLineItems } from "../../common/utils.mjs";
34

45
export default {
56
key: "quickbooks-create-invoice",
@@ -94,21 +95,11 @@ export default {
9495
throw new ConfigurationError("Must provide lineItems, and customerRefValue parameters.");
9596
}
9697

97-
if (this.lineItemsAsObjects) {
98-
try {
99-
this.lineItems = this.lineItems.map((lineItem) => typeof lineItem === "string"
100-
? JSON.parse(lineItem)
101-
: lineItem);
102-
} catch (error) {
103-
throw new ConfigurationError(`We got an error trying to parse the LineItems. Error: ${error}`);
104-
}
105-
}
106-
10798
const response = await this.quickbooks.createInvoice({
10899
$,
109100
data: {
110101
Line: this.lineItemsAsObjects
111-
? this.lineItems
102+
? parseLineItems(this.lineItems)
112103
: this.buildLineItems(),
113104
CustomerRef: {
114105
value: this.customerRefValue,

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import quickbooks from "../../quickbooks.app.mjs";
2-
import { ConfigurationError } from "@pipedream/platform";
2+
import { parseLineItems } from "../../common/utils.mjs";
33

44
export default {
55
key: "quickbooks-create-purchase",
@@ -104,16 +104,6 @@ export default {
104104
},
105105
},
106106
async run({ $ }) {
107-
if (this.lineItemsAsObjects) {
108-
try {
109-
this.lineItems = this.lineItems.map((lineItem) => typeof lineItem === "string"
110-
? JSON.parse(lineItem)
111-
: lineItem);
112-
} catch (error) {
113-
throw new ConfigurationError(`We got an error trying to parse the LineItems. Error: ${error}`);
114-
}
115-
}
116-
117107
const response = await this.quickbooks.createPurchase({
118108
$,
119109
data: {
@@ -122,7 +112,7 @@ export default {
122112
value: this.accountRefValue,
123113
},
124114
Line: this.lineItemsAsObjects
125-
? this.lineItems
115+
? parseLineItems(this.lineItems)
126116
: this.buildLineItems(),
127117
CurrencyRef: {
128118
value: this.currencyRefValue,

components/quickbooks/actions/create-sales-receipt/create-sales-receipt.mjs

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { ConfigurationError } from "@pipedream/platform";
21
import quickbooks from "../../quickbooks.app.mjs";
2+
import { parseLineItems } from "../../common/utils.mjs";
33

44
export default {
55
key: "quickbooks-create-sales-receipt",
@@ -9,19 +9,19 @@ export default {
99
type: "action",
1010
props: {
1111
quickbooks,
12-
currencyRefValue: {
12+
lineItemsAsObjects: {
1313
propDefinition: [
1414
quickbooks,
15-
"currencyRefValue",
15+
"lineItemsAsObjects",
1616
],
17-
optional: true,
17+
reloadProps: true,
1818
},
19-
lineItemsAsObjects: {
19+
currencyRefValue: {
2020
propDefinition: [
2121
quickbooks,
22-
"lineItemsAsObjects",
22+
"currency",
2323
],
24-
reloadProps: true,
24+
optional: true,
2525
},
2626
},
2727
async additionalProps() {
@@ -85,21 +85,11 @@ export default {
8585
},
8686
},
8787
async run({ $ }) {
88-
if (this.lineItemsAsObjects) {
89-
try {
90-
this.lineItems = this.lineItems.map((lineItem) => typeof lineItem === "string"
91-
? JSON.parse(lineItem)
92-
: lineItem);
93-
} catch (error) {
94-
throw new ConfigurationError(`We got an error trying to parse the LineItems. Error: ${error}`);
95-
}
96-
}
97-
9888
const response = await this.quickbooks.createSalesReceipt({
9989
$,
10090
data: {
10191
Line: this.lineItemsAsObjects
102-
? this.lineItems
92+
? parseLineItems(this.lineItems)
10393
: this.buildLineItems(),
10494
CurrencyRef: this.currencyRefValue && {
10595
value: this.currencyRefValue,

components/quickbooks/actions/search-invoices/search-invoices.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export default {
55
key: "quickbooks-search-invoices",
66
name: "Search Invoices",
77
description: "Searches for invoices. [See the documentation](https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/invoice#query-an-invoice)",
8-
version: "0.1.7",
8+
version: "0.0.1",
99
type: "action",
1010
props: {
1111
quickbooks,

components/quickbooks/actions/search-query/search-query.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ export default {
3030
if (response) {
3131
$.export("summary", "Successfully retrieved query results");
3232
}
33+
return response;
3334
},
3435
};

components/quickbooks/actions/search-services/search-services.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default {
3636
},
3737
},
3838
async run({ $ }) {
39-
if (!this.where_clause) {
39+
if (!this.whereClause) {
4040
throw new ConfigurationError("Must provide whereClause parameter.");
4141
}
4242

components/quickbooks/actions/sparse-update-invoice/sparse-update-invoice.mjs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { ConfigurationError } from "@pipedream/platform";
2-
import { parseOne } from "../../common/utils.mjs";
1+
import { parseLineItems } from "../../common/utils.mjs";
32
import quickbooks from "../../quickbooks.app.mjs";
43

54
export default {
@@ -97,33 +96,35 @@ export default {
9796
},
9897
},
9998
async run({ $ }) {
100-
if (this.lineItemsAsObjects) {
101-
try {
102-
this.lineItems = this.lineItems.map((lineItem) => typeof lineItem === "string"
103-
? JSON.parse(lineItem)
104-
: lineItem);
105-
} catch (error) {
106-
throw new ConfigurationError(`We got an error trying to parse the LineItems. Error: ${error}`);
107-
}
108-
}
99+
this.lineItems = this.lineItemsAsObjects
100+
? parseLineItems(this.lineItems)
101+
: this.buildLineItems();
109102

110-
const { Invoice } = await this.quickbooks.getInvoice({
103+
const { Invoice: invoice } = await this.quickbooks.getInvoice({
111104
$,
112105
invoiceId: this.invoiceId,
113106
});
114107

115-
if (this.lineItems.length) Invoice.Line?.push(...this.lineItems);
116-
117-
Invoice.CurrencyRef = parseOne(this.currency);
118-
Invoice.CustomerRef = parseOne(this.customer);
108+
if (this.lineItems?.length) invoice.Line?.push(...this.lineItems);
119109

120110
const response = await this.quickbooks.sparseUpdateInvoice({
121111
$,
122-
data: Invoice,
112+
data: {
113+
sparse: true,
114+
Id: this.invoiceId,
115+
SyncToken: invoice.SyncToken,
116+
CurrencyRef: this.currencyRefValue && {
117+
value: this.currencyRefValue,
118+
},
119+
CustomerRef: {
120+
value: this.customer,
121+
},
122+
Line: invoice.Line,
123+
},
123124
});
124125

125126
if (response) {
126-
$.export("summary", `Successfully updated invoice with Id ${response.Invoice.Id}`);
127+
$.export("summary", `Successfully updated invoice with ID ${response.Invoice.Id}`);
127128
}
128129

129130
return response;

components/quickbooks/actions/update-customer/update-customer.mjs

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export default {
6161
description: "If true, this entity is currently enabled for use by QuickBooks. If there is an amount in `Customer.Balance` when setting this Customer object to inactive through the QuickBooks UI, a CreditMemo balancing transaction is created for the amount.",
6262
label: "Active",
6363
optional: true,
64-
type: "string",
64+
type: "boolean",
6565
},
6666
alternatePhoneFreeFormNumber: {
6767
description: "Specifies the alternate phone number in free form.",
@@ -201,12 +201,6 @@ export default {
201201
],
202202
type: "string",
203203
},
204-
isProject: {
205-
description: "If true, indicates this is a Project.",
206-
label: "Is Project",
207-
optional: true,
208-
type: "boolean",
209-
},
210204
job: {
211205
description: "If true, this is a Job or sub-customer. If false or null, this is a top level customer, not a Job or sub-customer.",
212206
label: "Job",
@@ -362,7 +356,7 @@ export default {
362356
description: "If true, transactions for this customer are taxable. Default behavior with minor version 10 and above: true, if `DefaultTaxCodeRef` is defined or false if `TaxExemptionReasonId` is set.",
363357
label: "Taxable",
364358
optional: true,
365-
type: "string",
359+
type: "boolean",
366360
},
367361
taxExemptionReasonId: {
368362
label: "Tax Exemption Reason Id",
@@ -412,6 +406,31 @@ export default {
412406
throw new ConfigurationError("Must provide displayName or at least one of title, givenName, middleName, familyName, or suffix, and customerId parameters.");
413407
}
414408

409+
const hasBillingAddress = this.billAddrPostalCode
410+
|| this.billAddrCity
411+
|| this.billAddrCountry
412+
|| this.billAddrLine5
413+
|| this.billAddrLine4
414+
|| this.billAddrLine3
415+
|| this.billAddrLine2
416+
|| this.billAddrLine1
417+
|| this.billAddrLate
418+
|| this.billAddrLong
419+
|| this.billAddrCountrySubDivisionCode;
420+
421+
const hasShippingAddress = this.shipAddrId
422+
|| this.shipAddrPostalCode
423+
|| this.shipAddrCity
424+
|| this.shipAddrCountry
425+
|| this.shipAddrLine5
426+
|| this.shipAddrLine4
427+
|| this.shipAddrLine3
428+
|| this.shipAddrLine2
429+
|| this.shipAddrLine1
430+
|| this.shipAddrLate
431+
|| this.shipAddrLong
432+
|| this.shipAddrCountrySubDivisionCode;
433+
415434
const response = await this.quickbooks.updateCustomer({
416435
$,
417436
data: {
@@ -424,46 +443,48 @@ export default {
424443
FamilyName: this.familyName,
425444
GivenName: this.givenName,
426445
SyncToken: await this.getSyncToken($),
427-
PrimaryEmailAddr: this.primaryEmailAddr,
446+
PrimaryEmailAddr: this.primaryEmailAddr && {
447+
Address: this.primaryEmailAddr,
448+
},
428449
ResaleNum: this.resaleNum,
429450
SecondaryTaxIdentifier: this.secondaryTaxIdentifier,
430-
ARAccountRef: {
451+
ARAccountRef: this.arAccountRefValue && {
431452
value: this.arAccountRefValue,
432453
},
433-
DefaultTaxCodeRef: {
454+
DefaultTaxCodeRef: this.defaultTaxCodeValue && {
434455
value: this.defaultTaxCodeValue,
435456
},
436457
PreferredDeliveryMethod: this.preferredDeliveryMethod,
437458
GSTIN: this.GSTIN,
438-
SalesTermRef: {
459+
SalesTermRef: this.saleTermRefValue && {
439460
value: this.saleTermRefValue,
440461
},
441-
CustomerTypeRef: {
442-
value: this.customerRypeRefValue,
462+
CustomerTypeRef: this.customerTypeRefValue && {
463+
value: this.customerTypeRefValue,
443464
},
444-
Fax: {
465+
Fax: this.faxFreeFormNumber && {
445466
FreeFormNumber: this.faxFreeFormNumber,
446467
},
447468
BusinessNumber: this.businessNumber,
448469
BillWithParent: this.billWithParent,
449-
CurrencyRef: {
470+
CurrencyRef: this.currencyRefValue && {
450471
value: this.currencyRefValue,
451472
},
452-
Mobile: {
473+
Mobile: this.mobileFreeFormNumber && {
453474
FreeFormNumber: this.mobileFreeFormNumber,
454475
},
455476
Job: this.job,
456-
PrimaryPhone: {
477+
PrimaryPhone: this.primaryPhoneFreeFormNumber && {
457478
FreeFormNumber: this.primaryPhoneFreeFormNumber,
458479
},
459480
Taxable: this.taxable,
460-
AlternatePhone: {
481+
AlternatePhone: this.alternatePhoneFreeFormNumber && {
461482
FreeFormNumber: this.alternatePhoneFreeFormNumber,
462483
},
463484
Notes: this.notes,
464485
WebAddr: this.webAddr,
465486
Active: this.active,
466-
ShipAddr: {
487+
ShipAddr: hasShippingAddress && {
467488
Id: this.shipAddrId,
468489
PostalCode: this.shipAddrPostalCode,
469490
City: this.shipAddrCity,
@@ -477,15 +498,14 @@ export default {
477498
Long: this.shipAddrLong,
478499
CountrySubDivisionCode: this.shipAddrCountrySubDivisionCode,
479500
},
480-
PaymentMethodRef: {
501+
PaymentMethodRef: this.paymentMethodRefValue && {
481502
value: this.paymentMethodRefValue,
482503
},
483-
IsProject: this.isProject,
484504
CompanyName: this.companyName,
485505
PrimaryTaxIdentifier: this.primaryTaxIdentifier,
486506
GSTRegistrationType: this.gstRegistrationType,
487507
PrintOnCheckName: this.printOnCheckName,
488-
BillAddr: {
508+
BillAddr: hasBillingAddress && {
489509
PostalCode: this.billAddrPostalCode,
490510
City: this.billAddrCity,
491511
Country: this.billAddrCountry,

0 commit comments

Comments
 (0)