fix(remission-data-access, remission-list, remission-add-item-flow): enforce mandatory list type for add-item flow

Remove addToDepartmentList method and ensure items added via search dialog
are always processed as mandatory remission items (ReturnItem) instead of
department suggestions (ReturnSuggestion). This prevents items from being
incorrectly added to department overflow lists when remission is already
started, maintaining data consistency in the WBS system.

Changes:
- Remove addToDepartmentList method from RemissionSearchService
- Update remitItems to use mandatory list type for add-item flow
- Simplify addToRemiList to only use mandatory remission endpoint
- Add addItemFlow parameter to control remission list type behavior

Refs: #4768, #5273, #5280
This commit is contained in:
Nino
2025-09-02 14:40:26 +02:00
parent 327fdc745d
commit 3b0a63a53a
3 changed files with 19 additions and 48 deletions

View File

@@ -446,41 +446,4 @@ export class RemissionSearchService {
return res.successful?.map((r) => r.value) as ReturnItem[];
}
async addToDepartmentList(
items: { item: Item; quantity: number; reason: string }[],
abortSignal?: AbortSignal,
): Promise<ReturnSuggestion[]> {
const stock = await this.#remiStockService.fetchAssignedStock(abortSignal);
if (!stock) {
this.#logger.error('No assigned stock found for remission items');
throw new Error('No assigned stock found');
}
const req$ = this.#remiService.RemiCreateReturnSuggestions({
data: items.map((i) => ({
product: {
...i.item.product,
catalogProductNumber: String(i.item.id),
},
assortment: 'Basissortiment|B',
predefinedReturnQuantity: i.quantity,
retailPrice: i.item.catalogAvailability.price,
source: 'manually-added',
returnReason: i.reason,
stock: { id: stock.id },
})),
});
const res = await firstValueFrom(req$);
if (res.error) {
const error = new ResponseArgsError(res);
this.#logger.error('Failed to add to department list', error);
throw error;
}
return res.successful?.map((r) => r.value) as ReturnSuggestion[];
}
}

View File

@@ -401,7 +401,7 @@ export class RemissionListComponent {
this.#store.selectRemissionItem(item.id, item);
}
}
await this.remitItems();
await this.remitItems({ addItemFlow: true });
} else if (this.isDepartment()) {
return await this.navigateToDefaultRemissionList();
}
@@ -414,14 +414,25 @@ export class RemissionListComponent {
});
// TODO: Improvement - In Separate Komponente zusammen mit Remi-Button Auslagern
async remitItems() {
/**
* Initiates the process to remit selected items.
* If remission is already started, items are added directly to the remission.
* If not, navigates to the default remission list.
* @param options - Options for remitting items, including whether it's part of an add-item flow.
* @returns A promise that resolves when the operation is complete.
*/
async remitItems(options: { addItemFlow: boolean } = { addItemFlow: false }) {
if (this.remitItemsInProgress()) {
return;
}
this.remitItemsInProgress.set(true);
try {
const remissionListType = this.selectedRemissionListType();
// #5273, #5280 Fix - Bei gestarteter Remission dürfen Items die über den AddItemDialog hinzugefügt und direkt remittiert werden, nur als ReturnItem (statt ReturnSuggestion) zum WBS hinzugefügt werden
const remissionListType = options.addItemFlow
? RemissionListType.Pflicht
: this.selectedRemissionListType();
const selected = this.#store.selectedItems();
const quantities = this.#store.selectedQuantity();
@@ -448,7 +459,7 @@ export class RemissionListComponent {
quantity: stockToRemit,
inStock,
},
type: this.selectedRemissionListType(),
type: remissionListType,
});
}
}

View File

@@ -166,13 +166,10 @@ export class SelectRemiQuantityAndReasonComponent {
return;
}
let result: Array<ReturnSuggestion> | Array<ReturnItem> = [];
if (this.host.data.isDepartment) {
result = await this.#remiService.addToDepartmentList(this.params());
} else {
result = await this.#remiService.addToList(this.params());
}
// #5273, #4768 Fix - Items dürfen nur zur Pflichtremission hinzugefügt werden
const result: Array<ReturnItem> = await this.#remiService.addToList(
this.params(),
);
this.#feedbackDialog({
data: {