Adjust quote params

This commit is contained in:
Iván Ovejero 2021-05-09 23:57:53 +02:00
parent e99e07faf3
commit 9f8921e48e
3 changed files with 65 additions and 35 deletions

View file

@ -25,7 +25,7 @@ export async function zohoApiRequest(
qs: IDataObject = {}, qs: IDataObject = {},
uri?: string, uri?: string,
) { ) {
const { oauthTokenData: { api_domain: apiDomain } } = this.getCredentials('zohoOAuth2Api') as ZohoOAuth2ApiCredentials; const { oauthTokenData: { api_domain } } = this.getCredentials('zohoOAuth2Api') as ZohoOAuth2ApiCredentials;
const options: OptionsWithUri = { const options: OptionsWithUri = {
body: { body: {
@ -35,7 +35,7 @@ export async function zohoApiRequest(
}, },
method, method,
qs, qs,
uri: uri ?? `${apiDomain}/crm/v2${endpoint}`, uri: uri ?? `${api_domain}/crm/v2${endpoint}`,
json: true, json: true,
}; };
@ -95,16 +95,15 @@ export async function handleListing(
body: IDataObject = {}, body: IDataObject = {},
qs: IDataObject = {}, qs: IDataObject = {},
) { ) {
let responseData;
const returnAll = this.getNodeParameter('returnAll', 0) as boolean; const returnAll = this.getNodeParameter('returnAll', 0) as boolean;
if (returnAll) { if (returnAll) {
return await zohoApiRequestAllItems.call(this, method, endpoint, body, qs); 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; const limit = this.getNodeParameter('limit', 0) as number;
responseData = await zohoApiRequestAllItems.call(this, method, endpoint, body, qs);
return responseData.slice(0, limit); return responseData.slice(0, limit);
} }
@ -162,9 +161,10 @@ const adjustClosingDateField = adjustDateField('Closing_Date');
const adjustInvoiceDateField = adjustDateField('Invoice_Date'); const adjustInvoiceDateField = adjustDateField('Invoice_Date');
const adjustDueDateField = adjustDateField('Due_Date'); const adjustDueDateField = adjustDateField('Due_Date');
const adjustPurchaseOrderDateField = adjustDateField('PO_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) => { const adjustAccountField = (allFields: AllFields) => {
if (!allFields.Account) return allFields; if (!allFields.Account) return allFields;
@ -205,7 +205,11 @@ export const adjustPurchaseOrderFields = flow(
adjustPurchaseOrderDateField, adjustPurchaseOrderDateField,
); );
export const adjustQuoteFields = adjustInvoiceFields; export const adjustQuoteFields = flow(
adjustBillingAddressFields,
adjustShippingAddressFields,
adjustValidTillField,
);
export const adjustSalesOrderFields = adjustInvoiceFields; 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 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 = export type AllFields =
{ [Date in DateType]?: string } & { [Date in DateType]?: string } &

View file

@ -60,7 +60,7 @@ export class ZohoCrm implements INodeType {
description: 'Consume the Zoho API', description: 'Consume the Zoho API',
defaults: { defaults: {
name: 'Zoho', name: 'Zoho',
color: '\#CE2232', color: '#CE2232',
}, },
inputs: ['main'], inputs: ['main'],
outputs: ['main'], outputs: ['main'],
@ -140,13 +140,13 @@ export class ZohoCrm implements INodeType {
methods = { methods = {
loadOptions: { loadOptions: {
async getProducts(this: ILoadOptionsFunctions) { async getProducts(this: ILoadOptionsFunctions) {
const responseData = await zohoApiRequestAllItems.call(this, 'GET', '/products') as LoadedProducts; const products = await zohoApiRequestAllItems.call(this, 'GET', '/products') as LoadedProducts;
return responseData.map((p) => ({ name: p.Product_Name, value: p.id })); return products.map((p) => ({ name: p.Product_Name, value: p.id }));
}, },
async getVendors(this: ILoadOptionsFunctions) { async getVendors(this: ILoadOptionsFunctions) {
const responseData = await zohoApiRequestAllItems.call(this, 'GET', '/vendors') as LoadedVendors; const vendors = await zohoApiRequestAllItems.call(this, 'GET', '/vendors') as LoadedVendors;
return responseData.map((v) => ({ name: v.Vendor_Name, value: v.id })); 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 productDetails = this.getNodeParameter('Product_Details', i) as ProductDetails;
const vendorId = this.getNodeParameter('vendorId', i) as string;
const body: IDataObject = { const body: IDataObject = {
Product_Details: adjustProductDetails(productDetails), Product_Details: adjustProductDetails(productDetails),
Subject: this.getNodeParameter('subject', i), 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; const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
if (Object.keys(additionalFields).length) { if (Object.keys(additionalFields).length) {
@ -722,9 +716,11 @@ export class ZohoCrm implements INodeType {
// quote: create // quote: create
// ---------------------------------------- // ----------------------------------------
const productDetails = this.getNodeParameter('Product_Details', i) as ProductDetails;
const body: IDataObject = { const body: IDataObject = {
Product_Details: this.getNodeParameter('Product_Details', i), Product_Details: adjustProductDetails(productDetails),
Subject: this.getNodeParameter('Subject', i), Subject: this.getNodeParameter('subject', i),
}; };
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;

View file

@ -70,6 +70,7 @@ export const quoteFields = [
}, },
}, },
}, },
productDetails('quote', 'create'),
{ {
displayName: 'Additional Fields', displayName: 'Additional Fields',
name: 'additionalFields', name: 'additionalFields',
@ -91,7 +92,10 @@ export const quoteFields = [
displayName: 'Adjustment', displayName: 'Adjustment',
name: 'Adjustment', name: 'Adjustment',
type: 'number', type: 'number',
default: '', default: 0,
typeOptions: {
minValue: 0,
},
description: 'Adjustment in the grand total, if any.', description: 'Adjustment in the grand total, if any.',
}, },
billingAddress, billingAddress,
@ -118,14 +122,20 @@ export const quoteFields = [
displayName: 'Exchange Rate', displayName: 'Exchange Rate',
name: 'Exchange_Rate', name: 'Exchange_Rate',
type: 'number', type: 'number',
default: '', default: 0,
typeOptions: {
minValue: 0,
},
description: 'Exchange rate of the default currency to the home currency.', description: 'Exchange rate of the default currency to the home currency.',
}, },
{ {
displayName: 'Grand Total', displayName: 'Grand Total',
name: 'Grand_Total', name: 'Grand_Total',
type: 'number', type: 'number',
default: '', default: 0,
typeOptions: {
minValue: 0,
},
description: 'Total amount for the product after deducting tax and discounts.', description: 'Total amount for the product after deducting tax and discounts.',
}, },
{ {
@ -139,14 +149,20 @@ export const quoteFields = [
displayName: 'Sub Total', displayName: 'Sub Total',
name: 'Sub_Total', name: 'Sub_Total',
type: 'number', type: 'number',
default: '', default: 0,
typeOptions: {
minValue: 0,
},
description: 'Total amount for the product excluding tax.', description: 'Total amount for the product excluding tax.',
}, },
{ {
displayName: 'Tax', displayName: 'Tax',
name: 'Tax', name: 'Tax',
type: 'number', type: 'number',
default: '', default: 0,
typeOptions: {
minValue: 0,
},
description: 'Total amount as the sum of sales tax and value-added tax.', description: 'Total amount as the sum of sales tax and value-added tax.',
}, },
{ {
@ -166,7 +182,7 @@ export const quoteFields = [
{ {
displayName: 'Valid Till', displayName: 'Valid Till',
name: 'Valid_Till', name: 'Valid_Till',
type: 'string', type: 'dateTime',
default: '', default: '',
description: 'Date until when the quote is valid.', description: 'Date until when the quote is valid.',
}, },
@ -264,7 +280,10 @@ export const quoteFields = [
displayName: 'Adjustment', displayName: 'Adjustment',
name: 'Adjustment', name: 'Adjustment',
type: 'number', type: 'number',
default: '', default: 0,
typeOptions: {
minValue: 0,
},
description: 'Adjustment in the grand total, if any.', description: 'Adjustment in the grand total, if any.',
}, },
billingAddress, billingAddress,
@ -291,17 +310,22 @@ export const quoteFields = [
displayName: 'Exchange Rate', displayName: 'Exchange Rate',
name: 'Exchange_Rate', name: 'Exchange_Rate',
type: 'number', type: 'number',
default: '', default: 0,
typeOptions: {
minValue: 0,
},
description: 'Exchange rate of the default currency to the home currency.', description: 'Exchange rate of the default currency to the home currency.',
}, },
{ {
displayName: 'Grand Total', displayName: 'Grand Total',
name: 'Grand_Total', name: 'Grand_Total',
type: 'number', type: 'number',
default: '', default: 0,
typeOptions: {
minValue: 0,
},
description: 'Total amount for the product after deducting tax and discounts.', description: 'Total amount for the product after deducting tax and discounts.',
}, },
// productDetails,
{ {
displayName: 'Quote Stage', displayName: 'Quote Stage',
name: 'Quote_Stage', name: 'Quote_Stage',
@ -313,7 +337,10 @@ export const quoteFields = [
displayName: 'Sub Total', displayName: 'Sub Total',
name: 'Sub_Total', name: 'Sub_Total',
type: 'number', type: 'number',
default: '', default: 0,
typeOptions: {
minValue: 0,
},
description: 'Total amount for the product excluding tax.', description: 'Total amount for the product excluding tax.',
}, },
{ {
@ -327,7 +354,10 @@ export const quoteFields = [
displayName: 'Tax', displayName: 'Tax',
name: 'Tax', name: 'Tax',
type: 'number', type: 'number',
default: '', default: 0,
typeOptions: {
minValue: 0,
},
description: 'Tax amount as the sum of sales tax and value-added tax.', description: 'Tax amount as the sum of sales tax and value-added tax.',
}, },
{ {
@ -347,7 +377,7 @@ export const quoteFields = [
{ {
displayName: 'Valid Till', displayName: 'Valid Till',
name: 'Valid_Till', name: 'Valid_Till',
type: 'string', type: 'dateTime',
default: '', default: '',
description: 'Date until when the quote is valid.', description: 'Date until when the quote is valid.',
}, },