Feature: Added product Stock Keeping Units to prevent duplicate products. A lot of refactoring because of this.

Removed: Reset Stock as it was never used and don't think it is even needed with this new batch system.
Fix: Incentive update was not working
This commit is contained in:
2021-09-27 09:31:58 +05:30
parent 4f907e965b
commit 1647d356c9
71 changed files with 1272 additions and 904 deletions

View File

@ -13,6 +13,7 @@ import { AuthService } from '../auth/auth.service';
import { Account } from '../core/account';
import { AccountBalance } from '../core/account-balance';
import { AccountService } from '../core/account.service';
import { Batch } from '../core/batch';
import { DbFile } from '../core/db-file';
import { Inventory } from '../core/inventory';
import { Product } from '../core/product';
@ -100,6 +101,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
: this.productSer.autocomplete(
x,
false,
true,
moment(this.form.value.date).format('DD-MMM-YYYY'),
this.form.value.account.id,
),
@ -201,11 +203,11 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
const discount = this.product.isRateContracted
? 0
: this.math.parseAmount(formValue.discount, 5);
if (price <= 0 || tax < 0 || discount < 0) {
if ((price as number) <= 0 || (tax as number) < 0 || (discount as number) < 0) {
return;
}
const oldFiltered = this.voucher.inventories.filter(
(x) => x.product.id === (this.product as Product).id,
(x) => x.batch?.sku.id === (this.product as Product).id,
);
if (oldFiltered.length) {
this.toaster.show('Danger', 'Product already added');
@ -217,9 +219,8 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
rate: price,
tax,
discount,
amount: round(quantity * price * (1 + tax) * (1 - discount), 2),
product: this.product,
batch: null,
amount: round(quantity * (price as number) * (1 + tax) * (1 - discount), 2),
batch: new Batch({ sku: this.product }),
}),
);
this.resetAddRow();
@ -264,8 +265,8 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
}
const j = result as Inventory;
if (
j.product.id !== row.product.id &&
this.voucher.inventories.filter((x) => x.product.id === j.product.id).length
j.batch?.sku.id !== row.batch?.sku.id &&
this.voucher.inventories.filter((x) => x.batch?.sku.id === j.batch?.sku.id).length
) {
return;
}