Fix: Products could be added without skus rendering them useless

Feature: Change of product in purchase / issue / Purchase return allowed.
This commit is contained in:
2021-11-11 20:52:28 +05:30
parent eeb36d7f8b
commit 1a3248ad70
7 changed files with 52 additions and 52 deletions

View File

@ -166,20 +166,13 @@ export class IssueComponent implements OnInit, AfterViewInit, OnDestroy {
if (this.batch === null || quantity <= 0) {
return;
}
const oldFiltered = this.voucher.inventories.filter(
(x) => x.batch.sku.id === (this.batch as Batch).sku.id,
);
const old = oldFiltered.length ? oldFiltered[0] : null;
if (oldFiltered.length) {
if (((old as Inventory).batch as Batch).id !== this.batch.id) {
this.toaster.show('Danger', 'Product with a different batch already added');
return;
}
if (isConsumption && (old as Inventory).quantity + quantity > this.batch.quantityRemaining) {
const old = this.voucher.inventories.find((x) => x.batch.id === (this.batch as Batch).id);
if (old !== undefined) {
if (isConsumption && old.quantity + quantity > this.batch.quantityRemaining) {
this.toaster.show('Danger', 'Quantity issued cannot be more than quantity available');
return;
}
(old as Inventory).quantity += quantity;
old.quantity += quantity;
} else {
if (isConsumption && quantity > this.batch.quantityRemaining) {
this.toaster.show('Danger', 'Quantity issued cannot be more than quantity available');
@ -238,7 +231,7 @@ export class IssueComponent implements OnInit, AfterViewInit, OnDestroy {
const j = result as Inventory;
if (
j.batch.sku.id !== row.batch.sku.id &&
this.voucher.inventories.filter((x) => x.batch.sku.id === j.batch.sku.id).length
this.voucher.inventories.filter((x) => x.batch.id === j.batch.id).length
) {
return;
}

View File

@ -179,10 +179,8 @@ export class PurchaseReturnComponent implements OnInit, AfterViewInit, OnDestroy
if (this.batch === null || quantity <= 0 || this.batch.quantityRemaining < quantity) {
return;
}
const oldFiltered = this.voucher.inventories.filter(
(x) => x.batch.sku.id === (this.batch as Batch).sku.id,
);
if (oldFiltered.length) {
const old = this.voucher.inventories.find((x) => x.batch.id === (this.batch as Batch).id);
if (old !== undefined) {
this.toaster.show('Danger', 'Product already added');
return;
}