Merged PR 1503: #3876 Fix Reorder Modal with Selected Branch now returns correct availabiliti...

#3876 Fix Reorder Modal with Selected Branch now returns correct availabilities based by selected branch
This commit is contained in:
Nino Righi
2023-03-08 12:15:07 +00:00
committed by Lorenz Hilpert
parent c65c8edd2d
commit 89b8d07bb4
6 changed files with 42 additions and 18 deletions

View File

@@ -59,8 +59,8 @@ export class DomainAvailabilityService {
}
@memorize()
getStockByBranch(branch: BranchDTO): Observable<StockDTO> {
return this._stockService.StockGetStocksByBranch({ branchId: branch.id }).pipe(
getStockByBranch(branchId: number): Observable<StockDTO> {
return this._stockService.StockGetStocksByBranch({ branchId }).pipe(
map((response) => response.result),
map((result) => result?.find((_) => true)),
shareReplay(1)
@@ -149,7 +149,7 @@ export class DomainAvailabilityService {
quantity: number;
branch?: BranchDTO;
}): Observable<AvailabilityDTO> {
const request = !!branch ? this.getStockByBranch(branch) : this.getDefaultStock();
const request = !!branch ? this.getStockByBranch(branch.id) : this.getDefaultStock();
return request.pipe(
switchMap((s) =>
combineLatest([
@@ -160,7 +160,7 @@ export class DomainAvailabilityService {
),
map(([response, supplier, defaultBranch]) => {
const price = item?.price;
return this._mapToTakeAwayAvailability({ response, supplier, branch: branch ?? defaultBranch, quantity, price });
return this._mapToTakeAwayAvailability({ response, supplier, branchId: branch.id ?? defaultBranch.id, quantity, price });
}),
shareReplay(1)
);
@@ -183,7 +183,7 @@ export class DomainAvailabilityService {
this.getTakeAwaySupplier(),
]).pipe(
map(([response, supplier]) => {
return this._mapToTakeAwayAvailability({ response, supplier, branch, quantity, price });
return this._mapToTakeAwayAvailability({ response, supplier, branchId: branch.id, quantity, price });
}),
shareReplay(1)
);
@@ -193,16 +193,19 @@ export class DomainAvailabilityService {
eans,
price,
quantity,
branchId,
}: {
eans: string[];
price: PriceDTO;
quantity: number;
branchId?: number;
}): Observable<AvailabilityDTO> {
return this.getDefaultStock().pipe(
const request = !!branchId ? this.getStockByBranch(branchId) : this.getDefaultStock();
return request.pipe(
switchMap((s) => this._stockService.StockInStockByEAN({ eans, stockId: s.id })),
withLatestFrom(this.getTakeAwaySupplier(), this.getDefaultBranch()),
map(([response, supplier, branch]) => {
return this._mapToTakeAwayAvailability({ response, supplier, branch, quantity, price });
map(([response, supplier, defaultBranch]) => {
return this._mapToTakeAwayAvailability({ response, supplier, branchId: branchId ?? defaultBranch.id, quantity, price });
}),
shareReplay(1)
);
@@ -476,17 +479,17 @@ export class DomainAvailabilityService {
private _mapToTakeAwayAvailability({
response,
supplier,
branch,
branchId,
quantity,
price,
}: {
response: ResponseArgsOfIEnumerableOfStockInfoDTO;
supplier: SupplierDTO;
branch: BranchDTO;
branchId: number;
quantity: number;
price: PriceDTO;
}): AvailabilityDTO {
const stockInfo = response.result?.find((si) => si.branchId === branch.id);
const stockInfo = response.result?.find((si) => si.branchId === branchId);
const inStock = stockInfo?.inStock ?? 0;
const availability: AvailabilityDTO = {
availabilityType: quantity <= inStock ? 1024 : 1, // 1024 (=Available)
@@ -609,7 +612,7 @@ export class DomainAvailabilityService {
}
getInStock({ itemIds, branchId }: { itemIds: number[]; branchId: number }): Observable<StockInfoDTO[]> {
return this.getStockByBranch({ id: branchId }).pipe(
return this.getStockByBranch(branchId).pipe(
mergeMap((stock) =>
this._stockService.StockInStock({ articleIds: itemIds, stockId: stock.id }).pipe(map((response) => response.result))
)

View File

@@ -73,10 +73,10 @@
<ui-icon icon="documents_refresh" size="24px"></ui-icon>
Remission
</a>
<a [routerLink]="['/filiale/package-inspection']" routerLinkActive="active" (click)="fetchAndOpenPackages()">
<!-- <a [routerLink]="['/filiale/package-inspection']" routerLinkActive="active" (click)="fetchAndOpenPackages()">
<ui-svg-icon icon="clipboard-check-outline" [size]="24"></ui-svg-icon>
Wareneingang
</a>
</a> -->
</ng-container>
</shell-footer>
</div>

View File

@@ -212,8 +212,8 @@ describe('ShellComponent', () => {
expect(anchors[2]).toHaveAttribute('href', '/filiale/goods/in');
expect(anchors[3]).toHaveText('Remission');
expect(anchors[3]).toHaveAttribute('href', '/filiale/remission');
expect(anchors[4]).toHaveText('Wareneingang');
expect(anchors[4]).toHaveAttribute('href', '/filiale/package-inspection');
// expect(anchors[4]).toHaveText('Wareneingang');
// expect(anchors[4]).toHaveAttribute('href', '/filiale/package-inspection');
});
});

View File

@@ -98,6 +98,7 @@ export class ReorderModalComponent extends ComponentStore<GoodsInListReorderModa
eans: [item.product.ean],
quantity: item.quantity,
price: item.retailPrice,
branchId: item.targetBranchId,
})
.pipe(
catchError(() => {

View File

@@ -1,5 +1,10 @@
<shared-breadcrumb class="my-4" [key]="processId$ | async" [tags]="['customer-order']">
<shared-branch-selector [branchType]="1" [value]="selectedBranch$ | async" (valueChange)="patchProcessData($event)">
<shared-branch-selector
*ngIf="!(onCustomerOrderDetailsPage$ | async)"
[branchType]="1"
[value]="selectedBranch$ | async"
(valueChange)="patchProcessData($event)"
>
</shared-branch-selector>
</shared-breadcrumb>

View File

@@ -1,6 +1,7 @@
import { Component, ChangeDetectionStrategy, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { ApplicationService } from '@core/application';
import { BreadcrumbService } from '@core/breadcrumb';
import { BranchDTO } from '@swagger/checkout';
import { UiErrorModalComponent, UiModalService } from '@ui/modal';
import { Observable } from 'rxjs';
@@ -17,9 +18,23 @@ export class CustomerOrderComponent implements OnInit {
selectedBranch$: Observable<BranchDTO>;
constructor(public application: ApplicationService, private _activatedRoute: ActivatedRoute, private _uiModal: UiModalService) {}
onCustomerOrderDetailsPage$: Observable<boolean>;
constructor(
public application: ApplicationService,
private _activatedRoute: ActivatedRoute,
private _uiModal: UiModalService,
private _breadcrumb: BreadcrumbService
) {}
ngOnInit(): void {
this.onCustomerOrderDetailsPage$ = this.processId$.pipe(
switchMap((processId) => {
return this._breadcrumb
.getBreadcrumbsByKeyAndTags$(processId, ['customer-order', 'details'])
.pipe(map((crumbs) => crumbs?.length > 0));
})
);
this.selectedBranch$ = this.application.activatedProcessId$.pipe(
switchMap((processId) => this.application.getSelectedBranch$(Number(processId)))
);