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.
|
||||
*/
|
||||
const adjustDateField = (dateType: DateType) => (allFields: DateField) => {
|
||||
const adjustDateField = (dateType: DateType) => (allFields: IDataObject) => {
|
||||
const dateField = allFields[dateType];
|
||||
|
||||
if (!dateField) return allFields;
|
||||
|
||||
// @ts-ignore TODO
|
||||
allFields[dateType] = dateField.split('T')[0];
|
||||
|
||||
return allFields;
|
||||
|
@ -145,14 +146,47 @@ const adjustDateField = (dateType: DateType) => (allFields: DateField) => {
|
|||
|
||||
const adjustDateOfBirthField = adjustDateField('Date_of_Birth');
|
||||
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 adjustInvoiceFields = flow(adjustBillingAddressFields, adjustShippingAddressFields); // TODO: product details
|
||||
|
||||
export const adjustInvoiceFields = flow(
|
||||
adjustBillingAddressFields,
|
||||
adjustShippingAddressFields,
|
||||
adjustInvoiceDateField,
|
||||
adjustDueDateField,
|
||||
adjustAccountField,
|
||||
);
|
||||
|
||||
export const adjustLeadFields = adjustAddressFields;
|
||||
|
||||
export const adjustPurchaseOrderFields = adjustInvoiceFields;
|
||||
|
||||
export const adjustQuoteFields = adjustInvoiceFields;
|
||||
|
||||
export const adjustSalesOrderFields = adjustInvoiceFields;
|
||||
|
||||
// ----------------------------------------
|
||||
|
@ -176,6 +210,6 @@ type LocationField = {
|
|||
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 = {
|
||||
Product_Details: this.getNodeParameter('Product_Details', i),
|
||||
Subject: this.getNodeParameter('Subject', i),
|
||||
Product_Details: [
|
||||
this.getNodeParameter('Product_Details', i),
|
||||
],
|
||||
Subject: this.getNodeParameter('subject', i),
|
||||
};
|
||||
|
||||
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||
|
|
|
@ -52,23 +52,6 @@ export const invoiceFields = [
|
|||
// ----------------------------------------
|
||||
// invoice: create
|
||||
// ----------------------------------------
|
||||
{
|
||||
displayName: 'Product Details',
|
||||
name: 'productDetails',
|
||||
type: '',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'invoice',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Subject',
|
||||
name: 'subject',
|
||||
|
@ -87,6 +70,7 @@ export const invoiceFields = [
|
|||
},
|
||||
},
|
||||
},
|
||||
productDetails('invoice', 'create'),
|
||||
{
|
||||
displayName: 'Additional Fields',
|
||||
name: 'additionalFields',
|
||||
|
@ -105,9 +89,10 @@ export const invoiceFields = [
|
|||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Account Name',
|
||||
displayName: 'Account',
|
||||
name: 'Account_Name',
|
||||
type: 'fixedCollection',
|
||||
description: 'Account who the invoice is issued for.',
|
||||
default: {},
|
||||
placeholder: 'Add Account Name Field',
|
||||
options: [
|
||||
|
@ -121,6 +106,12 @@ export const invoiceFields = [
|
|||
type: 'string',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Name',
|
||||
name: 'name',
|
||||
type: 'string',
|
||||
default: '',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
|
@ -149,7 +140,7 @@ export const invoiceFields = [
|
|||
{
|
||||
displayName: 'Due Date',
|
||||
name: 'Due_Date',
|
||||
type: 'string',
|
||||
type: 'dateTime',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
|
@ -169,7 +160,7 @@ export const invoiceFields = [
|
|||
{
|
||||
displayName: 'Invoice Date',
|
||||
name: 'Invoice_Date',
|
||||
type: 'string',
|
||||
type: 'dateTime',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
|
@ -181,7 +172,7 @@ export const invoiceFields = [
|
|||
{
|
||||
displayName: 'Sales Commission',
|
||||
name: 'Sales_Commission',
|
||||
type: 'string',
|
||||
type: 'number',
|
||||
default: '',
|
||||
description: 'Commission of sales person on deal closure.',
|
||||
},
|
||||
|
@ -320,6 +311,12 @@ export const invoiceFields = [
|
|||
type: 'string',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Name',
|
||||
name: 'name',
|
||||
type: 'string',
|
||||
default: '',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
|
@ -348,7 +345,7 @@ export const invoiceFields = [
|
|||
{
|
||||
displayName: 'Due Date',
|
||||
name: 'Due_Date',
|
||||
type: 'string',
|
||||
type: 'dateTime',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
|
@ -368,7 +365,7 @@ export const invoiceFields = [
|
|||
{
|
||||
displayName: 'Invoice Date',
|
||||
name: 'Invoice_Date',
|
||||
type: 'string',
|
||||
type: 'dateTime',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
|
@ -377,11 +374,10 @@ export const invoiceFields = [
|
|||
type: 'string',
|
||||
default: '',
|
||||
},
|
||||
productDetails,
|
||||
{
|
||||
displayName: 'Sales Commission',
|
||||
name: 'Sales_Commission',
|
||||
type: 'string',
|
||||
type: 'number',
|
||||
default: '',
|
||||
description: 'Commission of sales person on deal closure.',
|
||||
},
|
||||
|
|
|
@ -216,7 +216,7 @@ export const purchaseOrderFields = [
|
|||
default: '',
|
||||
description: 'ID of the purchase order after creating a case.',
|
||||
},
|
||||
productDetails,
|
||||
// productDetails,
|
||||
{
|
||||
displayName: 'Sales Commission',
|
||||
name: 'Sales_Commission',
|
||||
|
@ -417,7 +417,7 @@ export const purchaseOrderFields = [
|
|||
default: '',
|
||||
description: 'ID of the purchase order after creating a case.',
|
||||
},
|
||||
productDetails,
|
||||
// productDetails,
|
||||
{
|
||||
displayName: 'Sales Commission',
|
||||
name: 'Sales_Commission',
|
||||
|
|
|
@ -52,23 +52,6 @@ export const quoteFields = [
|
|||
// ----------------------------------------
|
||||
// quote: create
|
||||
// ----------------------------------------
|
||||
{
|
||||
displayName: 'Product Details',
|
||||
name: 'productDetails',
|
||||
type: '',
|
||||
required: true,
|
||||
default: '',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
'quote',
|
||||
],
|
||||
operation: [
|
||||
'create',
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
displayName: 'Subject',
|
||||
name: 'subject',
|
||||
|
@ -318,7 +301,7 @@ export const quoteFields = [
|
|||
default: '',
|
||||
description: 'Total amount for the product after deducting tax and discounts.',
|
||||
},
|
||||
productDetails,
|
||||
// productDetails,
|
||||
{
|
||||
displayName: 'Quote Stage',
|
||||
name: 'Quote_Stage',
|
||||
|
|
|
@ -212,7 +212,7 @@ export const salesOrderFields = [
|
|||
default: '',
|
||||
description: 'Total amount for the product after deducting tax and discounts.',
|
||||
},
|
||||
productDetails,
|
||||
// productDetails,
|
||||
{
|
||||
displayName: 'Purchase Order',
|
||||
name: 'Purchase_Order',
|
||||
|
@ -487,7 +487,7 @@ export const salesOrderFields = [
|
|||
default: '',
|
||||
description: 'Total amount for the product after deducting tax and discounts.',
|
||||
},
|
||||
productDetails,
|
||||
// productDetails,
|
||||
{
|
||||
displayName: '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',
|
||||
name: 'Product_Details',
|
||||
type: 'fixedCollection',
|
||||
type: 'collection',
|
||||
default: {},
|
||||
placeholder: 'Add Product Details Field',
|
||||
placeholder: 'Add Field',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: [
|
||||
resource,
|
||||
],
|
||||
operation: [
|
||||
operation,
|
||||
],
|
||||
},
|
||||
},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Product Details Fields',
|
||||
name: 'product_details_fields',
|
||||
values: [
|
||||
displayName: 'List Price',
|
||||
name: 'list_price',
|
||||
type: 'number',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Net Total',
|
||||
name: 'net_total',
|
||||
type: 'number',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Product',
|
||||
name: 'product',
|
||||
type: 'collection',
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
displayName: 'Tax',
|
||||
name: 'Tax',
|
||||
displayName: 'ID',
|
||||
name: 'id',
|
||||
type: 'string',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'Book',
|
||||
name: 'book',
|
||||
displayName: 'Name',
|
||||
name: 'name',
|
||||
type: 'string',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
displayName: 'List Price',
|
||||
name: 'list_price',
|
||||
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',
|
||||
displayName: 'Product Code',
|
||||
name: 'Product_Code',
|
||||
type: 'string',
|
||||
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) => [
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue