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

@ -6,6 +6,7 @@ import { round } from 'mathjs';
import { Observable, of as observableOf } from 'rxjs';
import { debounceTime, distinctUntilChanged, map, startWith, switchMap } from 'rxjs/operators';
import { Batch } from '../core/batch';
import { Inventory } from '../core/inventory';
import { Product } from '../core/product';
import { ProductService } from '../product/product.service';
@ -47,13 +48,13 @@ export class PurchaseDialogComponent implements OnInit {
ngOnInit() {
this.form.setValue({
product: this.data.inventory.product,
product: this.data.inventory.batch?.sku,
quantity: this.data.inventory.quantity,
price: this.data.inventory.rate,
tax: this.data.inventory.tax,
discount: this.data.inventory.discount,
});
this.product = this.data.inventory.product;
this.product = this.data.inventory.batch?.sku;
}
displayFn(product?: Product): string {
@ -71,7 +72,10 @@ export class PurchaseDialogComponent implements OnInit {
const price = this.math.parseAmount(formValue.price, 2);
const tax = this.math.parseAmount(formValue.tax, 5);
const discount = this.math.parseAmount(formValue.discount, 5);
this.data.inventory.product = this.product;
if (this.data.inventory.batch === null) {
this.data.inventory.batch = new Batch();
}
this.data.inventory.batch.sku = this.product;
this.data.inventory.quantity = quantity;
this.data.inventory.rate = price;
this.data.inventory.tax = tax;

View File

@ -134,7 +134,7 @@
<!-- Product Column -->
<ng-container matColumnDef="product">
<mat-header-cell *matHeaderCellDef>Product</mat-header-cell>
<mat-cell *matCellDef="let row">{{ row.product.name }}</mat-cell>
<mat-cell *matCellDef="let row">{{ row.batch.sku.name }}</mat-cell>
</ng-container>
<!-- Quantity Column -->

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;
}