fix: customer/vendor opening balance .

This commit is contained in:
elforjani13
2022-03-23 00:09:08 +02:00
parent bac6812d36
commit 5a508dd789
4 changed files with 28 additions and 22 deletions

View File

@@ -7,7 +7,7 @@ import {
} from 'hooks/query'; } from 'hooks/query';
import { useFeatureCan } from 'hooks/state'; import { useFeatureCan } from 'hooks/state';
import { Features } from 'common'; import { Features } from 'common';
import { pick } from 'lodash'; import { transfromCustomertoForm } from './utils';
const CustomerOpeningBalanceContext = React.createContext(); const CustomerOpeningBalanceContext = React.createContext();
@@ -44,15 +44,7 @@ function CustomerOpeningBalanceFormProvider({
// State provider. // State provider.
const provider = { const provider = {
branches, branches,
customer: { customer: transfromCustomertoForm(customer),
...pick(customer, [
'id',
'opening_balance',
'opening_balance_exchange_rate',
'currency_code',
]),
// opening_balance_at: customer.formatted_opening_balance_at,
},
isBranchesSuccess, isBranchesSuccess,
isBranchesLoading, isBranchesLoading,

View File

@@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import { useFormikContext } from 'formik'; import { useFormikContext } from 'formik';
import { first } from 'lodash'; import { first, pick } from 'lodash';
import { useCustomerOpeningBalanceContext } from './CustomerOpeningBalanceFormProvider'; import { useCustomerOpeningBalanceContext } from './CustomerOpeningBalanceFormProvider';
@@ -18,3 +18,14 @@ export const useSetPrimaryBranchToForm = () => {
} }
}, [isBranchesSuccess, setFieldValue, branches]); }, [isBranchesSuccess, setFieldValue, branches]);
}; };
export function transfromCustomertoForm(values) {
return {
...pick(values, [
'id',
'opening_balance',
'opening_balance_exchange_rate',
'currency_code',
]),
};
}

View File

@@ -7,7 +7,7 @@ import {
} from 'hooks/query'; } from 'hooks/query';
import { useFeatureCan } from 'hooks/state'; import { useFeatureCan } from 'hooks/state';
import { Features } from 'common'; import { Features } from 'common';
import { pick, defaultTo } from 'lodash'; import { transfromVendorToForm } from './utils';
const VendorOpeningBalanceContext = React.createContext(); const VendorOpeningBalanceContext = React.createContext();
@@ -43,15 +43,7 @@ function VendorOpeningBalanceFormProvider({
// State provider. // State provider.
const provider = { const provider = {
branches, branches,
vendor: { vendor: transfromVendorToForm(vendor),
...pick(vendor, [
'id',
'opening_balance',
'opening_balance_exchange_rate',
'currency_code',
]),
},
isBranchesSuccess, isBranchesSuccess,
isBranchesLoading, isBranchesLoading,
dialogName, dialogName,

View File

@@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import { useFormikContext } from 'formik'; import { useFormikContext } from 'formik';
import { first } from 'lodash'; import { first, pick } from 'lodash';
import { useVendorOpeningBalanceContext } from './VendorOpeningBalanceFormProvider'; import { useVendorOpeningBalanceContext } from './VendorOpeningBalanceFormProvider';
@@ -18,3 +18,14 @@ export const useSetPrimaryBranchToForm = () => {
} }
}, [isBranchesSuccess, setFieldValue, branches]); }, [isBranchesSuccess, setFieldValue, branches]);
}; };
export function transfromVendorToForm(values) {
return {
...pick(values, [
'id',
'opening_balance',
'opening_balance_exchange_rate',
'currency_code',
]),
};
}