From 2b5d02b579690c1f4406d37e718d6518050e4625 Mon Sep 17 00:00:00 2001 From: vhu-axelor <146069039+vhu-axelor@users.noreply.github.com> Date: Fri, 20 Dec 2024 11:13:57 +0100 Subject: [PATCH] feat: add split lines on customer delivery (#842) * RM#88324 --- changelogs/unreleased/88324.json | 5 + .../src/api/customer-delivery-line-api.js | 9 ++ packages/apps/stock/src/api/index.ts | 3 +- .../CustomerDeliveryLineActionCard.tsx | 116 ++++++++++++++++++ .../CustomerDeliveryLineCard.tsx | 2 + .../CustomerDeliverySearchLineContainer.js | 29 ++--- .../templates/customerDelivery/index.js | 1 + .../src/features/asyncFunctions-index.ts | 1 + .../src/features/customerDeliveryLineSlice.js | 22 +++- packages/apps/stock/src/i18n/en.json | 3 +- packages/apps/stock/src/i18n/fr.json | 3 +- .../CustomerDeliveryLineListScreen.js | 28 ++--- 12 files changed, 175 insertions(+), 47 deletions(-) create mode 100644 changelogs/unreleased/88324.json create mode 100644 packages/apps/stock/src/components/templates/customerDelivery/CustomerDeliveryLineActionCard/CustomerDeliveryLineActionCard.tsx diff --git a/changelogs/unreleased/88324.json b/changelogs/unreleased/88324.json new file mode 100644 index 0000000000..6367dad398 --- /dev/null +++ b/changelogs/unreleased/88324.json @@ -0,0 +1,5 @@ +{ + "title": "Customer delivery: add button to split lines", + "type": "feat", + "packages": "stock" +} diff --git a/packages/apps/stock/src/api/customer-delivery-line-api.js b/packages/apps/stock/src/api/customer-delivery-line-api.js index 82035db913..3032dec64b 100644 --- a/packages/apps/stock/src/api/customer-delivery-line-api.js +++ b/packages/apps/stock/src/api/customer-delivery-line-api.js @@ -82,3 +82,12 @@ export async function fetchCustomerDeliveryLine({customerDeliveryLineId}) { provider: 'model', }); } + +export async function splitCustomerDeliveryLine({id, version}) { + return getActionApi().send({ + url: `ws/aos/stock-move-line/split/${id}`, + method: 'put', + body: {version}, + description: 'split customer delivery line', + }); +} diff --git a/packages/apps/stock/src/api/index.ts b/packages/apps/stock/src/api/index.ts index bcfec573e9..95f3c2cd6d 100644 --- a/packages/apps/stock/src/api/index.ts +++ b/packages/apps/stock/src/api/index.ts @@ -23,9 +23,10 @@ export { searchDeliveryFilter, } from './customer-delivery-api'; export { + fetchCustomerDeliveryLine as fetchCustomerDeliveryLineApi, searchCustomerDeliveryLines, + splitCustomerDeliveryLine as splitCustomerDeliveryLineApi, updateLine as updateCustomerDeliveryLineApi, - fetchCustomerDeliveryLine as fetchCustomerDeliveryLineApi, } from './customer-delivery-line-api'; export { createInternalStockMove, diff --git a/packages/apps/stock/src/components/templates/customerDelivery/CustomerDeliveryLineActionCard/CustomerDeliveryLineActionCard.tsx b/packages/apps/stock/src/components/templates/customerDelivery/CustomerDeliveryLineActionCard/CustomerDeliveryLineActionCard.tsx new file mode 100644 index 0000000000..1ff0cd839f --- /dev/null +++ b/packages/apps/stock/src/components/templates/customerDelivery/CustomerDeliveryLineActionCard/CustomerDeliveryLineActionCard.tsx @@ -0,0 +1,116 @@ +/* + * Axelor Business Solutions + * + * Copyright (C) 2024 Axelor (). + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +import React, {useCallback, useMemo} from 'react'; +import {ActionCard} from '@axelor/aos-mobile-ui'; +import { + useDispatch, + useSelector, + useTranslator, + useTypes, +} from '@axelor/aos-mobile-core'; +import {StockMoveLine} from '../../../../types'; +import {splitCustomerDeliveryLine} from '../../../../features/customerDeliveryLineSlice'; +import CustomerDeliveryLineCard from '../CustomerDeliveryLineCard/CustomerDeliveryLineCard'; + +interface CustomerDeliveryLineActionCardProps { + style?: any; + styleCard?: any; + customerDeliveryLine: any; + handleShowLine: (customerDeliveryLine: any) => void; +} + +const CustomerDeliveryLineActionCard = ({ + style, + styleCard, + customerDeliveryLine, + handleShowLine, +}: CustomerDeliveryLineActionCardProps) => { + const I18n = useTranslator(); + const dispatch = useDispatch(); + const {StockMove} = useTypes(); + + const {customerDelivery} = useSelector(state => state.customerDelivery); + + const splitCustomerDeliveryLineAPI = useCallback(() => { + dispatch( + (splitCustomerDeliveryLine as any)({ + id: customerDeliveryLine.id, + version: customerDeliveryLine.version, + customerDeliveryId: customerDelivery?.id, + }), + ); + }, [ + dispatch, + customerDeliveryLine.id, + customerDeliveryLine.version, + customerDelivery?.id, + ]); + + const pickedQty = useMemo( + () => + StockMoveLine.hideLineQty(customerDeliveryLine, customerDelivery) + ? 0 + : Number(customerDeliveryLine.realQty), + [customerDelivery, customerDeliveryLine], + ); + + const availability = useMemo( + () => + customerDelivery.statusSelect !== StockMove?.statusSelect.Realized + ? customerDeliveryLine.availableStatusSelect + : null, + [ + StockMove?.statusSelect.Realized, + customerDelivery.statusSelect, + customerDeliveryLine.availableStatusSelect, + ], + ); + + return ( + StockMove?.statusSelect.Planned || + pickedQty >= customerDeliveryLine.qty || + pickedQty === 0, + }, + ]}> + handleShowLine(customerDeliveryLine)} + /> + + ); +}; + +export default CustomerDeliveryLineActionCard; diff --git a/packages/apps/stock/src/components/templates/customerDelivery/CustomerDeliveryLineCard/CustomerDeliveryLineCard.tsx b/packages/apps/stock/src/components/templates/customerDelivery/CustomerDeliveryLineCard/CustomerDeliveryLineCard.tsx index 6e72271c22..c36c4a1ed8 100644 --- a/packages/apps/stock/src/components/templates/customerDelivery/CustomerDeliveryLineCard/CustomerDeliveryLineCard.tsx +++ b/packages/apps/stock/src/components/templates/customerDelivery/CustomerDeliveryLineCard/CustomerDeliveryLineCard.tsx @@ -149,6 +149,8 @@ const getStyles = color => borderWidth: 1.5, borderColor: color, paddingRight: 5, + marginVertical: 2, + marginHorizontal: 2, }, textWidth: { width: '85%', diff --git a/packages/apps/stock/src/components/templates/customerDelivery/CustomerDeliverySearchLineContainer/CustomerDeliverySearchLineContainer.js b/packages/apps/stock/src/components/templates/customerDelivery/CustomerDeliverySearchLineContainer/CustomerDeliverySearchLineContainer.js index a0670ab01a..20352c9789 100644 --- a/packages/apps/stock/src/components/templates/customerDelivery/CustomerDeliverySearchLineContainer/CustomerDeliverySearchLineContainer.js +++ b/packages/apps/stock/src/components/templates/customerDelivery/CustomerDeliverySearchLineContainer/CustomerDeliverySearchLineContainer.js @@ -26,10 +26,9 @@ import { useTranslator, useTypes, } from '@axelor/aos-mobile-core'; -import {CustomerDeliveryLineCard} from '../../../templates'; +import {CustomerDeliveryLineActionCard} from '../../../templates'; import {SearchLineContainer} from '../../../organisms'; import {showLine} from '../../../../utils/line-navigation'; -import {StockMoveLine} from '../../../../types'; import {fetchCustomerDeliveryLines} from '../../../../features/customerDeliveryLineSlice'; import {useCustomerLinesWithRacks} from '../../../../hooks'; @@ -138,23 +137,10 @@ const CustomerDeliverySearchLineContainer = ({}) => { showAction={showLineAdditionIcon} onAction={handleNewLine} renderItem={item => ( - handleShowLine(item)} + )} /> @@ -162,9 +148,8 @@ const CustomerDeliverySearchLineContainer = ({}) => { }; const styles = StyleSheet.create({ - item: { - marginHorizontal: 1, - marginVertical: 4, + card: { + width: '100%', }, }); diff --git a/packages/apps/stock/src/components/templates/customerDelivery/index.js b/packages/apps/stock/src/components/templates/customerDelivery/index.js index 2b10eb8c75..c548802979 100644 --- a/packages/apps/stock/src/components/templates/customerDelivery/index.js +++ b/packages/apps/stock/src/components/templates/customerDelivery/index.js @@ -18,6 +18,7 @@ export {default as CustomerDeliveryCard} from './CustomerDeliveryCard/CustomerDeliveryCard'; export {default as CustomerDeliveryHeader} from './CustomerDeliveryHeader/CustomerDeliveryHeader'; +export {default as CustomerDeliveryLineActionCard} from './CustomerDeliveryLineActionCard/CustomerDeliveryLineActionCard'; export {default as CustomerDeliveryLineButtons} from './CustomerDeliveryLineButtons/CustomerDeliveryLineButtons'; export {default as CustomerDeliveryLineCard} from './CustomerDeliveryLineCard/CustomerDeliveryLineCard'; export {default as CustomerDeliveryLineCreationButton} from './CustomerDeliveryLineCreationButton/CustomerDeliveryLineCreationButton'; diff --git a/packages/apps/stock/src/features/asyncFunctions-index.ts b/packages/apps/stock/src/features/asyncFunctions-index.ts index 824e2812bf..327e9192e5 100644 --- a/packages/apps/stock/src/features/asyncFunctions-index.ts +++ b/packages/apps/stock/src/features/asyncFunctions-index.ts @@ -20,6 +20,7 @@ export { addTrackingNumber as addTrackingNumberToCustomerDeliveryLine, fetchCustomerDeliveryLine, fetchCustomerDeliveryLines, + splitCustomerDeliveryLine, updateCustomerDeliveryLine, } from './customerDeliveryLineSlice'; export { diff --git a/packages/apps/stock/src/features/customerDeliveryLineSlice.js b/packages/apps/stock/src/features/customerDeliveryLineSlice.js index c43f645cba..7e7667777b 100644 --- a/packages/apps/stock/src/features/customerDeliveryLineSlice.js +++ b/packages/apps/stock/src/features/customerDeliveryLineSlice.js @@ -23,9 +23,10 @@ import { updateAgendaItems, } from '@axelor/aos-mobile-core'; import { + fetchCustomerDeliveryLine as _fetchCustomerDeliveryLine, searchCustomerDeliveryLines, + splitCustomerDeliveryLine as _splitCustomerDeliveryLine, updateLine, - fetchCustomerDeliveryLine as _fetchCustomerDeliveryLine, } from '../api/customer-delivery-line-api'; import {updateStockMoveLineTrackingNumber} from '../api/tracking-number-api'; @@ -97,6 +98,25 @@ export const addTrackingNumber = createAsyncThunk( }, ); +export const splitCustomerDeliveryLine = createAsyncThunk( + 'stock_customerDeliveryLine/splitCustomerDeliveryLine', + async function (data, {getState, dispatch}) { + return handlerApiCall({ + fetchFunction: _splitCustomerDeliveryLine, + data, + action: 'Stock_SliceAction_SplitCustomerDeliveryLine', + getState, + responseOptions: {showToast: true}, + }).then(() => { + dispatch( + fetchCustomerDeliveryLines({ + customerDeliveryId: data.customerDeliveryId, + }), + ); + }); + }, +); + const initialState = { loadingCDLinesList: false, moreLoading: false, diff --git a/packages/apps/stock/src/i18n/en.json b/packages/apps/stock/src/i18n/en.json index 83041b2d70..ea3f19325c 100644 --- a/packages/apps/stock/src/i18n/en.json +++ b/packages/apps/stock/src/i18n/en.json @@ -185,5 +185,6 @@ "Stock_SliceAction_FetchSaleOrderQtyIndicator": "fetch data of sale order quantity indicator", "Stock_SliceAction_FetchPurchaseOrderQtyIndicator": "fetch data of purchase order quantity indicator", "Stock_SliceAction_FetchAvailableStockIndicator": "fetch data of available stock indicator", - "Stock_SliceAction_SplitSupplierArrivalLine": "split supplier arrival line" + "Stock_SliceAction_SplitSupplierArrivalLine": "split supplier arrival line", + "Stock_SliceAction_SplitCustomerDeliveryLine": "split customer delivery line" } diff --git a/packages/apps/stock/src/i18n/fr.json b/packages/apps/stock/src/i18n/fr.json index 63e3427427..9bad8df66c 100644 --- a/packages/apps/stock/src/i18n/fr.json +++ b/packages/apps/stock/src/i18n/fr.json @@ -185,5 +185,6 @@ "Stock_SliceAction_FetchSaleOrderQtyIndicator": "récupération des données de l'indicateur sur la quantité en commande client", "Stock_SliceAction_FetchPurchaseOrderQtyIndicator": "récupération des données de l'indicateur sur la quantité en ordre d'achat", "Stock_SliceAction_FetchAvailableStockIndicator": "récupération des données de l'indicateur sur le stock disponible", - "Stock_SliceAction_SplitSupplierArrivalLine": "séparation de la ligne de réception fournisseur" + "Stock_SliceAction_SplitSupplierArrivalLine": "séparation de la ligne de réception fournisseur", + "Stock_SliceAction_SplitCustomerDeliveryLine": "séparation de la ligne de livraison client" } diff --git a/packages/apps/stock/src/screens/customerDeliveries/CustomerDeliveryLineListScreen.js b/packages/apps/stock/src/screens/customerDeliveries/CustomerDeliveryLineListScreen.js index 5ac31c36fa..7c921ad342 100644 --- a/packages/apps/stock/src/screens/customerDeliveries/CustomerDeliveryLineListScreen.js +++ b/packages/apps/stock/src/screens/customerDeliveries/CustomerDeliveryLineListScreen.js @@ -22,9 +22,11 @@ import { SearchListView, useSelector, useTranslator, - useTypes, } from '@axelor/aos-mobile-core'; -import {CustomerDeliveryLineCard, StockMoveHeader} from '../../components'; +import { + CustomerDeliveryLineActionCard, + StockMoveHeader, +} from '../../components'; import {fetchCustomerDeliveryLines} from '../../features/customerDeliveryLineSlice'; import {StockMove as StockMoveType, StockMoveLine} from '../../types'; import {showLine} from '../../utils/line-navigation'; @@ -37,7 +39,6 @@ const CustomerDeliveryLineListScreen = ({route, navigation}) => { const customerDelivery = route.params.customerDelivery; const Colors = useThemeColor(); const I18n = useTranslator(); - const {StockMove} = useTypes(); const {mobileSettings} = useSelector(state => state.appConfig); const {customerDeliveryLineList} = @@ -140,24 +141,9 @@ const CustomerDeliveryLineListScreen = ({route, navigation}) => { /> } renderListItem={({item}) => ( - handleShowLine(item)} + )} />