Merged PR 1566: #4112 Hotfix Manueller Preis Archivartikel

#4112 Hotfix Manueller Preis Archivartikel
This commit is contained in:
Nino Righi
2023-06-15 11:43:09 +00:00
committed by Lorenz Hilpert
parent 6ba65f031b
commit e449e612c1
3 changed files with 17 additions and 23 deletions

View File

@@ -21,7 +21,7 @@ import { UiQuantityDropdownModule } from '@ui/quantity-dropdown';
import { UiSpinnerModule } from '@ui/spinner';
import { UiTooltipModule } from '@ui/tooltip';
import { combineLatest, ReplaySubject, Subscription } from 'rxjs';
import { map, take, shareReplay, startWith, switchMap, withLatestFrom } from 'rxjs/operators';
import { map, take, shareReplay, startWith, switchMap, withLatestFrom, last } from 'rxjs/operators';
import { GIFT_CARD_MAX_PRICE, PRICE_PATTERN } from '../constants';
import { Item, PurchaseOptionsStore } from '../store';
import { OrderDeadlinePipeModule } from '@shared/pipes/order-deadline';
@@ -140,6 +140,8 @@ export class PurchaseOptionsListItemComponent implements OnInit, OnDestroy, OnCh
priceValue$ = this.price$.pipe(map((price) => price?.value?.value));
vats$ = this._store.vats$.pipe(shareReplay());
// Ticket #4074 analog zu Ticket #2244
// take(2) um die Response des Katalogpreises und danach um die Response der OLAs abzuwarten
// Logik gilt ausschließlich für Archivartikel
@@ -156,10 +158,6 @@ export class PurchaseOptionsListItemComponent implements OnInit, OnDestroy, OnCh
})
);
vats$ = this._store.vats$.pipe(shareReplay());
priceVat$ = this.price$.pipe(map((price) => price?.vat?.vatType));
canEditPrice$ = this.item$.pipe(switchMap((item) => this._store.getCanEditPrice$(item.id)));
canAddResult$ = this.item$.pipe(switchMap((item) => this._store.getCanAddResultForItemAndCurrentPurchaseOption$(item.id)));
@@ -244,14 +242,11 @@ export class PurchaseOptionsListItemComponent implements OnInit, OnDestroy, OnCh
// Ticket #4074 analog zu Ticket #2244
// Logik gilt ausschließlich für Archivartikel und über die Kaufoptionen. Nicht über den Warenkorb
initManualPriceSubscriptions() {
const features = this.item?.features as KeyValueDTOOfStringAndString[];
if (!!features && Array.isArray(features)) {
const isArchive = !!features?.find((feature) => feature?.enabled === true && feature?.key === 'ARC') ?? false;
if (isArchive) {
this.initManualPriceSubscription();
this.initManualVatSubscription();
}
async initManualPriceSubscriptions() {
const isManualPrice = await this.setManualPrice$.pipe(last()).toPromise();
if (!!isManualPrice) {
this.initManualPriceSubscription();
this.initManualVatSubscription();
}
}
@@ -314,12 +309,12 @@ export class PurchaseOptionsListItemComponent implements OnInit, OnDestroy, OnCh
const parsedPrice = this.parsePrice(value);
if (!parsedPrice) {
this._store.setPrice(this.item.id, null);
this._store.setPrice(this.item.id, null, true);
return;
}
if (price[this.item.id] !== parsedPrice) {
this._store.setPrice(this.item.id, this.parsePrice(value));
this._store.setPrice(this.item.id, this.parsePrice(value), true);
}
});
this._subscriptions.add(sub);

View File

@@ -60,12 +60,7 @@ export class PurchaseOptionsModalComponent implements OnInit, OnDestroy {
?.getPrice$(item?.id)
.pipe(
map((price) =>
isArchive
? !!price?.value?.value &&
price?.vat !== undefined &&
price?.vat?.vatType !== undefined &&
price?.vat?.value !== undefined
: !!price?.value?.value
isArchive ? !!price?.value?.value && price?.vat !== undefined && price?.vat?.value !== undefined : !!price?.value?.value
)
)
);

View File

@@ -640,12 +640,16 @@ export class PurchaseOptionsStore extends ComponentStore<PurchaseOptionsState> {
return this.select(Selectors.getCanEditPrice(itemId));
}
setPrice(itemId: number, value: number) {
setPrice(itemId: number, value: number, manually: boolean = false) {
const prices = this.prices;
let price = prices[itemId];
if (price?.value?.value !== value) {
if (!price) {
price = { ...DEFAULT_PRICE_DTO, value: { ...DEFAULT_PRICE_VALUE, value }, vat: { ...DEFAULT_VAT_VALUE, ...price?.vat } };
price = {
...DEFAULT_PRICE_DTO,
value: { ...DEFAULT_PRICE_VALUE, value },
vat: manually ? price?.vat : { ...DEFAULT_VAT_VALUE, ...price?.vat },
};
} else {
price = { ...price, value: { ...price.value, value }, vat: price?.vat };
}