fix(webapp): update condition of customer opening balance

This commit is contained in:
Ahmed Bouhuolia
2023-06-11 20:09:51 +02:00
parent 728729094a
commit 6a72594faf
2 changed files with 21 additions and 2 deletions

View File

@@ -141,6 +141,7 @@ function CustomerOpeningBalanceField() {
inline={true} inline={true}
shouldUpdate={openingBalanceFieldShouldUpdate} shouldUpdate={openingBalanceFieldShouldUpdate}
shouldUpdateDeps={{ currencyCode: values.currency_code }} shouldUpdateDeps={{ currencyCode: values.currency_code }}
fastField={true}
> >
<ControlGroup> <ControlGroup>
<InputPrependText text={values.currency_code} /> <InputPrependText text={values.currency_code} />

View File

@@ -18,7 +18,11 @@ import {
ExchangeRateInputGroup, ExchangeRateInputGroup,
FDateInput, FDateInput,
} from '@/components'; } from '@/components';
import { useIsVendorForeignCurrency, useSetPrimaryBranchToForm } from './utils'; import {
openingBalanceFieldShouldUpdate,
useIsVendorForeignCurrency,
useSetPrimaryBranchToForm,
} from './utils';
import { useVendorFormContext } from './VendorFormProvider'; import { useVendorFormContext } from './VendorFormProvider';
import { useCurrentOrganization } from '@/hooks/state'; import { useCurrentOrganization } from '@/hooks/state';
@@ -87,6 +91,10 @@ export default function VendorFinanicalPanelTab() {
); );
} }
/**
* Vendor opening balance field.
* @returns {JSX.Element}
*/
function VendorOpeningBalanceField() { function VendorOpeningBalanceField() {
const { vendorId } = useVendorFormContext(); const { vendorId } = useVendorFormContext();
const { values } = useFormikContext(); const { values } = useFormikContext();
@@ -99,6 +107,9 @@ function VendorOpeningBalanceField() {
name={'opening_balance'} name={'opening_balance'}
label={<T id={'opening_balance'} />} label={<T id={'opening_balance'} />}
inline={true} inline={true}
shouldUpdate={openingBalanceFieldShouldUpdate}
shouldUpdateDeps={{ currencyCode: values.currency_code }}
FastField={true}
> >
<ControlGroup> <ControlGroup>
<InputPrependText text={values.currency_code} /> <InputPrependText text={values.currency_code} />
@@ -111,6 +122,10 @@ function VendorOpeningBalanceField() {
); );
} }
/**
* Vendor opening balance at date field.
* @returns {JSX.Element}
*/
function VendorOpeningBalanceAtField() { function VendorOpeningBalanceAtField() {
const { vendorId } = useVendorFormContext(); const { vendorId } = useVendorFormContext();
@@ -136,6 +151,10 @@ function VendorOpeningBalanceAtField() {
); );
} }
/**
* Vendor opening balance exchange rate field if the vendor has foreign currency.
* @returns {JSX.Element}
*/
function VendorOpeningBalanceExchangeRateField() { function VendorOpeningBalanceExchangeRateField() {
const { values } = useFormikContext(); const { values } = useFormikContext();
const { vendorId } = useVendorFormContext(); const { vendorId } = useVendorFormContext();
@@ -146,7 +165,6 @@ function VendorOpeningBalanceExchangeRateField() {
if (!isForeignVendor || vendorId) { if (!isForeignVendor || vendorId) {
return null; return null;
} }
return ( return (
<FFormGroup <FFormGroup
label={' '} label={' '}