mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 13:20:31 +00:00
feat( S&P ): Add currency code in conversion to invoice & credit.
This commit is contained in:
@@ -74,8 +74,8 @@ function InvoiceForm({
|
||||
invoice_no: invoiceNumber,
|
||||
}),
|
||||
entries: orderingLinesIndexes(defaultInvoice.entries),
|
||||
...newInvoice,
|
||||
currency_code: base_currency,
|
||||
...newInvoice,
|
||||
}),
|
||||
}),
|
||||
[invoice, newInvoice, invoiceNumber, invoiceIncrementMode, base_currency],
|
||||
|
||||
@@ -16,6 +16,7 @@ import styled from 'styled-components';
|
||||
import {
|
||||
useObserveInvoiceNoSettings,
|
||||
customerNameFieldShouldUpdate,
|
||||
useSetForeignCurrencyToEditForm,
|
||||
} from './utils';
|
||||
import { CLASSES } from 'common/classes';
|
||||
import {
|
||||
@@ -84,6 +85,8 @@ function InvoiceFormHeaderFields({
|
||||
}
|
||||
};
|
||||
|
||||
useSetForeignCurrencyToEditForm();
|
||||
|
||||
// Syncs invoice number settings with form.
|
||||
useObserveInvoiceNoSettings(invoiceNumberPrefix, invoiceNextNumber);
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ function InvoiceFormProvider({ invoiceId, baseCurrency, ...props }) {
|
||||
|
||||
const newInvoice = !isEmpty(estimate)
|
||||
? transformToEditForm({
|
||||
...pick(estimate, ['customer_id', 'customer', 'entries']),
|
||||
...pick(estimate, ['customer_id', 'currency_code', 'entries']),
|
||||
})
|
||||
: [];
|
||||
|
||||
@@ -91,10 +91,6 @@ function InvoiceFormProvider({ invoiceId, baseCurrency, ...props }) {
|
||||
!isEqual(selectCustomer?.currency_code, baseCurrency) &&
|
||||
!isUndefined(selectCustomer?.currency_code);
|
||||
|
||||
const currencyCode = isForeignCustomer
|
||||
? selectCustomer?.currency_code
|
||||
: baseCurrency;
|
||||
|
||||
const provider = {
|
||||
invoice,
|
||||
items,
|
||||
@@ -107,7 +103,6 @@ function InvoiceFormProvider({ invoiceId, baseCurrency, ...props }) {
|
||||
baseCurrency,
|
||||
branches,
|
||||
warehouses,
|
||||
currencyCode,
|
||||
|
||||
isInvoiceLoading,
|
||||
isItemsLoading,
|
||||
|
||||
@@ -200,3 +200,14 @@ export const useSetPrimaryBranchToForm = () => {
|
||||
}
|
||||
}, [isBranchesSuccess, setFieldValue, branches]);
|
||||
};
|
||||
|
||||
export const useSetForeignCurrencyToEditForm = () => {
|
||||
const { values } = useFormikContext();
|
||||
const { isNewMode, setSelectCustomer } = useInvoiceFormContext();
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!isNewMode) {
|
||||
setSelectCustomer({ currency_code: values.currency_code });
|
||||
}
|
||||
}, [isNewMode, setSelectCustomer, values]);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user