From 69afa07e3ba45495a4cab3490c15f2b0c40c4790 Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Mon, 2 Oct 2023 23:27:05 +0200 Subject: [PATCH] fix(webapp): Disable tax rates from item entries editor table on services do not support tax rates --- .../containers/Entries/ItemsEntriesTable.tsx | 15 +++++++++++++- .../src/containers/Entries/components.tsx | 20 +++++++++++-------- .../Bills/BillForm/BillItemsEntriesEditor.tsx | 5 +++-- .../VendorCreditNoteItemsEntriesEditor.tsx | 5 +++-- .../CreditNoteItemsEntriesEditorField.tsx | 5 +++-- .../EstimateItemsEntriesField.tsx | 5 +++-- .../Sales/Estimates/EstimateForm/utils.tsx | 13 +++++++++++- .../ReceiptForm/ReceiptItemsEntriesEditor.tsx | 5 +++-- .../Sales/Receipts/ReceiptForm/utils.tsx | 13 +++++++++++- 9 files changed, 65 insertions(+), 21 deletions(-) diff --git a/packages/webapp/src/containers/Entries/ItemsEntriesTable.tsx b/packages/webapp/src/containers/Entries/ItemsEntriesTable.tsx index 4a881cfec8..9af0a963fc 100644 --- a/packages/webapp/src/containers/Entries/ItemsEntriesTable.tsx +++ b/packages/webapp/src/containers/Entries/ItemsEntriesTable.tsx @@ -17,11 +17,21 @@ import { useItemEntriesTableContext, } from './ItemEntriesTableProvider'; import { useUncontrolled } from '@/hooks/useUncontrolled'; +import { ItemEntry } from '@/interfaces/ItemEntries'; + +interface ItemsEntriesTableProps { + initialValue?: ItemEntry; + value?: ItemEntry[]; + onChange?: (entries: ItemEntry[]) => void; + taxRates?: any[]; + minLinesNumber?: number; + enableTaxRates?: boolean; +} /** * Items entries table. */ -function ItemsEntriesTable(props) { +function ItemsEntriesTable(props: ItemsEntriesTableProps) { const { value, initialValue, onChange } = props; const [localValue, handleChange] = useUncontrolled({ @@ -119,8 +129,11 @@ ItemsEntriesTable.defaultProps = { discount: '', }, initialEntries: [], + taxRates: [], + items: [], linesNumber: 1, minLinesNumber: 1, + enableTaxRates: true, }; export default ItemsEntriesTable; diff --git a/packages/webapp/src/containers/Entries/components.tsx b/packages/webapp/src/containers/Entries/components.tsx index e8d875b43f..7de9334d51 100644 --- a/packages/webapp/src/containers/Entries/components.tsx +++ b/packages/webapp/src/containers/Entries/components.tsx @@ -92,7 +92,7 @@ const LandedCostHeaderCell = () => { */ export function useEditableItemsEntriesColumns() { const { featureCan } = useFeatureCan(); - const { landedCost } = useItemEntriesTableContext(); + const { landedCost, enableTaxRates } = useItemEntriesTableContext(); const isProjectsFeatureEnabled = featureCan(Features.Projects); @@ -132,13 +132,17 @@ export function useEditableItemsEntriesColumns() { width: 70, align: Align.Right, }, - { - Header: 'Tax rate', - accessor: 'tax_rate_id', - Cell: TaxRatesSuggestInputCell, - disableSortBy: true, - width: 110, - }, + ...(enableTaxRates + ? [ + { + Header: 'Tax rate', + accessor: 'tax_rate_id', + Cell: TaxRatesSuggestInputCell, + disableSortBy: true, + width: 110, + }, + ] + : []), { Header: intl.get('discount'), accessor: 'discount', diff --git a/packages/webapp/src/containers/Purchases/Bills/BillForm/BillItemsEntriesEditor.tsx b/packages/webapp/src/containers/Purchases/Bills/BillForm/BillItemsEntriesEditor.tsx index 4f0d3b773a..5d46a0e034 100644 --- a/packages/webapp/src/containers/Purchases/Bills/BillForm/BillItemsEntriesEditor.tsx +++ b/packages/webapp/src/containers/Purchases/Bills/BillForm/BillItemsEntriesEditor.tsx @@ -27,8 +27,8 @@ export default function BillFormBody({ defaultBill }) { meta: { error, touched }, }) => ( { + value={value} + onChange={(entries) => { setFieldValue('entries', entries); }} items={items} @@ -37,6 +37,7 @@ export default function BillFormBody({ defaultBill }) { currencyCode={values.currency_code} itemType={ITEM_TYPE.PURCHASABLE} landedCost={true} + enableTaxRates={false} /> )} diff --git a/packages/webapp/src/containers/Purchases/CreditNotes/CreditNoteForm/VendorCreditNoteItemsEntriesEditor.tsx b/packages/webapp/src/containers/Purchases/CreditNotes/CreditNoteForm/VendorCreditNoteItemsEntriesEditor.tsx index 61db5ca9fe..e0c12871fa 100644 --- a/packages/webapp/src/containers/Purchases/CreditNotes/CreditNoteForm/VendorCreditNoteItemsEntriesEditor.tsx +++ b/packages/webapp/src/containers/Purchases/CreditNotes/CreditNoteForm/VendorCreditNoteItemsEntriesEditor.tsx @@ -22,14 +22,15 @@ export default function VendorCreditNoteItemsEntriesEditor() { meta: { error, touched }, }) => ( { + value={value} + onChange={(entries) => { setFieldValue('entries', entries); }} items={items} errors={error} linesNumber={4} currencyCode={values.currency_code} + enableTaxRates={false} /> )} diff --git a/packages/webapp/src/containers/Sales/CreditNotes/CreditNoteForm/CreditNoteItemsEntriesEditorField.tsx b/packages/webapp/src/containers/Sales/CreditNotes/CreditNoteForm/CreditNoteItemsEntriesEditorField.tsx index 60f2bd15e0..17709be69d 100644 --- a/packages/webapp/src/containers/Sales/CreditNotes/CreditNoteForm/CreditNoteItemsEntriesEditorField.tsx +++ b/packages/webapp/src/containers/Sales/CreditNotes/CreditNoteForm/CreditNoteItemsEntriesEditorField.tsx @@ -26,14 +26,15 @@ export default function CreditNoteItemsEntriesEditorField() { meta: { error, touched }, }) => ( { + value={value} + onChange={(entries) => { setFieldValue('entries', entries); }} items={items} errors={error} linesNumber={4} currencyCode={values.currency_code} + enableTaxRates={false} /> )} diff --git a/packages/webapp/src/containers/Sales/Estimates/EstimateForm/EstimateItemsEntriesField.tsx b/packages/webapp/src/containers/Sales/Estimates/EstimateForm/EstimateItemsEntriesField.tsx index 8f612a9708..977c55ef15 100644 --- a/packages/webapp/src/containers/Sales/Estimates/EstimateForm/EstimateItemsEntriesField.tsx +++ b/packages/webapp/src/containers/Sales/Estimates/EstimateForm/EstimateItemsEntriesField.tsx @@ -26,14 +26,15 @@ export default function EstimateFormItemsEntriesField() { meta: { error, touched }, }) => ( { + value={value} + onChange={(entries) => { setFieldValue('entries', entries); }} items={items} errors={error} linesNumber={4} currencyCode={values.currency_code} + enableTaxRates={false} /> )} diff --git a/packages/webapp/src/containers/Sales/Estimates/EstimateForm/utils.tsx b/packages/webapp/src/containers/Sales/Estimates/EstimateForm/utils.tsx index 029a3a70dd..486c1de21a 100644 --- a/packages/webapp/src/containers/Sales/Estimates/EstimateForm/utils.tsx +++ b/packages/webapp/src/containers/Sales/Estimates/EstimateForm/utils.tsx @@ -31,6 +31,15 @@ export const defaultEstimateEntry = { amount: '', }; +const defaultEstimateEntryReq = { + index: 0, + item_id: '', + rate: '', + discount: '', + quantity: '', + description: '', +}; + export const defaultEstimate = { customer_id: '', estimate_date: moment(new Date()).format('YYYY-MM-DD'), @@ -148,7 +157,9 @@ export const transfromsFormValuesToRequest = (values) => { ...(values.estimate_number_manually && { estimate_number: values.estimate_number, }), - entries: entries.map((entry) => ({ ...omit(entry, ['amount']) })), + entries: entries.map((entry) => ({ + ...transformToForm(entry, defaultEstimateEntryReq), + })), }; }; diff --git a/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/ReceiptItemsEntriesEditor.tsx b/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/ReceiptItemsEntriesEditor.tsx index 1fbf003de6..002559fbd4 100644 --- a/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/ReceiptItemsEntriesEditor.tsx +++ b/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/ReceiptItemsEntriesEditor.tsx @@ -19,14 +19,15 @@ export default function ReceiptItemsEntriesEditor({ defaultReceipt }) { meta: { error, touched }, }) => ( { + value={value} + onChange={(entries) => { setFieldValue('entries', entries); }} items={items} errors={error} linesNumber={4} currencyCode={values.currency_code} + enableTaxRates={false} /> )} diff --git a/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/utils.tsx b/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/utils.tsx index b1f766d3ba..e8c019e7ac 100644 --- a/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/utils.tsx +++ b/packages/webapp/src/containers/Sales/Receipts/ReceiptForm/utils.tsx @@ -32,6 +32,15 @@ export const defaultReceiptEntry = { amount: '', }; +const defaultReceiptEntryReq = { + index: 0, + item_id: '', + rate: '', + discount: '', + quantity: '', + description: '', +}; + export const defaultReceipt = { customer_id: '', deposit_account_id: '', @@ -140,7 +149,9 @@ export const transformFormValuesToRequest = (values) => { ...(values.receipt_number_manually && { receipt_number: values.receipt_number, }), - entries: entries.map((entry) => ({ ...omit(entry, ['amount']) })), + entries: entries.map((entry) => ({ + ...transformToForm(entry, defaultReceiptEntryReq), + })), closed: false, }; };