diff --git a/changelogs/unreleased/88463.json b/changelogs/unreleased/88463.json new file mode 100644 index 0000000000..5c59b7e78e --- /dev/null +++ b/changelogs/unreleased/88463.json @@ -0,0 +1,5 @@ +{ + "title": "Data fetching: add active company management", + "type": "refactor", + "packages": "stock" +} diff --git a/packages/apps/stock/src/api/customer-delivery-api.js b/packages/apps/stock/src/api/customer-delivery-api.js index 5392e6776b..6911deb180 100644 --- a/packages/apps/stock/src/api/customer-delivery-api.js +++ b/packages/apps/stock/src/api/customer-delivery-api.js @@ -96,10 +96,12 @@ export async function searchDeliveryFilter({ fromStockLocationId, partnerId, statusList, + companyId, page = 0, }) { return createStandardSearch({ model: 'com.axelor.apps.stock.db.StockMove', + companyId, criteria: createSearchCriteria( searchValue, fromStockLocationId, diff --git a/packages/apps/stock/src/api/internal-move-api.js b/packages/apps/stock/src/api/internal-move-api.js index 17c0025187..f35c67fcec 100644 --- a/packages/apps/stock/src/api/internal-move-api.js +++ b/packages/apps/stock/src/api/internal-move-api.js @@ -87,10 +87,12 @@ export async function searchInternalMoveFilter({ fromStockLocationId, toStockLocationId, statusList, + companyId, page = 0, }) { return createStandardSearch({ model: 'com.axelor.apps.stock.db.StockMove', + companyId, criteria: createSearchCriteria( searchValue, fromStockLocationId, diff --git a/packages/apps/stock/src/api/inventory-api.js b/packages/apps/stock/src/api/inventory-api.js index 09e7a0d8e0..8c34001c5b 100644 --- a/packages/apps/stock/src/api/inventory-api.js +++ b/packages/apps/stock/src/api/inventory-api.js @@ -76,10 +76,12 @@ export async function searchInventoryFilter({ searchValue, stockLocationId, statusList, + companyId, page = 0, }) { return createStandardSearch({ model: 'com.axelor.apps.stock.db.Inventory', + companyId, criteria: createSearchCriteria(searchValue, stockLocationId, statusList), fieldKey: 'stock_inventory', sortKey: 'stock_inventory', diff --git a/packages/apps/stock/src/api/partner-api.js b/packages/apps/stock/src/api/partner-api.js index 7e65377967..772c968fa5 100644 --- a/packages/apps/stock/src/api/partner-api.js +++ b/packages/apps/stock/src/api/partner-api.js @@ -58,9 +58,15 @@ const createSearchCriteria = (searchValue, isSupplier) => { return criteria; }; -export async function searchSuppliersFilter({searchValue, page = 0}) { +export async function searchSuppliersFilter({ + searchValue, + companyId, + page = 0, +}) { return createStandardSearch({ model: 'com.axelor.apps.base.db.Partner', + companyId, + isCompanyM2M: true, criteria: createSearchCriteria(searchValue, true), fieldKey: 'stock_partner', page, @@ -68,9 +74,11 @@ export async function searchSuppliersFilter({searchValue, page = 0}) { }); } -export async function searchClientsFilter({searchValue, page = 0}) { +export async function searchClientsFilter({searchValue, companyId, page = 0}) { return createStandardSearch({ model: 'com.axelor.apps.base.db.Partner', + companyId, + isCompanyM2M: true, criteria: createSearchCriteria(searchValue, false), fieldKey: 'stock_partner', page, diff --git a/packages/apps/stock/src/api/product-indicators-api.js b/packages/apps/stock/src/api/product-indicators-api.js index f530011a34..ee92769af0 100644 --- a/packages/apps/stock/src/api/product-indicators-api.js +++ b/packages/apps/stock/src/api/product-indicators-api.js @@ -23,7 +23,6 @@ const createStockQtyCriteria = ( isAllocatedQty, productId, stockLocationId, - companyId, ) => { const criteria = [ { @@ -64,14 +63,6 @@ const createStockQtyCriteria = ( }); } - if (companyId != null) { - criteria.push({ - fieldName: 'stockMove.company.id', - operator: '=', - value: companyId, - }); - } - return criteria; }; @@ -174,12 +165,13 @@ export async function fetchStockQtyIndicator({ }) { return createStandardSearch({ model: 'com.axelor.apps.stock.db.StockMoveLine', + companyId, + companyFieldName: 'stockMove.company', criteria: createStockQtyCriteria( status, isAllocatedQty, productId, stockLocationId, - companyId, ), fieldKey: 'stock_stockQtyIndicator', page, @@ -187,9 +179,15 @@ export async function fetchStockQtyIndicator({ }); } -export async function fetchSaleOrderQtyIndicator({productId, page = 0}) { +export async function fetchSaleOrderQtyIndicator({ + productId, + companyId, + page = 0, +}) { return createStandardSearch({ model: 'com.axelor.apps.sale.db.SaleOrderLine', + companyId, + companyFieldName: 'saleOrder.company', criteria: createSaleOrderQtyCriteria(productId), fieldKey: 'stock_saleOrderQtyIndicator', page, @@ -197,9 +195,15 @@ export async function fetchSaleOrderQtyIndicator({productId, page = 0}) { }); } -export async function fetchPurchaseOrderQtyIndicator({productId, page = 0}) { +export async function fetchPurchaseOrderQtyIndicator({ + productId, + companyId, + page = 0, +}) { return createStandardSearch({ model: 'com.axelor.apps.purchase.db.PurchaseOrderLine', + companyId, + companyFieldName: 'purchaseOrder.company', criteria: createPurchaseOrderQtyCriteria(productId), fieldKey: 'stock_purchaseOrderQtyIndicator', page, @@ -207,9 +211,15 @@ export async function fetchPurchaseOrderQtyIndicator({productId, page = 0}) { }); } -export async function fetchAvailableStockIndicator({productId, page = 0}) { +export async function fetchAvailableStockIndicator({ + productId, + companyId, + page = 0, +}) { return createStandardSearch({ model: 'com.axelor.apps.stock.db.StockLocationLine', + companyId, + companyFieldName: 'stockLocation.company', criteria: createAvailableStockCriteria(productId), fieldKey: 'stock_stockLocationLine', page, diff --git a/packages/apps/stock/src/api/stock-location-api.js b/packages/apps/stock/src/api/stock-location-api.js index 5d3e28e381..44a5499e89 100644 --- a/packages/apps/stock/src/api/stock-location-api.js +++ b/packages/apps/stock/src/api/stock-location-api.js @@ -22,11 +22,7 @@ import { getTypes, } from '@axelor/aos-mobile-core'; -const createSearchCriteria = ({ - companyId, - searchValue, - defaultStockLocation, -}) => { +const createSearchCriteria = ({searchValue, defaultStockLocation}) => { const StockLocation = getTypes().StockLocation; let criterias = [ @@ -38,14 +34,6 @@ const createSearchCriteria = ({ getSearchCriterias('stock_stockLocation', searchValue), ]; - if (companyId != null) { - criterias.push({ - fieldName: 'company.id', - operator: '=', - value: companyId, - }); - } - if (defaultStockLocation != null) { criterias.push({ operator: 'or', @@ -69,14 +57,14 @@ const createSearchCriteria = ({ export async function searchStockLocationsFilter({ searchValue = null, - companyId = null, + companyId, defaultStockLocation = null, page = 0, }) { return createStandardSearch({ model: 'com.axelor.apps.stock.db.StockLocation', + companyId, criteria: createSearchCriteria({ - companyId: companyId, searchValue: searchValue, defaultStockLocation: defaultStockLocation, }), diff --git a/packages/apps/stock/src/api/stock-location-line-api.js b/packages/apps/stock/src/api/stock-location-line-api.js index 39dafa7454..bef1eff660 100644 --- a/packages/apps/stock/src/api/stock-location-line-api.js +++ b/packages/apps/stock/src/api/stock-location-line-api.js @@ -22,7 +22,7 @@ import { getTypes, } from '@axelor/aos-mobile-core'; -const createSearchCriteria = ({productId, companyId, stockLocationId}) => { +const createSearchCriteria = ({productId, stockLocationId}) => { const StockLocation = getTypes().StockLocation; let criterias = [ @@ -45,14 +45,6 @@ const createSearchCriteria = ({productId, companyId, stockLocationId}) => { operator: '=', value: StockLocation?.typeSelect.internal, }); - - if (companyId != null) { - criterias.push({ - fieldName: 'stockLocation.company.id', - operator: '=', - value: companyId, - }); - } } return criterias; @@ -66,8 +58,9 @@ export async function searchStockLocationLine({ }) { return createStandardSearch({ model: 'com.axelor.apps.stock.db.StockLocationLine', + companyId, + companyFieldName: 'stockLocation.company', criteria: createSearchCriteria({ - companyId: companyId, productId: productId, stockLocationId: stockId, }), diff --git a/packages/apps/stock/src/api/supplier-arrival-api.js b/packages/apps/stock/src/api/supplier-arrival-api.js index 493a652af8..6088aaa875 100644 --- a/packages/apps/stock/src/api/supplier-arrival-api.js +++ b/packages/apps/stock/src/api/supplier-arrival-api.js @@ -96,10 +96,12 @@ export async function searchSupplierArrivalFilter({ toStockLocationId, partnerId, statusList, + companyId, page = 0, }) { return createStandardSearch({ model: 'com.axelor.apps.stock.db.StockMove', + companyId, criteria: createSearchCriteria( searchValue, toStockLocationId, diff --git a/packages/apps/stock/src/components/templates/PartnerSearchBar/PartnerSearchBar.js b/packages/apps/stock/src/components/templates/PartnerSearchBar/PartnerSearchBar.js index 37db6a7930..7f23f649c2 100644 --- a/packages/apps/stock/src/components/templates/PartnerSearchBar/PartnerSearchBar.js +++ b/packages/apps/stock/src/components/templates/PartnerSearchBar/PartnerSearchBar.js @@ -34,19 +34,24 @@ const PartnerSearchBar = ({ const {loadingPartners, moreLoading, isListEnd, clientList, supplierList} = useSelector(state => state.stock_partner); + const {user} = useSelector(state => state.user); const fetchClientsAPI = useCallback( ({page = 0, searchValue}) => { - dispatch(filterClients({page, searchValue})); + dispatch( + filterClients({page, searchValue, companyId: user.activeCompany?.id}), + ); }, - [dispatch], + [dispatch, user.activeCompany?.id], ); const fetchSuppliersAPI = useCallback( ({page = 0, searchValue}) => { - dispatch(filterSuppliers({page, searchValue})); + dispatch( + filterSuppliers({page, searchValue, companyId: user.activeCompany?.id}), + ); }, - [dispatch], + [dispatch, user.activeCompany?.id], ); return ( diff --git a/packages/apps/stock/src/features/internalMoveSlice.js b/packages/apps/stock/src/features/internalMoveSlice.js index 254f8a574f..407f9df96e 100644 --- a/packages/apps/stock/src/features/internalMoveSlice.js +++ b/packages/apps/stock/src/features/internalMoveSlice.js @@ -86,7 +86,7 @@ export const createInternalMove = createAsyncThunk( .then(() => handlerApiCall({ fetchFunction: searchInternalMoveFilter, - data: {}, + data: {companyId: data.companyId}, action: 'Stock_SliceAction_FilterInternalMoves', getState, responseOptions: {isArrayResponse: true}, diff --git a/packages/apps/stock/src/screens/customerDeliveries/CustomerDeliveryListScreen.js b/packages/apps/stock/src/screens/customerDeliveries/CustomerDeliveryListScreen.js index 3ec8cc02d4..bfab5449d1 100644 --- a/packages/apps/stock/src/screens/customerDeliveries/CustomerDeliveryListScreen.js +++ b/packages/apps/stock/src/screens/customerDeliveries/CustomerDeliveryListScreen.js @@ -43,6 +43,7 @@ const CustomerDeliveryListScreen = ({navigation}) => { const {loadingList, moreLoading, isListEnd, deliveryList} = useSelector( state => state.customerDelivery, ); + const {user} = useSelector(state => state.user); const [stockLocation, setStockLocation] = useState(null); const [customer, setCustomer] = useState(null); @@ -74,8 +75,9 @@ const CustomerDeliveryListScreen = ({navigation}) => { fromStockLocationId: stockLocation?.id, partnerId: customer?.id, statusList: selectedStatus, + companyId: user.activeCompany?.id, }), - [customer?.id, selectedStatus, stockLocation?.id], + [customer?.id, selectedStatus, stockLocation?.id, user.activeCompany?.id], ); return ( diff --git a/packages/apps/stock/src/screens/internalMoves/InternalMoveListScreen.js b/packages/apps/stock/src/screens/internalMoves/InternalMoveListScreen.js index 39d72d846d..349273b19c 100644 --- a/packages/apps/stock/src/screens/internalMoves/InternalMoveListScreen.js +++ b/packages/apps/stock/src/screens/internalMoves/InternalMoveListScreen.js @@ -42,6 +42,7 @@ const InternalMoveListScreen = ({navigation}) => { const {loadingInternalMoveList, moreLoading, isListEnd, internalMoveList} = useSelector(state => state.internalMove); + const {user} = useSelector(state => state.user); const [originalStockLocation, setOriginalStockLocation] = useState(null); const [destinationStockLocation, setDestinationStockLocation] = @@ -75,8 +76,14 @@ const InternalMoveListScreen = ({navigation}) => { fromStockLocationId: originalStockLocation?.id, toStockLocationId: destinationStockLocation?.id, statusList: selectedStatus, + companyId: user.activeCompany?.id, }), - [destinationStockLocation?.id, originalStockLocation?.id, selectedStatus], + [ + destinationStockLocation?.id, + originalStockLocation?.id, + selectedStatus, + user.activeCompany?.id, + ], ); return ( diff --git a/packages/apps/stock/src/screens/inventories/InventoryListScreen.js b/packages/apps/stock/src/screens/inventories/InventoryListScreen.js index 6600f4a555..0460a29c68 100644 --- a/packages/apps/stock/src/screens/inventories/InventoryListScreen.js +++ b/packages/apps/stock/src/screens/inventories/InventoryListScreen.js @@ -40,6 +40,7 @@ const InventoryListScreen = ({navigation}) => { const {loadingList, moreLoading, isListEnd, inventoryList} = useSelector( state => state.inventory, ); + const {user} = useSelector(state => state.user); const [stockLocation, setStockLocation] = useState(null); const [navigate, setNavigate] = useState(false); @@ -66,8 +67,9 @@ const InventoryListScreen = ({navigation}) => { () => ({ stockLocationId: stockLocation?.id, statusList: selectedStatus, + companyId: user.activeCompany?.id, }), - [selectedStatus, stockLocation?.id], + [selectedStatus, stockLocation?.id, user.activeCompany?.id], ); return ( diff --git a/packages/apps/stock/src/screens/products/ProductStockIndicatorDetails.tsx b/packages/apps/stock/src/screens/products/ProductStockIndicatorDetails.tsx index 7a0660a196..c8bdb20fe1 100644 --- a/packages/apps/stock/src/screens/products/ProductStockIndicatorDetails.tsx +++ b/packages/apps/stock/src/screens/products/ProductStockIndicatorDetails.tsx @@ -145,9 +145,11 @@ const ProductStockIndicatorDetails = ({route}) => { return null; } - dispatch((sliceFunction as any)({productId: product?.id, page})); + dispatch( + (sliceFunction as any)({productId: product?.id, companyId, page}), + ); }, - [dispatch, indicatorType, product?.id], + [dispatch, indicatorType, product?.id, companyId], ); const scrollListData = useMemo(() => { diff --git a/packages/apps/stock/src/screens/supplierArrivals/SupplierArrivalListScreen.js b/packages/apps/stock/src/screens/supplierArrivals/SupplierArrivalListScreen.js index 61e33616f2..db23c8ddcc 100644 --- a/packages/apps/stock/src/screens/supplierArrivals/SupplierArrivalListScreen.js +++ b/packages/apps/stock/src/screens/supplierArrivals/SupplierArrivalListScreen.js @@ -42,6 +42,7 @@ const SupplierArrivalListScreen = ({navigation}) => { const {loadingList, moreLoading, isListEnd, supplierArrivalsList} = useSelector(state => state.supplierArrival); + const {user} = useSelector(state => state.user); const [stockLocation, setStockLocation] = useState(null); const [partner, setPartner] = useState(null); @@ -73,8 +74,9 @@ const SupplierArrivalListScreen = ({navigation}) => { toStockLocationId: stockLocation?.id, partnerId: partner?.id, statusList: selectedStatus, + companyId: user.activeCompany?.id, }), - [partner?.id, selectedStatus, stockLocation?.id], + [partner?.id, selectedStatus, stockLocation?.id, user.activeCompany?.id], ); return (