From 619755c610196b1ccdc10310493a5ee741fe932c Mon Sep 17 00:00:00 2001
From: vhu-axelor <146069039+vhu-axelor@users.noreply.github.com>
Date: Tue, 11 Feb 2025 14:44:58 +0100
Subject: [PATCH] feat: manage stock location on inventory line requests
---
changelogs/unreleased/88586.json | 5 +++++
packages/apps/stock/src/api/inventory-line-api.js | 11 ++++++++++-
.../InventoryLineButtons/InventoryLineButtons.js | 5 +++++
.../InventoryLineCard/InventoryLineCard.tsx | 7 +++++++
.../InventorySearchLineContainer.js | 1 +
packages/apps/stock/src/models/objectFields.ts | 1 +
.../inventories/InventoryLineDetailsScreen.js | 12 ++++++++++++
.../screens/inventories/InventoryLineListScreen.js | 1 +
8 files changed, 42 insertions(+), 1 deletion(-)
create mode 100644 changelogs/unreleased/88586.json
diff --git a/changelogs/unreleased/88586.json b/changelogs/unreleased/88586.json
new file mode 100644
index 0000000000..68ad1e2299
--- /dev/null
+++ b/changelogs/unreleased/88586.json
@@ -0,0 +1,5 @@
+{
+ "title": "Inventory line: manage stock location",
+ "type": "feat",
+ "packages": "stock"
+}
diff --git a/packages/apps/stock/src/api/inventory-line-api.js b/packages/apps/stock/src/api/inventory-line-api.js
index b220077696..bb4d5cf7e4 100644
--- a/packages/apps/stock/src/api/inventory-line-api.js
+++ b/packages/apps/stock/src/api/inventory-line-api.js
@@ -51,6 +51,7 @@ export async function searchInventoryLines({
export async function updateInventoryLineDetails({
inventoryLineId,
version,
+ stockLocationId,
realQty,
description = null,
}) {
@@ -59,6 +60,7 @@ export async function updateInventoryLineDetails({
method: 'put',
body: {
version,
+ stockLocationId,
realQty,
description,
},
@@ -66,7 +68,11 @@ export async function updateInventoryLineDetails({
matchers: {
modelName: 'com.axelor.apps.stock.db.InventoryLine',
id: inventoryLineId,
- fields: {description, realQty},
+ fields: {
+ stockLocationId: 'stockLocation.id',
+ description,
+ realQty,
+ },
},
});
}
@@ -75,6 +81,7 @@ export async function createInventoryLine({
inventoryId,
inventoryVersion,
productId,
+ stockLocationId = null,
trackingNumberId = null,
rack = null,
realQty,
@@ -86,6 +93,7 @@ export async function createInventoryLine({
inventoryId,
inventoryVersion,
productId,
+ stockLocationId,
trackingNumberId,
rack,
realQty,
@@ -96,6 +104,7 @@ export async function createInventoryLine({
id: Date.now(),
fields: {
productId: 'product.id',
+ stockLocationId: 'stockLocation.id',
trackingNumberId: 'trackingNumber.id',
inventoryId: 'inventory.id',
rack,
diff --git a/packages/apps/stock/src/components/templates/inventory/InventoryLineButtons/InventoryLineButtons.js b/packages/apps/stock/src/components/templates/inventory/InventoryLineButtons/InventoryLineButtons.js
index 5c89dcffa3..744305dc5d 100644
--- a/packages/apps/stock/src/components/templates/inventory/InventoryLineButtons/InventoryLineButtons.js
+++ b/packages/apps/stock/src/components/templates/inventory/InventoryLineButtons/InventoryLineButtons.js
@@ -34,6 +34,7 @@ import {
const InventoryLineButtons = ({
inventoryLine,
inventory,
+ stockLocation,
trackingNumber,
rack,
realQty,
@@ -56,6 +57,7 @@ const InventoryLineButtons = ({
inventoryId: inventory.id,
inventoryVersion: inventory.version,
productId: productFromId?.id,
+ stockLocationId: stockLocation?.id,
trackingNumberId: trackingNumber?.id,
rack: rack == null || rack === '' ? null : rack,
realQty: realQty,
@@ -71,6 +73,7 @@ const InventoryLineButtons = ({
productFromId?.id,
rack,
realQty,
+ stockLocation?.id,
trackingNumber?.id,
]);
@@ -79,6 +82,7 @@ const InventoryLineButtons = ({
updateInventoryLine({
inventoryLineId: inventoryLine?.id,
version: inventoryLine?.version,
+ stockLocationId: stockLocation?.id,
realQty: realQty,
description: description,
inventoryId: inventory?.id,
@@ -93,6 +97,7 @@ const InventoryLineButtons = ({
inventoryLine,
navigation,
realQty,
+ stockLocation?.id,
]);
if (!visible) {
diff --git a/packages/apps/stock/src/components/templates/inventory/InventoryLineCard/InventoryLineCard.tsx b/packages/apps/stock/src/components/templates/inventory/InventoryLineCard/InventoryLineCard.tsx
index 5b67944817..81dc1561ae 100644
--- a/packages/apps/stock/src/components/templates/inventory/InventoryLineCard/InventoryLineCard.tsx
+++ b/packages/apps/stock/src/components/templates/inventory/InventoryLineCard/InventoryLineCard.tsx
@@ -34,6 +34,7 @@ interface InventoryLineCardProps {
unit: string;
trackingNumber?: {trackingNumberSeq: string};
locker?: string;
+ stockLocationName?: string;
onPress: () => void;
}
@@ -45,6 +46,7 @@ const InventoryLineCard = ({
unit,
trackingNumber,
locker,
+ stockLocationName,
onPress,
}: InventoryLineCardProps) => {
const Colors = useThemeColor();
@@ -89,6 +91,11 @@ const InventoryLineCard = ({
hideIf: trackingNumber?.trackingNumberSeq == null,
iconName: 'qr-code',
},
+ {
+ indicatorText: stockLocationName,
+ hideIfNull: true,
+ iconName: 'house',
+ },
],
}}
/>
diff --git a/packages/apps/stock/src/components/templates/inventory/InventorySearchLineContainer/InventorySearchLineContainer.js b/packages/apps/stock/src/components/templates/inventory/InventorySearchLineContainer/InventorySearchLineContainer.js
index 2e12bd0a7f..5c469603d8 100644
--- a/packages/apps/stock/src/components/templates/inventory/InventorySearchLineContainer/InventorySearchLineContainer.js
+++ b/packages/apps/stock/src/components/templates/inventory/InventorySearchLineContainer/InventorySearchLineContainer.js
@@ -125,6 +125,7 @@ const InventorySearchLineContainer = ({}) => {
unit={item.unit?.name}
locker={item.rack}
trackingNumber={item.trackingNumber}
+ stockLocationName={item.stockLocation?.name}
onPress={() => handleShowLine(item)}
/>
)}
diff --git a/packages/apps/stock/src/models/objectFields.ts b/packages/apps/stock/src/models/objectFields.ts
index ea5e408db0..e64713ce9e 100644
--- a/packages/apps/stock/src/models/objectFields.ts
+++ b/packages/apps/stock/src/models/objectFields.ts
@@ -128,6 +128,7 @@ export const stock_modelAPI: ObjectFields = {
realQty: schemaContructor.number(),
description: schemaContructor.string(),
rack: schemaContructor.string(),
+ stockLocation: schemaContructor.subObject('name'),
}),
stock_partner: schemaContructor.object({
partnerSeq: schemaContructor.string(),
diff --git a/packages/apps/stock/src/screens/inventories/InventoryLineDetailsScreen.js b/packages/apps/stock/src/screens/inventories/InventoryLineDetailsScreen.js
index 74059e44c7..70ed38d421 100644
--- a/packages/apps/stock/src/screens/inventories/InventoryLineDetailsScreen.js
+++ b/packages/apps/stock/src/screens/inventories/InventoryLineDetailsScreen.js
@@ -37,11 +37,14 @@ import {
InventoryLineQuantityCard,
InventoryLineButtons,
InventoryLineTrackingNumberSelect,
+ StockLocationSearchBar,
} from '../../components';
import {fetchInventoryLine} from '../../features/inventoryLineSlice';
import {fetchProductWithId} from '../../features/productSlice';
import {Inventory as InventoryType} from '../../types';
+const stockLocationScanKey = 'stock-location_inventory-line-details';
+
const InventoryLineDetailsScreen = ({route, navigation}) => {
const {inventory, inventoryLineId, productId} = route.params;
const I18n = useTranslator();
@@ -65,6 +68,7 @@ const InventoryLineDetailsScreen = ({route, navigation}) => {
const [rack, setRack] = useState(null);
const [realQty, setRealQty] = useState(0);
const [description, setDescription] = useState();
+ const [stockLocation, setStockLocation] = useState();
const trackingNumber = useMemo(
() => inventoryLine?.trackingNumber ?? route.params.trackingNumber,
@@ -84,6 +88,7 @@ const InventoryLineDetailsScreen = ({route, navigation}) => {
useEffect(() => {
setRealQty(inventoryLine?.realQty ?? 0);
setDescription(inventoryLine?.description);
+ setStockLocation(inventoryLine?.stockLocation);
setLoading(false);
}, [inventoryLine]);
@@ -119,6 +124,7 @@ const InventoryLineDetailsScreen = ({route, navigation}) => {
inventoryLine={inventoryLine}
rack={rack}
realQty={realQty}
+ stockLocation={stockLocation}
trackingNumber={trackingNumber}
visible={!isTrackingNumberSelectVisible}
/>
@@ -153,6 +159,12 @@ const InventoryLineDetailsScreen = ({route, navigation}) => {
trackingNumber={trackingNumber?.trackingNumberSeq}
locker={inventoryLine?.rack}
/>
+
{
unit={item.unit?.name}
locker={item.rack}
trackingNumber={item.trackingNumber}
+ stockLocationName={item.stockLocation?.name}
onPress={() => handleShowLine(item)}
/>
)}