mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-21 02:56:40 -08:00
⚡ Adjust quote params
This commit is contained in:
parent
e99e07faf3
commit
9f8921e48e
|
@ -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 } &
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.',
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue