fix(InvoiceForm): control display exchange rate input for foreign customers.

This commit is contained in:
a.bouhuolia
2022-03-20 11:03:48 +02:00
parent cc637471d9
commit 05126253db
4 changed files with 56 additions and 17 deletions

View File

@@ -14,6 +14,7 @@ import intl from 'react-intl-universal';
import { defaultFastFieldShouldUpdate } from 'utils';
import { ERROR } from 'common/errors';
import { AppToaster } from 'components';
import { useCurrentOrganization } from 'hooks/state';
import { getEntriesTotal } from 'containers/Entries/utils';
import { useInvoiceFormContext } from './InvoiceFormProvider';
import {
@@ -210,3 +211,18 @@ export const useInvoiceTotal = () => {
// Calculate the total due amount of invoice entries.
return React.useMemo(() => getEntriesTotal(entries), [entries]);
};
/**
* Detarmines whether the invoice has foreign customer.
* @returns {boolean}
*/
export const useInvoiceIsForeignCustomer = () => {
const { values } = useFormikContext();
const currentOrganization = useCurrentOrganization();
const isForeignCustomer = React.useMemo(
() => values.currency_code !== currentOrganization.base_currency,
[values.currency_code, currentOrganization.base_currency],
);
return isForeignCustomer;
};