From 5a508dd78984faa25530d99a6ee165c2d7aa3cdb Mon Sep 17 00:00:00 2001 From: elforjani13 <39470382+elforjani13@users.noreply.github.com> Date: Wed, 23 Mar 2022 00:09:08 +0200 Subject: [PATCH] fix: customer/vendor opening balance . --- .../CustomerOpeningBalanceFormProvider.js | 12 ++---------- .../Dialogs/CustomerOpeningBalanceDialog/utils.js | 13 ++++++++++++- .../VendorOpeningBalanceFormProvider.js | 12 ++---------- .../Dialogs/VendorOpeningBalanceDialog/utils.js | 13 ++++++++++++- 4 files changed, 28 insertions(+), 22 deletions(-) diff --git a/src/containers/Dialogs/CustomerOpeningBalanceDialog/CustomerOpeningBalanceFormProvider.js b/src/containers/Dialogs/CustomerOpeningBalanceDialog/CustomerOpeningBalanceFormProvider.js index 62d070245..ecc7af40b 100644 --- a/src/containers/Dialogs/CustomerOpeningBalanceDialog/CustomerOpeningBalanceFormProvider.js +++ b/src/containers/Dialogs/CustomerOpeningBalanceDialog/CustomerOpeningBalanceFormProvider.js @@ -7,7 +7,7 @@ import { } from 'hooks/query'; import { useFeatureCan } from 'hooks/state'; import { Features } from 'common'; -import { pick } from 'lodash'; +import { transfromCustomertoForm } from './utils'; const CustomerOpeningBalanceContext = React.createContext(); @@ -44,15 +44,7 @@ function CustomerOpeningBalanceFormProvider({ // State provider. const provider = { branches, - customer: { - ...pick(customer, [ - 'id', - 'opening_balance', - 'opening_balance_exchange_rate', - 'currency_code', - ]), - // opening_balance_at: customer.formatted_opening_balance_at, - }, + customer: transfromCustomertoForm(customer), isBranchesSuccess, isBranchesLoading, diff --git a/src/containers/Dialogs/CustomerOpeningBalanceDialog/utils.js b/src/containers/Dialogs/CustomerOpeningBalanceDialog/utils.js index 206545395..c0177edef 100644 --- a/src/containers/Dialogs/CustomerOpeningBalanceDialog/utils.js +++ b/src/containers/Dialogs/CustomerOpeningBalanceDialog/utils.js @@ -1,6 +1,6 @@ import React from 'react'; import { useFormikContext } from 'formik'; -import { first } from 'lodash'; +import { first, pick } from 'lodash'; import { useCustomerOpeningBalanceContext } from './CustomerOpeningBalanceFormProvider'; @@ -18,3 +18,14 @@ export const useSetPrimaryBranchToForm = () => { } }, [isBranchesSuccess, setFieldValue, branches]); }; + +export function transfromCustomertoForm(values) { + return { + ...pick(values, [ + 'id', + 'opening_balance', + 'opening_balance_exchange_rate', + 'currency_code', + ]), + }; +} diff --git a/src/containers/Dialogs/VendorOpeningBalanceDialog/VendorOpeningBalanceFormProvider.js b/src/containers/Dialogs/VendorOpeningBalanceDialog/VendorOpeningBalanceFormProvider.js index 4f0aa7b4b..17f763cfb 100644 --- a/src/containers/Dialogs/VendorOpeningBalanceDialog/VendorOpeningBalanceFormProvider.js +++ b/src/containers/Dialogs/VendorOpeningBalanceDialog/VendorOpeningBalanceFormProvider.js @@ -7,7 +7,7 @@ import { } from 'hooks/query'; import { useFeatureCan } from 'hooks/state'; import { Features } from 'common'; -import { pick, defaultTo } from 'lodash'; +import { transfromVendorToForm } from './utils'; const VendorOpeningBalanceContext = React.createContext(); @@ -43,15 +43,7 @@ function VendorOpeningBalanceFormProvider({ // State provider. const provider = { branches, - vendor: { - ...pick(vendor, [ - 'id', - 'opening_balance', - 'opening_balance_exchange_rate', - 'currency_code', - ]), - }, - + vendor: transfromVendorToForm(vendor), isBranchesSuccess, isBranchesLoading, dialogName, diff --git a/src/containers/Dialogs/VendorOpeningBalanceDialog/utils.js b/src/containers/Dialogs/VendorOpeningBalanceDialog/utils.js index 8b534e87e..ca739d669 100644 --- a/src/containers/Dialogs/VendorOpeningBalanceDialog/utils.js +++ b/src/containers/Dialogs/VendorOpeningBalanceDialog/utils.js @@ -1,6 +1,6 @@ import React from 'react'; import { useFormikContext } from 'formik'; -import { first } from 'lodash'; +import { first, pick } from 'lodash'; import { useVendorOpeningBalanceContext } from './VendorOpeningBalanceFormProvider'; @@ -18,3 +18,14 @@ export const useSetPrimaryBranchToForm = () => { } }, [isBranchesSuccess, setFieldValue, branches]); }; + +export function transfromVendorToForm(values) { + return { + ...pick(values, [ + 'id', + 'opening_balance', + 'opening_balance_exchange_rate', + 'currency_code', + ]), + }; +}