Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: manage company in data fetching in stock #851

Merged
merged 3 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelogs/unreleased/88463.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"title": "Data fetching: add active company management",
"type": "refactor",
"packages": "stock"
}
2 changes: 2 additions & 0 deletions packages/apps/stock/src/api/customer-delivery-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions packages/apps/stock/src/api/internal-move-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions packages/apps/stock/src/api/inventory-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
12 changes: 10 additions & 2 deletions packages/apps/stock/src/api/partner-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,27 @@ 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,
provider: 'model',
});
}

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,
Expand Down
36 changes: 23 additions & 13 deletions packages/apps/stock/src/api/product-indicators-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const createStockQtyCriteria = (
isAllocatedQty,
productId,
stockLocationId,
companyId,
) => {
const criteria = [
{
Expand Down Expand Up @@ -64,14 +63,6 @@ const createStockQtyCriteria = (
});
}

if (companyId != null) {
criteria.push({
fieldName: 'stockMove.company.id',
operator: '=',
value: companyId,
});
}

return criteria;
};

Expand Down Expand Up @@ -174,42 +165,61 @@ export async function fetchStockQtyIndicator({
}) {
return createStandardSearch({
model: 'com.axelor.apps.stock.db.StockMoveLine',
companyId,
companyFieldName: 'stockMove.company',
vhu-axelor marked this conversation as resolved.
Show resolved Hide resolved
criteria: createStockQtyCriteria(
status,
isAllocatedQty,
productId,
stockLocationId,
companyId,
),
fieldKey: 'stock_stockQtyIndicator',
page,
provider: 'model',
});
}

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,
provider: 'model',
});
}

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,
provider: 'model',
});
}

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,
Expand Down
18 changes: 3 additions & 15 deletions packages/apps/stock/src/api/stock-location-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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',
Expand All @@ -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,
}),
Expand Down
13 changes: 3 additions & 10 deletions packages/apps/stock/src/api/stock-location-line-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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;
Expand All @@ -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,
}),
Expand Down
2 changes: 2 additions & 0 deletions packages/apps/stock/src/api/supplier-arrival-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/stock/src/features/internalMoveSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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] =
Expand Down Expand Up @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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 (
Expand Down