Fix: Autocomplete could fuck up and was definitely doing it in product.

When checking for .name, it would error out if the input was null

Fix: Journal addRow reset would reset Debit/Credit
This commit is contained in:
tanshu committed 2022-07-17 14:31:19 +05:30
1 parent 9f70ec2917
commit bddd5ec749
17 files changed
+104 -127

No files matched your search

@@ -4,7 +4,7 @@ import { MatAutocompleteSelectedEvent } from '@angular/material/autocomplete';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { round } from 'mathjs';
import { Observable, of as observableOf } from 'rxjs';
import { debounceTime, distinctUntilChanged, map, switchMap } from 'rxjs/operators';
import { debounceTime, distinctUntilChanged, switchMap } from 'rxjs/operators';
import { Batch } from '../core/batch';
import { Inventory } from '../core/inventory';
@@ -21,7 +21,7 @@ import { MathService } from '../shared/math.service';
export class PurchaseDialogComponent implements OnInit {
products: Observable<ProductSku[]>;
form: FormGroup<{
product: FormControl<ProductSku | string | null>;
product: FormControl<string | null>;
quantity: FormControl<string>;
price: FormControl<string>;
tax: FormControl<string>;
@@ -37,7 +37,7 @@ export class PurchaseDialogComponent implements OnInit {
private productSer: ProductService,
) {
this.form = new FormGroup({
product: new FormControl<ProductSku | string | null>(null),
product: new FormControl<string | null>(null),
quantity: new FormControl('', { nonNullable: true }),
price: new FormControl('', { nonNullable: true }),
tax: new FormControl('', { nonNullable: true }),
@@ -45,8 +45,6 @@ export class PurchaseDialogComponent implements OnInit {
});
// Listen to Product Autocomplete Change
this.products = this.form.controls.product.valueChanges.pipe(
map((x) => ((x as ProductSku).name !== undefined ? (x as ProductSku).name : (x as string))),
map((x) => (x !== null && x.length >= 1 ? x : null)),
debounceTime(150),
distinctUntilChanged(),
switchMap((x) => (x === null ? observableOf([]) : this.productSer.autocompleteSku(x, true))),
@@ -55,7 +53,7 @@ export class PurchaseDialogComponent implements OnInit {
ngOnInit() {
this.form.setValue({
product: this.data.inventory.batch?.sku,
product: this.data.inventory.batch?.sku.name,
quantity: `${this.data.inventory.quantity}`,
price: `${this.data.inventory.rate}`,
tax: `${this.data.inventory.tax}`,
@@ -64,8 +62,8 @@ export class PurchaseDialogComponent implements OnInit {
this.product = this.data.inventory.batch?.sku;
}
displayFn(product?: Product): string {
return product ? product.name : '';
displayFn(product?: Product | string): string {
return !product ? '' : typeof product === 'string' ? product : product.name;
}
productSelected(event: MatAutocompleteSelectedEvent): void {