mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 14:20:31 +00:00
fix(WarehouseTransfer).
This commit is contained in:
@@ -37,7 +37,7 @@ export default function WarehouseTransferEditorField() {
|
||||
defaultEntry={defaultWarehouseTransferEntry}
|
||||
errors={error}
|
||||
sourceWarehouseId={values.from_warehouse_id}
|
||||
distentionWarehouseId={value.to_warehouse_id}
|
||||
destinationWarehouseId={values.to_warehouse_id}
|
||||
/>
|
||||
)}
|
||||
</FastField>
|
||||
|
||||
@@ -20,9 +20,10 @@ import WarehouseTransferFormDialog from './WarehouseTransferFormDialog';
|
||||
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
|
||||
import withSettings from 'containers/Settings/withSettings';
|
||||
|
||||
import { AppToaster } from 'components';
|
||||
import { AppToaster, } from 'components';
|
||||
import { useWarehouseTransferFormContext } from './WarehouseTransferFormProvider';
|
||||
import { compose, orderingLinesIndexes, transactionNumber } from 'utils';
|
||||
import { WarehouseTransferObserveItemsCost } from './components';
|
||||
import {
|
||||
defaultWarehouseTransfer,
|
||||
transformValueToRequest,
|
||||
@@ -37,13 +38,14 @@ function WarehouseTransferForm({
|
||||
warehouseTransferIncrementMode,
|
||||
}) {
|
||||
const history = useHistory();
|
||||
|
||||
|
||||
const {
|
||||
isNewMode,
|
||||
warehouseTransfer,
|
||||
createWarehouseTransferMutate,
|
||||
editWarehouseTransferMutate,
|
||||
submitPayload,
|
||||
setItemCostQuery,
|
||||
} = useWarehouseTransferFormContext();
|
||||
|
||||
// WarehouseTransfer number.
|
||||
@@ -118,7 +120,7 @@ function WarehouseTransferForm({
|
||||
.catch(onError);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return (
|
||||
<div
|
||||
className={classNames(
|
||||
@@ -140,16 +142,18 @@ function WarehouseTransferForm({
|
||||
<WarehouseTransferFormFooter />
|
||||
<WarehouseTransferFormDialog />
|
||||
<WarehouseTransferFloatingActions />
|
||||
<WarehouseTransferObserveItemsCost />
|
||||
</Form>
|
||||
</Formik>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(withDashboardActions,
|
||||
export default compose(
|
||||
withDashboardActions,
|
||||
withSettings(({ warehouseTransferSettings }) => ({
|
||||
warehouseTransferNextNumber: warehouseTransferSettings?.nextNumber,
|
||||
warehouseTransferNumberPrefix: warehouseTransferSettings?.numberPrefix,
|
||||
warehouseTransferIncrementMode: warehouseTransferSettings?.autoIncrement,
|
||||
})),
|
||||
)(WarehouseTransferForm);
|
||||
)(WarehouseTransferForm);
|
||||
|
||||
@@ -6,10 +6,12 @@ import {
|
||||
useWarehouseTransfer,
|
||||
useCreateWarehouseTransfer,
|
||||
useEditWarehouseTransfer,
|
||||
useItemInventoryCost,
|
||||
} from 'hooks/query';
|
||||
import { Features } from 'common';
|
||||
import { useFeatureCan } from 'hooks/state';
|
||||
import { ITEMS_FILTER_ROLES_QUERY } from './utils.js';
|
||||
import { isEmpty } from 'lodash';
|
||||
|
||||
const WarehouseFormContext = React.createContext();
|
||||
|
||||
@@ -44,6 +46,23 @@ function WarehouseTransferFormProvider({ warehouseTransferId, ...props }) {
|
||||
isLoading: isWarehouesLoading,
|
||||
} = useWarehouses({}, { enabled: isWarehouseFeatureCan });
|
||||
|
||||
// Inventory items cost query.
|
||||
const [itemCostQuery, setItemCostQuery] = React.useState(null);
|
||||
|
||||
// Detarmines whether the inventory items cost query is enabled.
|
||||
const isItemsCostQueryEnabled =
|
||||
!isEmpty(itemCostQuery?.date) && !isEmpty(itemCostQuery?.itemsIds);
|
||||
|
||||
// Retrieves the inventory item cost.
|
||||
const { data: inventoryItemsCost } = useItemInventoryCost(
|
||||
{
|
||||
date: itemCostQuery?.date,
|
||||
items_ids: itemCostQuery?.itemsIds,
|
||||
},
|
||||
{
|
||||
enabled: isItemsCostQueryEnabled,
|
||||
},
|
||||
);
|
||||
// Create and edit warehouse mutations.
|
||||
const { mutateAsync: createWarehouseTransferMutate } =
|
||||
useCreateWarehouseTransfer();
|
||||
@@ -70,6 +89,10 @@ function WarehouseTransferFormProvider({ warehouseTransferId, ...props }) {
|
||||
setSubmitPayload,
|
||||
createWarehouseTransferMutate,
|
||||
editWarehouseTransferMutate,
|
||||
|
||||
inventoryItemsCost,
|
||||
itemCostQuery,
|
||||
setItemCostQuery,
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import React from 'react';
|
||||
import { FormikObserver } from 'components';
|
||||
import { useWarehouseTransferFormContext } from './WarehouseTransferFormProvider';
|
||||
|
||||
export function WarehouseTransferObserveItemsCost() {
|
||||
const { setItemCostQuery } = useWarehouseTransferFormContext();
|
||||
|
||||
// Handle the form change.
|
||||
const handleFormChange = (values) => {
|
||||
const itemsIds = values.entries
|
||||
.filter((e) => e.item_id)
|
||||
.map((e) => e.item_id);
|
||||
|
||||
setItemCostQuery({
|
||||
date: values.date,
|
||||
itemsIds,
|
||||
});
|
||||
};
|
||||
return <FormikObserver onChange={handleFormChange} />;
|
||||
}
|
||||
@@ -65,10 +65,10 @@ export const useFetchItemWarehouseQuantity = () => {
|
||||
return isItemSuccess
|
||||
? {
|
||||
...tableRow,
|
||||
warehouses: [],
|
||||
warehouses: transformWarehousesQuantity(item),
|
||||
}
|
||||
: null;
|
||||
}, [isItemSuccess, tableRow]);
|
||||
}, [isItemSuccess, item, tableRow]);
|
||||
|
||||
// Reset the table row.
|
||||
const resetTableRow = React.useCallback(() => {
|
||||
@@ -84,3 +84,11 @@ export const useFetchItemWarehouseQuantity = () => {
|
||||
newRowMeta,
|
||||
};
|
||||
};
|
||||
|
||||
const transformWarehousesQuantity = (item) => {
|
||||
return item.item_warehouses.map((warehouse) => ({
|
||||
warehouseId: warehouse.warehouse_id,
|
||||
quantityOnHand: warehouse.quantity_on_hand,
|
||||
quantityOnHandFormatted: warehouse.quantity_on_hand_formatted,
|
||||
}));
|
||||
};
|
||||
|
||||
@@ -22,14 +22,12 @@ import {
|
||||
updateMinEntriesLines,
|
||||
updateRemoveLineByIndex,
|
||||
} from 'utils';
|
||||
|
||||
// import { defaultFastFieldShouldUpdate } from 'utils';
|
||||
import {
|
||||
updateItemsEntriesTotal,
|
||||
ensureEntriesHaveEmptyLine,
|
||||
} from 'containers/Entries/utils';
|
||||
|
||||
export const MIN_LINES_NUMBER = 4;
|
||||
export const MIN_LINES_NUMBER = 1;
|
||||
|
||||
// Default warehouse transfer entry.
|
||||
export const defaultWarehouseTransferEntry = {
|
||||
|
||||
Reference in New Issue
Block a user