Adjust sales orders params

This commit is contained in:
Iván Ovejero 2021-05-10 11:11:11 +02:00
parent 9f8921e48e
commit a61e5bb4d4
9 changed files with 278 additions and 278 deletions

View file

@ -17,6 +17,16 @@ import {
flow, flow,
} from 'lodash'; } from 'lodash';
import {
AllFields,
DateType,
IdType,
LocationType,
NameType,
ProductDetails,
ZohoOAuth2ApiCredentials,
} from './types';
export async function zohoApiRequest( export async function zohoApiRequest(
this: IExecuteFunctions | IHookFunctions | ILoadOptionsFunctions, this: IExecuteFunctions | IHookFunctions | ILoadOptionsFunctions,
method: string, method: string,
@ -25,7 +35,7 @@ export async function zohoApiRequest(
qs: IDataObject = {}, qs: IDataObject = {},
uri?: string, uri?: string,
) { ) {
const { oauthTokenData: { api_domain } } = this.getCredentials('zohoOAuth2Api') as ZohoOAuth2ApiCredentials; const { oauthTokenData } = this.getCredentials('zohoOAuth2Api') as ZohoOAuth2ApiCredentials;
const options: OptionsWithUri = { const options: OptionsWithUri = {
body: { body: {
@ -35,7 +45,7 @@ export async function zohoApiRequest(
}, },
method, method,
qs, qs,
uri: uri ?? `${api_domain}/crm/v2${endpoint}`, uri: uri ?? `${oauthTokenData.api_domain}/crm/v2${endpoint}`,
json: true, json: true,
}; };
@ -164,17 +174,23 @@ const adjustPurchaseOrderDateField = adjustDateField('PO_Date');
const adjustValidTillField = adjustDateField('Valid_Till'); const adjustValidTillField = adjustDateField('Valid_Till');
/** /**
* Place an account field's subfields at the top level of the payload. * Place an ID field's value nested inside the payload.
*/ */
const adjustAccountField = (allFields: AllFields) => { const adjustIdField = (idType: IdType, nameProperty: NameType) => (allFields: AllFields) => {
if (!allFields.Account) return allFields; const idValue = allFields[idType];
if (!idValue) return allFields;
return { return {
...omit('Account', allFields), ...omit(idType, allFields),
...allFields.Account.subfields, [nameProperty]: { id: idValue },
}; };
}; };
const adjustAccountIdField = adjustIdField('accountId', 'Account_Name');
const adjustContactIdField = adjustIdField('contactId', 'Full_Name');
const adjustDealIdField = adjustIdField('dealId', 'Deal_Name');
export const adjustAccountFields = flow( export const adjustAccountFields = flow(
adjustBillingAddressFields, adjustBillingAddressFields,
adjustShippingAddressFields, adjustShippingAddressFields,
@ -193,7 +209,7 @@ export const adjustInvoiceFields = flow(
adjustShippingAddressFields, adjustShippingAddressFields,
adjustInvoiceDateField, adjustInvoiceDateField,
adjustDueDateField, adjustDueDateField,
adjustAccountField, adjustAccountIdField,
); );
export const adjustLeadFields = adjustAddressFields; export const adjustLeadFields = adjustAddressFields;
@ -211,7 +227,14 @@ export const adjustQuoteFields = flow(
adjustValidTillField, adjustValidTillField,
); );
export const adjustSalesOrderFields = adjustInvoiceFields; export const adjustSalesOrderFields = flow(
adjustBillingAddressFields,
adjustShippingAddressFields,
adjustDueDateField,
adjustAccountIdField,
adjustContactIdField,
adjustDealIdField,
);
// ---------------------------------------- // ----------------------------------------
// helpers // helpers
@ -219,34 +242,5 @@ export const adjustSalesOrderFields = adjustInvoiceFields;
const omit = (keyToOmit: string, { [keyToOmit]: _, ...omittedPropObj }) => omittedPropObj; const omit = (keyToOmit: string, { [keyToOmit]: _, ...omittedPropObj }) => omittedPropObj;
// ---------------------------------------- export const toLoadOptions = (resourceItems: Array<{ [key: string]: string }>, nameProperty: NameType) =>
// types resourceItems.map((item) => ({ name: item[nameProperty], value: item.id }));
// ----------------------------------------
type LocationType = 'Address' | 'Billing_Address' | 'Mailing_Address' | 'Shipping_Address' | 'Other_Address';
type DateType = 'Date_of_Birth' | 'Closing_Date' | 'Due_Date' | 'Invoice_Date' | 'PO_Date' | 'Valid_Till';
export type AllFields =
{ [Date in DateType]?: string } &
{ [Location in LocationType]?: { address_fields: { [key: string]: string } } } &
{ Account?: { subfields: { id: string; name: string; } } } &
IDataObject;
export type ProductDetails = Array<{ id: string, quantity: number }>;
type ZohoOAuth2ApiCredentials = {
oauthTokenData: {
api_domain: string;
};
};
export type LoadedProducts = Array<{
Product_Name: string;
id: string;
}>;
export type LoadedVendors = Array<{
Vendor_Name: string;
id: string;
}>;

View file

@ -21,13 +21,20 @@ import {
adjustQuoteFields, adjustQuoteFields,
adjustSalesOrderFields, adjustSalesOrderFields,
handleListing, handleListing,
LoadedProducts, toLoadOptions,
LoadedVendors,
ProductDetails,
zohoApiRequest, zohoApiRequest,
zohoApiRequestAllItems, zohoApiRequestAllItems,
} from './GenericFunctions'; } from './GenericFunctions';
import {
LoadedAccounts,
LoadedContacts,
LoadedDeals,
LoadedProducts,
LoadedVendors,
ProductDetails,
} from './types';
import { import {
accountFields, accountFields,
accountOperations, accountOperations,
@ -139,14 +146,29 @@ export class ZohoCrm implements INodeType {
methods = { methods = {
loadOptions: { loadOptions: {
async getAccounts(this: ILoadOptionsFunctions) {
const accounts = await zohoApiRequestAllItems.call(this, 'GET', '/accounts') as LoadedAccounts;
return toLoadOptions(accounts, 'Account_Name');
},
async getContacts(this: ILoadOptionsFunctions) {
const contacts = await zohoApiRequestAllItems.call(this, 'GET', '/contacts') as LoadedContacts;
return toLoadOptions(contacts, 'Full_Name');
},
async getDeals(this: ILoadOptionsFunctions) {
const deals = await zohoApiRequestAllItems.call(this, 'GET', '/deals') as LoadedDeals;
return toLoadOptions(deals, 'Deal_Name');
},
async getProducts(this: ILoadOptionsFunctions) { async getProducts(this: ILoadOptionsFunctions) {
const products = await zohoApiRequestAllItems.call(this, 'GET', '/products') as LoadedProducts; const products = await zohoApiRequestAllItems.call(this, 'GET', '/products') as LoadedProducts;
return products.map((p) => ({ name: p.Product_Name, value: p.id })); return toLoadOptions(products, 'Product_Name');
}, },
async getVendors(this: ILoadOptionsFunctions) { async getVendors(this: ILoadOptionsFunctions) {
const vendors = await zohoApiRequestAllItems.call(this, 'GET', '/vendors') as LoadedVendors; const vendors = await zohoApiRequestAllItems.call(this, 'GET', '/vendors') as LoadedVendors;
return vendors.map((v) => ({ name: v.Vendor_Name, value: v.id })); return toLoadOptions(vendors, 'Vendor_Name');
}, },
}, },
}; };
@ -410,8 +432,8 @@ export class ZohoCrm implements INodeType {
const productDetails = this.getNodeParameter('Product_Details', i) as ProductDetails; const productDetails = this.getNodeParameter('Product_Details', i) as ProductDetails;
const body: IDataObject = { const body: IDataObject = {
Product_Details: adjustProductDetails(productDetails),
Subject: this.getNodeParameter('subject', i), Subject: this.getNodeParameter('subject', i),
Product_Details: adjustProductDetails(productDetails),
}; };
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
@ -639,9 +661,9 @@ export class ZohoCrm implements INodeType {
const productDetails = this.getNodeParameter('Product_Details', i) as ProductDetails; const productDetails = this.getNodeParameter('Product_Details', i) as ProductDetails;
const body: IDataObject = { const body: IDataObject = {
Product_Details: adjustProductDetails(productDetails),
Subject: this.getNodeParameter('subject', i), Subject: this.getNodeParameter('subject', i),
Vendor_Name: { id: this.getNodeParameter('vendorId', i) }, Vendor_Name: { id: this.getNodeParameter('vendorId', i) },
Product_Details: adjustProductDetails(productDetails),
}; };
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
@ -719,8 +741,8 @@ export class ZohoCrm implements INodeType {
const productDetails = this.getNodeParameter('Product_Details', i) as ProductDetails; const productDetails = this.getNodeParameter('Product_Details', i) as ProductDetails;
const body: IDataObject = { const body: IDataObject = {
Product_Details: adjustProductDetails(productDetails),
Subject: this.getNodeParameter('subject', i), Subject: this.getNodeParameter('subject', i),
Product_Details: adjustProductDetails(productDetails),
}; };
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
@ -792,9 +814,12 @@ export class ZohoCrm implements INodeType {
// salesOrder: create // salesOrder: create
// ---------------------------------------- // ----------------------------------------
const productDetails = this.getNodeParameter('Product_Details', i) as ProductDetails;
const body: IDataObject = { const body: IDataObject = {
Account_Name: this.getNodeParameter('Account_Name', i), Account_Name: { id: this.getNodeParameter('accountId', i) },
Subject: this.getNodeParameter('Subject', i), Subject: this.getNodeParameter('subject', i),
Product_Details: adjustProductDetails(productDetails),
}; };
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject; const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
@ -803,7 +828,7 @@ export class ZohoCrm implements INodeType {
Object.assign(body, adjustSalesOrderFields(additionalFields)); Object.assign(body, adjustSalesOrderFields(additionalFields));
} }
responseData = await zohoApiRequest.call(this, 'POST', '/salesorders', body); responseData = await zohoApiRequest.call(this, 'POST', '/sales_orders', body);
} else if (operation === 'delete') { } else if (operation === 'delete') {
@ -813,7 +838,7 @@ export class ZohoCrm implements INodeType {
const salesOrderId = this.getNodeParameter('salesOrderId', i); const salesOrderId = this.getNodeParameter('salesOrderId', i);
const endpoint = `/salesorders/${salesOrderId}`; const endpoint = `/sales_orders/${salesOrderId}`;
responseData = await zohoApiRequest.call(this, 'DELETE', endpoint); responseData = await zohoApiRequest.call(this, 'DELETE', endpoint);
} else if (operation === 'get') { } else if (operation === 'get') {
@ -824,7 +849,7 @@ export class ZohoCrm implements INodeType {
const salesOrderId = this.getNodeParameter('salesOrderId', i); const salesOrderId = this.getNodeParameter('salesOrderId', i);
const endpoint = `/salesorders/${salesOrderId}`; const endpoint = `/sales_orders/${salesOrderId}`;
responseData = await zohoApiRequest.call(this, 'GET', endpoint); responseData = await zohoApiRequest.call(this, 'GET', endpoint);
} else if (operation === 'getAll') { } else if (operation === 'getAll') {
@ -833,7 +858,7 @@ export class ZohoCrm implements INodeType {
// salesOrder: getAll // salesOrder: getAll
// ---------------------------------------- // ----------------------------------------
responseData = await handleListing.call(this, 'GET', '/salesorders'); responseData = await handleListing.call(this, 'GET', '/sales_orders');
} else if (operation === 'update') { } else if (operation === 'update') {
@ -850,7 +875,7 @@ export class ZohoCrm implements INodeType {
const salesOrderId = this.getNodeParameter('salesOrderId', i); const salesOrderId = this.getNodeParameter('salesOrderId', i);
const endpoint = `/salesorders/${salesOrderId}`; const endpoint = `/sales_orders/${salesOrderId}`;
responseData = await zohoApiRequest.call(this, 'PUT', endpoint, body); responseData = await zohoApiRequest.call(this, 'PUT', endpoint, body);
} }

View file

@ -5,7 +5,7 @@ import {
import { import {
billingAddress, billingAddress,
makeGetAllFields, makeGetAllFields,
productDetails, makeProductDetails,
shippingAddress, shippingAddress,
} from './SharedFields'; } from './SharedFields';
@ -70,7 +70,7 @@ export const invoiceFields = [
}, },
}, },
}, },
productDetails('invoice', 'create'), makeProductDetails('invoice', 'create'),
{ {
displayName: 'Additional Fields', displayName: 'Additional Fields',
name: 'additionalFields', name: 'additionalFields',
@ -89,32 +89,14 @@ export const invoiceFields = [
}, },
options: [ options: [
{ {
displayName: 'Account', displayName: 'Account ID',
name: 'Account', name: 'accountId',
type: 'fixedCollection', type: 'options',
description: 'Account who the invoice is issued for.', default: [],
default: {}, typeOptions: {
placeholder: 'Add Account Field', loadOptionsMethod: 'getAccounts',
options: [
{
displayName: 'Account Fields',
name: 'subfields',
values: [
{
displayName: 'ID',
name: 'id',
type: 'string',
default: '',
}, },
{ description: 'ID of the account associated with this invoice.',
displayName: 'Name',
name: 'name',
type: 'string',
default: '',
},
],
},
],
}, },
{ {
displayName: 'Adjustment', displayName: 'Adjustment',
@ -295,31 +277,14 @@ export const invoiceFields = [
}, },
options: [ options: [
{ {
displayName: 'Account', displayName: 'Account ID',
name: 'Account', name: 'accountId',
type: 'fixedCollection', type: 'options',
default: {}, default: [],
placeholder: 'Add Account Field', typeOptions: {
options: [ loadOptionsMethod: 'getAccounts',
{
displayName: 'Account Fields',
name: 'subfields',
values: [
{
displayName: 'ID',
name: 'id',
type: 'string',
default: '',
}, },
{ description: 'ID of the account associated with this invoice.',
displayName: 'Name',
name: 'name',
type: 'string',
default: '',
},
],
},
],
}, },
{ {
displayName: 'Adjustment', displayName: 'Adjustment',

View file

@ -136,6 +136,12 @@ export const leadFields = [
type: 'string', type: 'string',
default: '', default: '',
}, },
{
displayName: 'Email Opt Ou',
name: 'Email_Opt_Out',
type: 'boolean',
default: false,
},
{ {
displayName: 'Fax', displayName: 'Fax',
name: 'Fax', name: 'Fax',
@ -361,6 +367,12 @@ export const leadFields = [
type: 'string', type: 'string',
default: '', default: '',
}, },
{
displayName: 'Email Opt Ou',
name: 'Email_Opt_Out',
type: 'boolean',
default: false,
},
{ {
displayName: 'Fax', displayName: 'Fax',
name: 'Fax', name: 'Fax',

View file

@ -5,7 +5,7 @@ import {
import { import {
billingAddress, billingAddress,
makeGetAllFields, makeGetAllFields,
productDetails, makeProductDetails,
shippingAddress, shippingAddress,
} from './SharedFields'; } from './SharedFields';
@ -90,7 +90,7 @@ export const purchaseOrderFields = [
}, },
}, },
}, },
productDetails('purchaseOrder', 'create'), makeProductDetails('purchaseOrder', 'create'),
{ {
displayName: 'Additional Fields', displayName: 'Additional Fields',
name: 'additionalFields', name: 'additionalFields',

View file

@ -5,7 +5,7 @@ import {
import { import {
billingAddress, billingAddress,
makeGetAllFields, makeGetAllFields,
productDetails, makeProductDetails,
shippingAddress, shippingAddress,
} from './SharedFields'; } from './SharedFields';
@ -70,7 +70,7 @@ export const quoteFields = [
}, },
}, },
}, },
productDetails('quote', 'create'), makeProductDetails('quote', 'create'),
{ {
displayName: 'Additional Fields', displayName: 'Additional Fields',
name: 'additionalFields', name: 'additionalFields',

View file

@ -5,7 +5,7 @@ import {
import { import {
billingAddress, billingAddress,
makeGetAllFields, makeGetAllFields,
productDetails, makeProductDetails,
shippingAddress, shippingAddress,
} from './SharedFields'; } from './SharedFields';
@ -53,11 +53,14 @@ export const salesOrderFields = [
// salesOrder: create // salesOrder: create
// ---------------------------------------- // ----------------------------------------
{ {
displayName: 'Account Name', displayName: 'Account ID',
name: 'accountName', name: 'accountId',
type: '',
required: true, required: true,
default: '', type: 'options',
default: [],
typeOptions: {
loadOptionsMethod: 'getAccounts',
},
displayOptions: { displayOptions: {
show: { show: {
resource: [ resource: [
@ -87,6 +90,7 @@ export const salesOrderFields = [
}, },
}, },
}, },
makeProductDetails('salesOrder', 'create'),
{ {
displayName: 'Additional Fields', displayName: 'Additional Fields',
name: 'additionalFields', name: 'additionalFields',
@ -108,7 +112,10 @@ export const salesOrderFields = [
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,
@ -120,31 +127,13 @@ export const salesOrderFields = [
description: 'Name of the carrier.', description: 'Name of the carrier.',
}, },
{ {
displayName: 'Contact Name', displayName: 'Contact ID',
name: 'Contact_Name', name: 'contactId',
type: 'fixedCollection', type: 'options',
default: {}, default: [],
placeholder: 'Add Contact Name Field', typeOptions: {
options: [ loadOptionsMethod: 'getContacts',
{
displayName: 'Contact Name Fields',
name: 'contact_name_fields',
values: [
{
displayName: 'ID',
name: 'id',
type: 'string',
default: '',
}, },
{
displayName: 'Name',
name: 'name',
type: 'string',
default: '',
},
],
},
],
}, },
{ {
displayName: 'Currency', displayName: 'Currency',
@ -154,31 +143,13 @@ export const salesOrderFields = [
description: 'Symbol of the currency in which revenue is generated.', description: 'Symbol of the currency in which revenue is generated.',
}, },
{ {
displayName: 'Deal Name', displayName: 'Deal ID',
name: 'Deal_Name', name: 'dealId',
type: 'fixedCollection', type: 'options',
default: {}, default: [],
placeholder: 'Add Deal Name Field', typeOptions: {
options: [ loadOptionsMethod: 'getDeals',
{
displayName: 'Deal Name Fields',
name: 'deal_name_fields',
values: [
{
displayName: 'ID',
name: 'id',
type: 'string',
default: '',
}, },
{
displayName: 'Name',
name: 'name',
type: 'string',
default: '',
},
],
},
],
}, },
{ {
displayName: 'Description', displayName: 'Description',
@ -190,37 +161,39 @@ export const salesOrderFields = [
displayName: 'Discount', displayName: 'Discount',
name: 'Discount', name: 'Discount',
type: 'number', type: 'number',
default: '', default: 0,
typeOptions: {
minValue: 0,
},
}, },
{ {
displayName: 'Due Date', displayName: 'Due Date',
name: 'Due_Date', name: 'Due_Date',
type: 'string', type: 'dateTime',
default: '', default: '',
}, },
{ {
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: 'Purchase Order', displayName: 'Sales Order Number',
name: 'Purchase_Order',
type: 'string',
default: '',
},
{
displayName: 'SO Number',
name: 'SO_Number', name: 'SO_Number',
type: 'string', type: 'string',
default: '', default: '',
@ -229,8 +202,11 @@ export const salesOrderFields = [
{ {
displayName: 'Sales Commission', displayName: 'Sales Commission',
name: 'Sales_Commission', name: 'Sales_Commission',
type: 'string', type: 'number',
default: '', default: 0,
typeOptions: {
minValue: 0,
},
description: 'Commission of sales person on deal closure.', description: 'Commission of sales person on deal closure.',
}, },
shippingAddress, shippingAddress,
@ -245,14 +221,20 @@ export const salesOrderFields = [
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: '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.',
}, },
{ {
@ -291,7 +273,7 @@ export const salesOrderFields = [
// salesOrder: get // salesOrder: get
// ---------------------------------------- // ----------------------------------------
{ {
displayName: 'salesOrder ID', displayName: 'Sales Order ID',
name: 'salesOrderId', name: 'salesOrderId',
description: 'ID of the sales order to retrieve.', description: 'ID of the sales order to retrieve.',
type: 'string', type: 'string',
@ -353,37 +335,23 @@ export const salesOrderFields = [
}, },
options: [ options: [
{ {
displayName: 'Account Name', displayName: 'Account ID',
name: 'Account_Name', name: 'accountId',
type: 'fixedCollection', type: 'options',
default: {}, default: [],
placeholder: 'Add Account Name Field', typeOptions: {
options: [ loadOptionsMethod: 'getAccounts',
{
displayName: 'Account Name Fields',
name: 'account_name_fields',
values: [
{
displayName: 'ID',
name: 'id',
type: 'string',
default: '',
}, },
{ description: 'ID of the account associated with this invoice.',
displayName: 'Name',
name: 'name',
type: 'string',
default: '',
},
],
},
],
}, },
{ {
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,
@ -395,31 +363,13 @@ export const salesOrderFields = [
description: 'Name of the carrier.', description: 'Name of the carrier.',
}, },
{ {
displayName: 'Contact Name', displayName: 'Contact ID',
name: 'Contact_Name', name: 'contactId',
type: 'fixedCollection', type: 'options',
default: {}, default: [],
placeholder: 'Add Contact Name Field', typeOptions: {
options: [ loadOptionsMethod: 'getContacts',
{
displayName: 'Contact Name Fields',
name: 'contact_name_fields',
values: [
{
displayName: 'ID',
name: 'id',
type: 'string',
default: '',
}, },
{
displayName: 'Name',
name: 'name',
type: 'string',
default: '',
},
],
},
],
}, },
{ {
displayName: 'Currency', displayName: 'Currency',
@ -429,31 +379,13 @@ export const salesOrderFields = [
description: 'Symbol of the currency in which revenue is generated.', description: 'Symbol of the currency in which revenue is generated.',
}, },
{ {
displayName: 'Deal Name', displayName: 'Deal ID',
name: 'Deal_Name', name: 'dealId',
type: 'fixedCollection', type: 'options',
default: {}, default: [],
placeholder: 'Add Deal Name Field', typeOptions: {
options: [ loadOptionsMethod: 'getDeals',
{
displayName: 'Deal Name Fields',
name: 'deal_name_fields',
values: [
{
displayName: 'ID',
name: 'id',
type: 'string',
default: '',
}, },
{
displayName: 'Name',
name: 'name',
type: 'string',
default: '',
},
],
},
],
}, },
{ {
displayName: 'Description', displayName: 'Description',
@ -465,37 +397,39 @@ export const salesOrderFields = [
displayName: 'Discount', displayName: 'Discount',
name: 'Discount', name: 'Discount',
type: 'number', type: 'number',
default: '', default: 0,
typeOptions: {
minValue: 0,
},
}, },
{ {
displayName: 'Due Date', displayName: 'Due Date',
name: 'Due_Date', name: 'Due_Date',
type: 'string', type: 'dateTime',
default: '', default: '',
}, },
{ {
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: 'Purchase Order', displayName: 'Sales Order Number',
name: 'Purchase_Order',
type: 'string',
default: '',
},
{
displayName: 'SO Number',
name: 'SO_Number', name: 'SO_Number',
type: 'string', type: 'string',
default: '', default: '',
@ -504,8 +438,11 @@ export const salesOrderFields = [
{ {
displayName: 'Sales Commission', displayName: 'Sales Commission',
name: 'Sales_Commission', name: 'Sales_Commission',
type: 'string', type: 'number',
default: '', default: 0,
typeOptions: {
minValue: 0,
},
description: 'Commission of sales person on deal closure.', description: 'Commission of sales person on deal closure.',
}, },
shippingAddress, shippingAddress,
@ -520,7 +457,10 @@ export const salesOrderFields = [
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.',
}, },
{ {
@ -534,7 +474,10 @@ export const salesOrderFields = [
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.',
}, },
{ {

View file

@ -222,7 +222,7 @@ export const address = {
], ],
}; };
export const productDetails = (resource: string, operation: string) => ({ export const makeProductDetails = (resource: string, operation: string) => ({
displayName: 'Products', displayName: 'Products',
name: 'Product_Details', name: 'Product_Details',
type: 'collection', type: 'collection',

View file

@ -0,0 +1,61 @@
import { IDataObject } from "n8n-workflow";
// ----------------------------------------
// for auth
// ----------------------------------------
export type ZohoOAuth2ApiCredentials = {
oauthTokenData: {
api_domain: string;
};
};
// ----------------------------------------
// for field adjusters
// ----------------------------------------
export type IdType = 'accountId' | 'contactId' | 'dealId' | 'purchaseOrderId';
export type NameType = 'Account_Name' | 'Full_Name' | 'Deal_Name' | 'Product_Name' | 'Vendor_Name';
type LocationType = 'Address' | 'Billing_Address' | 'Mailing_Address' | 'Shipping_Address' | 'Other_Address';
type DateType = 'Date_of_Birth' | 'Closing_Date' | 'Due_Date' | 'Invoice_Date' | 'PO_Date' | 'Valid_Till';
export type AllFields =
{ [Date in DateType]?: string } &
{ [Location in LocationType]?: { address_fields: { [key: string]: string } } } &
{ Account?: { subfields: { id: string; name: string; } } } &
{ [key in 'accountId' | 'contactId' | 'dealId']?: string } &
IDataObject;
export type ProductDetails = Array<{ id: string, quantity: number }>;
// ----------------------------------------
// for resource loaders
// ----------------------------------------
export type LoadedAccounts = Array<{
Account_Name: string;
id: string;
}>;
export type LoadedContacts = Array<{
Full_Name: string;
id: string;
}>;
export type LoadedDeals = Array<{
Deal_Name: string;
id: string;
}>;
export type LoadedVendors = Array<{
Vendor_Name: string;
id: string;
}>;
export type LoadedProducts = Array<{
Product_Name: string;
id: string;
}>;