From 6a72594fafa86b869317c882461814f26efd27b5 Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Sun, 11 Jun 2023 20:09:51 +0200 Subject: [PATCH] fix(webapp): update condition of customer opening balance --- .../CustomerForm/CustomerFinancialPanel.tsx | 1 + .../VendorForm/VendorFinanicalPanelTab.tsx | 22 +++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/webapp/src/containers/Customers/CustomerForm/CustomerFinancialPanel.tsx b/packages/webapp/src/containers/Customers/CustomerForm/CustomerFinancialPanel.tsx index 47225a6a7..8de4eb45c 100644 --- a/packages/webapp/src/containers/Customers/CustomerForm/CustomerFinancialPanel.tsx +++ b/packages/webapp/src/containers/Customers/CustomerForm/CustomerFinancialPanel.tsx @@ -141,6 +141,7 @@ function CustomerOpeningBalanceField() { inline={true} shouldUpdate={openingBalanceFieldShouldUpdate} shouldUpdateDeps={{ currencyCode: values.currency_code }} + fastField={true} > diff --git a/packages/webapp/src/containers/Vendors/VendorForm/VendorFinanicalPanelTab.tsx b/packages/webapp/src/containers/Vendors/VendorForm/VendorFinanicalPanelTab.tsx index 03f21f959..def50c6a7 100644 --- a/packages/webapp/src/containers/Vendors/VendorForm/VendorFinanicalPanelTab.tsx +++ b/packages/webapp/src/containers/Vendors/VendorForm/VendorFinanicalPanelTab.tsx @@ -18,7 +18,11 @@ import { ExchangeRateInputGroup, FDateInput, } from '@/components'; -import { useIsVendorForeignCurrency, useSetPrimaryBranchToForm } from './utils'; +import { + openingBalanceFieldShouldUpdate, + useIsVendorForeignCurrency, + useSetPrimaryBranchToForm, +} from './utils'; import { useVendorFormContext } from './VendorFormProvider'; import { useCurrentOrganization } from '@/hooks/state'; @@ -87,6 +91,10 @@ export default function VendorFinanicalPanelTab() { ); } +/** + * Vendor opening balance field. + * @returns {JSX.Element} + */ function VendorOpeningBalanceField() { const { vendorId } = useVendorFormContext(); const { values } = useFormikContext(); @@ -99,6 +107,9 @@ function VendorOpeningBalanceField() { name={'opening_balance'} label={} inline={true} + shouldUpdate={openingBalanceFieldShouldUpdate} + shouldUpdateDeps={{ currencyCode: values.currency_code }} + FastField={true} > @@ -111,6 +122,10 @@ function VendorOpeningBalanceField() { ); } +/** + * Vendor opening balance at date field. + * @returns {JSX.Element} + */ function VendorOpeningBalanceAtField() { 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() { const { values } = useFormikContext(); const { vendorId } = useVendorFormContext(); @@ -146,7 +165,6 @@ function VendorOpeningBalanceExchangeRateField() { if (!isForeignVendor || vendorId) { return null; } - return (