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:
@ -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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user