mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
⚡ Adjust invoice operations
This commit is contained in:
parent
75a7bbef34
commit
6efae90a89
|
@ -133,11 +133,12 @@ const adjustOtherAddressFields = adjustLocationFields('Other_Address');
|
||||||
/**
|
/**
|
||||||
* Remove a date field's timestamp.
|
* Remove a date field's timestamp.
|
||||||
*/
|
*/
|
||||||
const adjustDateField = (dateType: DateType) => (allFields: DateField) => {
|
const adjustDateField = (dateType: DateType) => (allFields: IDataObject) => {
|
||||||
const dateField = allFields[dateType];
|
const dateField = allFields[dateType];
|
||||||
|
|
||||||
if (!dateField) return allFields;
|
if (!dateField) return allFields;
|
||||||
|
|
||||||
|
// @ts-ignore TODO
|
||||||
allFields[dateType] = dateField.split('T')[0];
|
allFields[dateType] = dateField.split('T')[0];
|
||||||
|
|
||||||
return allFields;
|
return allFields;
|
||||||
|
@ -145,14 +146,47 @@ const adjustDateField = (dateType: DateType) => (allFields: DateField) => {
|
||||||
|
|
||||||
const adjustDateOfBirthField = adjustDateField('Date_of_Birth');
|
const adjustDateOfBirthField = adjustDateField('Date_of_Birth');
|
||||||
const adjustClosingDateField = adjustDateField('Closing_Date');
|
const adjustClosingDateField = adjustDateField('Closing_Date');
|
||||||
|
const adjustInvoiceDateField = adjustDateField('Invoice_Date');
|
||||||
|
const adjustDueDateField = adjustDateField('Due_Date');
|
||||||
|
|
||||||
|
const adjustAccountField = (allFields: IDataObject) => {
|
||||||
|
if (!allFields.Account_Name) return allFields;
|
||||||
|
|
||||||
|
// @ts-ignore TODO
|
||||||
|
return { ...omit('Account_Name', allFields), ...allFields.Account_Name.account_name_fields };
|
||||||
|
};
|
||||||
|
|
||||||
|
// ----------------------------------------
|
||||||
|
// field adjusters per resource
|
||||||
|
// ----------------------------------------
|
||||||
|
|
||||||
|
export const adjustAccountFields = flow(
|
||||||
|
adjustBillingAddressFields,
|
||||||
|
adjustShippingAddressFields,
|
||||||
|
);
|
||||||
|
|
||||||
|
export const adjustContactFields = flow(
|
||||||
|
adjustMailingAddressFields,
|
||||||
|
adjustOtherAddressFields,
|
||||||
|
adjustDateOfBirthField,
|
||||||
|
);
|
||||||
|
|
||||||
export const adjustAccountFields = flow(adjustBillingAddressFields, adjustShippingAddressFields);
|
|
||||||
export const adjustContactFields = flow(adjustMailingAddressFields, adjustOtherAddressFields, adjustDateOfBirthField);
|
|
||||||
export const adjustDealFields = adjustClosingDateField;
|
export const adjustDealFields = adjustClosingDateField;
|
||||||
export const adjustInvoiceFields = flow(adjustBillingAddressFields, adjustShippingAddressFields); // TODO: product details
|
|
||||||
|
export const adjustInvoiceFields = flow(
|
||||||
|
adjustBillingAddressFields,
|
||||||
|
adjustShippingAddressFields,
|
||||||
|
adjustInvoiceDateField,
|
||||||
|
adjustDueDateField,
|
||||||
|
adjustAccountField,
|
||||||
|
);
|
||||||
|
|
||||||
export const adjustLeadFields = adjustAddressFields;
|
export const adjustLeadFields = adjustAddressFields;
|
||||||
|
|
||||||
export const adjustPurchaseOrderFields = adjustInvoiceFields;
|
export const adjustPurchaseOrderFields = adjustInvoiceFields;
|
||||||
|
|
||||||
export const adjustQuoteFields = adjustInvoiceFields;
|
export const adjustQuoteFields = adjustInvoiceFields;
|
||||||
|
|
||||||
export const adjustSalesOrderFields = adjustInvoiceFields;
|
export const adjustSalesOrderFields = adjustInvoiceFields;
|
||||||
|
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
|
@ -176,6 +210,6 @@ type LocationField = {
|
||||||
address_fields: { [key in LocationType]: string };
|
address_fields: { [key in LocationType]: string };
|
||||||
};
|
};
|
||||||
|
|
||||||
type DateType = 'Date_of_Birth' | 'Closing_Date';
|
type DateType = 'Date_of_Birth' | 'Closing_Date' | 'Due_Date' | 'Invoice_Date';
|
||||||
|
|
||||||
type DateField = { Date_of_Birth?: string; Closing_Date?: string; };
|
type DateField = { Date_of_Birth?: string; Closing_Date?: string; Due_Date?: string; Invoice_Date?: string };
|
||||||
|
|
|
@ -380,8 +380,10 @@ export class ZohoCrm implements INodeType {
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
|
|
||||||
const body: IDataObject = {
|
const body: IDataObject = {
|
||||||
Product_Details: this.getNodeParameter('Product_Details', i),
|
Product_Details: [
|
||||||
Subject: this.getNodeParameter('Subject', i),
|
this.getNodeParameter('Product_Details', i),
|
||||||
|
],
|
||||||
|
Subject: this.getNodeParameter('subject', i),
|
||||||
};
|
};
|
||||||
|
|
||||||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||||
|
|
|
@ -52,23 +52,6 @@ export const invoiceFields = [
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
// invoice: create
|
// invoice: create
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
{
|
|
||||||
displayName: 'Product Details',
|
|
||||||
name: 'productDetails',
|
|
||||||
type: '',
|
|
||||||
required: true,
|
|
||||||
default: '',
|
|
||||||
displayOptions: {
|
|
||||||
show: {
|
|
||||||
resource: [
|
|
||||||
'invoice',
|
|
||||||
],
|
|
||||||
operation: [
|
|
||||||
'create',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
displayName: 'Subject',
|
displayName: 'Subject',
|
||||||
name: 'subject',
|
name: 'subject',
|
||||||
|
@ -87,6 +70,7 @@ export const invoiceFields = [
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
productDetails('invoice', 'create'),
|
||||||
{
|
{
|
||||||
displayName: 'Additional Fields',
|
displayName: 'Additional Fields',
|
||||||
name: 'additionalFields',
|
name: 'additionalFields',
|
||||||
|
@ -105,9 +89,10 @@ export const invoiceFields = [
|
||||||
},
|
},
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
displayName: 'Account Name',
|
displayName: 'Account',
|
||||||
name: 'Account_Name',
|
name: 'Account_Name',
|
||||||
type: 'fixedCollection',
|
type: 'fixedCollection',
|
||||||
|
description: 'Account who the invoice is issued for.',
|
||||||
default: {},
|
default: {},
|
||||||
placeholder: 'Add Account Name Field',
|
placeholder: 'Add Account Name Field',
|
||||||
options: [
|
options: [
|
||||||
|
@ -121,6 +106,12 @@ export const invoiceFields = [
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Name',
|
||||||
|
name: 'name',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -149,7 +140,7 @@ export const invoiceFields = [
|
||||||
{
|
{
|
||||||
displayName: 'Due Date',
|
displayName: 'Due Date',
|
||||||
name: 'Due_Date',
|
name: 'Due_Date',
|
||||||
type: 'string',
|
type: 'dateTime',
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -169,7 +160,7 @@ export const invoiceFields = [
|
||||||
{
|
{
|
||||||
displayName: 'Invoice Date',
|
displayName: 'Invoice Date',
|
||||||
name: 'Invoice_Date',
|
name: 'Invoice_Date',
|
||||||
type: 'string',
|
type: 'dateTime',
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -181,7 +172,7 @@ export const invoiceFields = [
|
||||||
{
|
{
|
||||||
displayName: 'Sales Commission',
|
displayName: 'Sales Commission',
|
||||||
name: 'Sales_Commission',
|
name: 'Sales_Commission',
|
||||||
type: 'string',
|
type: 'number',
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Commission of sales person on deal closure.',
|
description: 'Commission of sales person on deal closure.',
|
||||||
},
|
},
|
||||||
|
@ -320,6 +311,12 @@ export const invoiceFields = [
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Name',
|
||||||
|
name: 'name',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
@ -348,7 +345,7 @@ export const invoiceFields = [
|
||||||
{
|
{
|
||||||
displayName: 'Due Date',
|
displayName: 'Due Date',
|
||||||
name: 'Due_Date',
|
name: 'Due_Date',
|
||||||
type: 'string',
|
type: 'dateTime',
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -368,7 +365,7 @@ export const invoiceFields = [
|
||||||
{
|
{
|
||||||
displayName: 'Invoice Date',
|
displayName: 'Invoice Date',
|
||||||
name: 'Invoice_Date',
|
name: 'Invoice_Date',
|
||||||
type: 'string',
|
type: 'dateTime',
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -377,11 +374,10 @@ export const invoiceFields = [
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
productDetails,
|
|
||||||
{
|
{
|
||||||
displayName: 'Sales Commission',
|
displayName: 'Sales Commission',
|
||||||
name: 'Sales_Commission',
|
name: 'Sales_Commission',
|
||||||
type: 'string',
|
type: 'number',
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Commission of sales person on deal closure.',
|
description: 'Commission of sales person on deal closure.',
|
||||||
},
|
},
|
||||||
|
|
|
@ -216,7 +216,7 @@ export const purchaseOrderFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'ID of the purchase order after creating a case.',
|
description: 'ID of the purchase order after creating a case.',
|
||||||
},
|
},
|
||||||
productDetails,
|
// productDetails,
|
||||||
{
|
{
|
||||||
displayName: 'Sales Commission',
|
displayName: 'Sales Commission',
|
||||||
name: 'Sales_Commission',
|
name: 'Sales_Commission',
|
||||||
|
@ -417,7 +417,7 @@ export const purchaseOrderFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'ID of the purchase order after creating a case.',
|
description: 'ID of the purchase order after creating a case.',
|
||||||
},
|
},
|
||||||
productDetails,
|
// productDetails,
|
||||||
{
|
{
|
||||||
displayName: 'Sales Commission',
|
displayName: 'Sales Commission',
|
||||||
name: 'Sales_Commission',
|
name: 'Sales_Commission',
|
||||||
|
|
|
@ -52,23 +52,6 @@ export const quoteFields = [
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
// quote: create
|
// quote: create
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
{
|
|
||||||
displayName: 'Product Details',
|
|
||||||
name: 'productDetails',
|
|
||||||
type: '',
|
|
||||||
required: true,
|
|
||||||
default: '',
|
|
||||||
displayOptions: {
|
|
||||||
show: {
|
|
||||||
resource: [
|
|
||||||
'quote',
|
|
||||||
],
|
|
||||||
operation: [
|
|
||||||
'create',
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
displayName: 'Subject',
|
displayName: 'Subject',
|
||||||
name: 'subject',
|
name: 'subject',
|
||||||
|
@ -318,7 +301,7 @@ export const quoteFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Total amount for the product after deducting tax and discounts.',
|
description: 'Total amount for the product after deducting tax and discounts.',
|
||||||
},
|
},
|
||||||
productDetails,
|
// productDetails,
|
||||||
{
|
{
|
||||||
displayName: 'Quote Stage',
|
displayName: 'Quote Stage',
|
||||||
name: 'Quote_Stage',
|
name: 'Quote_Stage',
|
||||||
|
|
|
@ -212,7 +212,7 @@ export const salesOrderFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Total amount for the product after deducting tax and discounts.',
|
description: 'Total amount for the product after deducting tax and discounts.',
|
||||||
},
|
},
|
||||||
productDetails,
|
// productDetails,
|
||||||
{
|
{
|
||||||
displayName: 'Purchase Order',
|
displayName: 'Purchase Order',
|
||||||
name: 'Purchase_Order',
|
name: 'Purchase_Order',
|
||||||
|
@ -487,7 +487,7 @@ export const salesOrderFields = [
|
||||||
default: '',
|
default: '',
|
||||||
description: 'Total amount for the product after deducting tax and discounts.',
|
description: 'Total amount for the product after deducting tax and discounts.',
|
||||||
},
|
},
|
||||||
productDetails,
|
// productDetails,
|
||||||
{
|
{
|
||||||
displayName: 'Purchase Order',
|
displayName: 'Purchase Order',
|
||||||
name: 'Purchase_Order',
|
name: 'Purchase_Order',
|
||||||
|
|
|
@ -222,87 +222,105 @@ export const address = {
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
export const productDetails = {
|
export const productDetails = (resource: string, operation: string) => ({
|
||||||
displayName: 'Product Details',
|
displayName: 'Product Details',
|
||||||
name: 'Product_Details',
|
name: 'Product_Details',
|
||||||
type: 'fixedCollection',
|
type: 'collection',
|
||||||
default: {},
|
default: {},
|
||||||
placeholder: 'Add Product Details Field',
|
placeholder: 'Add Field',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
resource,
|
||||||
|
],
|
||||||
|
operation: [
|
||||||
|
operation,
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
displayName: 'Product Details Fields',
|
displayName: 'List Price',
|
||||||
name: 'product_details_fields',
|
name: 'list_price',
|
||||||
values: [
|
type: 'number',
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Net Total',
|
||||||
|
name: 'net_total',
|
||||||
|
type: 'number',
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Product',
|
||||||
|
name: 'product',
|
||||||
|
type: 'collection',
|
||||||
|
default: {},
|
||||||
|
options: [
|
||||||
{
|
{
|
||||||
displayName: 'Tax',
|
displayName: 'ID',
|
||||||
name: 'Tax',
|
name: 'id',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Book',
|
displayName: 'Name',
|
||||||
name: 'book',
|
name: 'name',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'List Price',
|
displayName: 'Product Code',
|
||||||
name: 'list_price',
|
name: 'Product_Code',
|
||||||
type: 'string',
|
|
||||||
default: '',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
displayName: 'Net Total',
|
|
||||||
name: 'net_total',
|
|
||||||
type: 'string',
|
|
||||||
default: '',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
displayName: 'Product',
|
|
||||||
name: 'product',
|
|
||||||
type: 'string',
|
|
||||||
default: '',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
displayName: 'Product Description',
|
|
||||||
name: 'product_description',
|
|
||||||
type: 'string',
|
|
||||||
default: '',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
displayName: 'Quantity',
|
|
||||||
name: 'quantity',
|
|
||||||
type: 'string',
|
|
||||||
default: '',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
displayName: 'Quantity in Stock',
|
|
||||||
name: 'quantity_in_stock',
|
|
||||||
type: 'string',
|
|
||||||
default: '',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
displayName: 'Total',
|
|
||||||
name: 'total',
|
|
||||||
type: 'string',
|
|
||||||
default: '',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
displayName: 'Total After Discount',
|
|
||||||
name: 'total_after_discount',
|
|
||||||
type: 'string',
|
|
||||||
default: '',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
displayName: 'Unit Price',
|
|
||||||
name: 'unit_price',
|
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Product Description',
|
||||||
|
name: 'product_description',
|
||||||
|
type: 'string',
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Quantity',
|
||||||
|
name: 'quantity',
|
||||||
|
type: 'number',
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Quantity in Stock',
|
||||||
|
name: 'quantity_in_stock',
|
||||||
|
type: 'number',
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Tax',
|
||||||
|
name: 'Tax',
|
||||||
|
type: 'number',
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Total',
|
||||||
|
name: 'total',
|
||||||
|
type: 'number',
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Total After Discount',
|
||||||
|
name: 'total_after_discount',
|
||||||
|
type: 'number',
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Unit Price',
|
||||||
|
name: 'unit_price',
|
||||||
|
type: 'number',
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
};
|
});
|
||||||
|
|
||||||
export const makeGetAllFields = (resource: string) => [
|
export const makeGetAllFields = (resource: string) => [
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue