From 9f8921e48ebc7bfd5a9ccd7d0852445d8c38930b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Sun, 9 May 2021 23:57:53 +0200 Subject: [PATCH] :zap: Adjust quote params --- .../nodes-base/nodes/Zoho/GenericFunctions.ts | 20 ++++--- .../nodes-base/nodes/Zoho/ZohoCrm.node.ts | 24 ++++---- .../Zoho/descriptions/QuoteDescription.ts | 56 ++++++++++++++----- 3 files changed, 65 insertions(+), 35 deletions(-) diff --git a/packages/nodes-base/nodes/Zoho/GenericFunctions.ts b/packages/nodes-base/nodes/Zoho/GenericFunctions.ts index 1ea285a92b..d8504a7930 100644 --- a/packages/nodes-base/nodes/Zoho/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Zoho/GenericFunctions.ts @@ -25,7 +25,7 @@ export async function zohoApiRequest( qs: IDataObject = {}, uri?: string, ) { - const { oauthTokenData: { api_domain: apiDomain } } = this.getCredentials('zohoOAuth2Api') as ZohoOAuth2ApiCredentials; + const { oauthTokenData: { api_domain } } = this.getCredentials('zohoOAuth2Api') as ZohoOAuth2ApiCredentials; const options: OptionsWithUri = { body: { @@ -35,7 +35,7 @@ export async function zohoApiRequest( }, method, qs, - uri: uri ?? `${apiDomain}/crm/v2${endpoint}`, + uri: uri ?? `${api_domain}/crm/v2${endpoint}`, json: true, }; @@ -95,16 +95,15 @@ export async function handleListing( body: IDataObject = {}, qs: IDataObject = {}, ) { - let responseData; - const returnAll = this.getNodeParameter('returnAll', 0) as boolean; if (returnAll) { return await zohoApiRequestAllItems.call(this, method, endpoint, body, qs); } + const responseData = await zohoApiRequestAllItems.call(this, method, endpoint, body, qs); const limit = this.getNodeParameter('limit', 0) as number; - responseData = await zohoApiRequestAllItems.call(this, method, endpoint, body, qs); + return responseData.slice(0, limit); } @@ -162,9 +161,10 @@ const adjustClosingDateField = adjustDateField('Closing_Date'); const adjustInvoiceDateField = adjustDateField('Invoice_Date'); const adjustDueDateField = adjustDateField('Due_Date'); const adjustPurchaseOrderDateField = adjustDateField('PO_Date'); +const adjustValidTillField = adjustDateField('Valid_Till'); /** - * Place an account name field's contents at the top level of the payload. + * Place an account field's subfields at the top level of the payload. */ const adjustAccountField = (allFields: AllFields) => { if (!allFields.Account) return allFields; @@ -205,7 +205,11 @@ export const adjustPurchaseOrderFields = flow( adjustPurchaseOrderDateField, ); -export const adjustQuoteFields = adjustInvoiceFields; +export const adjustQuoteFields = flow( + adjustBillingAddressFields, + adjustShippingAddressFields, + adjustValidTillField, +); export const adjustSalesOrderFields = adjustInvoiceFields; @@ -221,7 +225,7 @@ const omit = (keyToOmit: string, { [keyToOmit]: _, ...omittedPropObj }) => omitt type LocationType = 'Address' | 'Billing_Address' | 'Mailing_Address' | 'Shipping_Address' | 'Other_Address'; -type DateType = 'Date_of_Birth' | 'Closing_Date' | 'Due_Date' | 'Invoice_Date' | 'PO_Date'; +type DateType = 'Date_of_Birth' | 'Closing_Date' | 'Due_Date' | 'Invoice_Date' | 'PO_Date' | 'Valid_Till'; export type AllFields = { [Date in DateType]?: string } & diff --git a/packages/nodes-base/nodes/Zoho/ZohoCrm.node.ts b/packages/nodes-base/nodes/Zoho/ZohoCrm.node.ts index cf85bd5288..22776fa3af 100644 --- a/packages/nodes-base/nodes/Zoho/ZohoCrm.node.ts +++ b/packages/nodes-base/nodes/Zoho/ZohoCrm.node.ts @@ -60,7 +60,7 @@ export class ZohoCrm implements INodeType { description: 'Consume the Zoho API', defaults: { name: 'Zoho', - color: '\#CE2232', + color: '#CE2232', }, inputs: ['main'], outputs: ['main'], @@ -140,13 +140,13 @@ export class ZohoCrm implements INodeType { methods = { loadOptions: { async getProducts(this: ILoadOptionsFunctions) { - const responseData = await zohoApiRequestAllItems.call(this, 'GET', '/products') as LoadedProducts; - return responseData.map((p) => ({ name: p.Product_Name, value: p.id })); + const products = await zohoApiRequestAllItems.call(this, 'GET', '/products') as LoadedProducts; + return products.map((p) => ({ name: p.Product_Name, value: p.id })); }, async getVendors(this: ILoadOptionsFunctions) { - const responseData = await zohoApiRequestAllItems.call(this, 'GET', '/vendors') as LoadedVendors; - return responseData.map((v) => ({ name: v.Vendor_Name, value: v.id })); + const vendors = await zohoApiRequestAllItems.call(this, 'GET', '/vendors') as LoadedVendors; + return vendors.map((v) => ({ name: v.Vendor_Name, value: v.id })); }, }, }; @@ -637,19 +637,13 @@ export class ZohoCrm implements INodeType { // ---------------------------------------- const productDetails = this.getNodeParameter('Product_Details', i) as ProductDetails; - const vendorId = this.getNodeParameter('vendorId', i) as string; const body: IDataObject = { Product_Details: adjustProductDetails(productDetails), Subject: this.getNodeParameter('subject', i), - Vendor_Name: { id: vendorId }, + Vendor_Name: { id: this.getNodeParameter('vendorId', i) }, }; - // const body: IDataObject = { - // Subject: this.getNodeParameter('subject', i), - // Vendor_Name: this.getNodeParameter('vendorName', i), - // }; - const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; if (Object.keys(additionalFields).length) { @@ -722,9 +716,11 @@ export class ZohoCrm implements INodeType { // quote: create // ---------------------------------------- + const productDetails = this.getNodeParameter('Product_Details', i) as ProductDetails; + const body: IDataObject = { - Product_Details: this.getNodeParameter('Product_Details', i), - Subject: this.getNodeParameter('Subject', i), + Product_Details: adjustProductDetails(productDetails), + Subject: this.getNodeParameter('subject', i), }; const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; diff --git a/packages/nodes-base/nodes/Zoho/descriptions/QuoteDescription.ts b/packages/nodes-base/nodes/Zoho/descriptions/QuoteDescription.ts index 719fc8135e..69b20d0c59 100644 --- a/packages/nodes-base/nodes/Zoho/descriptions/QuoteDescription.ts +++ b/packages/nodes-base/nodes/Zoho/descriptions/QuoteDescription.ts @@ -70,6 +70,7 @@ export const quoteFields = [ }, }, }, + productDetails('quote', 'create'), { displayName: 'Additional Fields', name: 'additionalFields', @@ -91,7 +92,10 @@ export const quoteFields = [ displayName: 'Adjustment', name: 'Adjustment', type: 'number', - default: '', + default: 0, + typeOptions: { + minValue: 0, + }, description: 'Adjustment in the grand total, if any.', }, billingAddress, @@ -118,14 +122,20 @@ export const quoteFields = [ displayName: 'Exchange Rate', name: 'Exchange_Rate', type: 'number', - default: '', + default: 0, + typeOptions: { + minValue: 0, + }, description: 'Exchange rate of the default currency to the home currency.', }, { displayName: 'Grand Total', name: 'Grand_Total', type: 'number', - default: '', + default: 0, + typeOptions: { + minValue: 0, + }, description: 'Total amount for the product after deducting tax and discounts.', }, { @@ -139,14 +149,20 @@ export const quoteFields = [ displayName: 'Sub Total', name: 'Sub_Total', type: 'number', - default: '', + default: 0, + typeOptions: { + minValue: 0, + }, description: 'Total amount for the product excluding tax.', }, { displayName: 'Tax', name: 'Tax', type: 'number', - default: '', + default: 0, + typeOptions: { + minValue: 0, + }, description: 'Total amount as the sum of sales tax and value-added tax.', }, { @@ -166,7 +182,7 @@ export const quoteFields = [ { displayName: 'Valid Till', name: 'Valid_Till', - type: 'string', + type: 'dateTime', default: '', description: 'Date until when the quote is valid.', }, @@ -264,7 +280,10 @@ export const quoteFields = [ displayName: 'Adjustment', name: 'Adjustment', type: 'number', - default: '', + default: 0, + typeOptions: { + minValue: 0, + }, description: 'Adjustment in the grand total, if any.', }, billingAddress, @@ -291,17 +310,22 @@ export const quoteFields = [ displayName: 'Exchange Rate', name: 'Exchange_Rate', type: 'number', - default: '', + default: 0, + typeOptions: { + minValue: 0, + }, description: 'Exchange rate of the default currency to the home currency.', }, { displayName: 'Grand Total', name: 'Grand_Total', type: 'number', - default: '', + default: 0, + typeOptions: { + minValue: 0, + }, description: 'Total amount for the product after deducting tax and discounts.', }, - // productDetails, { displayName: 'Quote Stage', name: 'Quote_Stage', @@ -313,7 +337,10 @@ export const quoteFields = [ displayName: 'Sub Total', name: 'Sub_Total', type: 'number', - default: '', + default: 0, + typeOptions: { + minValue: 0, + }, description: 'Total amount for the product excluding tax.', }, { @@ -327,7 +354,10 @@ export const quoteFields = [ displayName: 'Tax', name: 'Tax', type: 'number', - default: '', + default: 0, + typeOptions: { + minValue: 0, + }, description: 'Tax amount as the sum of sales tax and value-added tax.', }, { @@ -347,7 +377,7 @@ export const quoteFields = [ { displayName: 'Valid Till', name: 'Valid_Till', - type: 'string', + type: 'dateTime', default: '', description: 'Date until when the quote is valid.', },