Chore: Reformatted everthing

Fix: Product ledger was not totalling.
This is because for some reason, pydantic was sending the data as string when the field was nullable
This commit is contained in:
2023-08-04 21:00:26 +05:30
parent af27bf74ef
commit ac868257b7
194 changed files with 513 additions and 1580 deletions
@@ -8,8 +8,7 @@ import { map } from 'rxjs/operators';
import { ClosingStockItem } from './closing-stock-item';
/** Simple sort comparator for example ID/Name columns (for client-side sorting). */
const compare = (a: string | number, b: string | number, isAsc: boolean) =>
(a < b ? -1 : 1) * (isAsc ? 1 : -1);
const compare = (a: string | number, b: string | number, isAsc: boolean) => (a < b ? -1 : 1) * (isAsc ? 1 : -1);
export class ClosingStockDataSource extends DataSource<ClosingStockItem> {
constructor(
public data: ClosingStockItem[],
@@ -13,8 +13,7 @@ const closingStockRoutes: Routes = [
path: '',
component: ClosingStockComponent,
canActivate: [
(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) =>
inject(AuthGuard).canActivate(route, state),
(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) => inject(AuthGuard).canActivate(route, state),
],
data: {
permission: 'Closing Stock',
@@ -29,8 +28,7 @@ const closingStockRoutes: Routes = [
path: ':date',
component: ClosingStockComponent,
canActivate: [
(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) =>
inject(AuthGuard).canActivate(route, state),
(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) => inject(AuthGuard).canActivate(route, state),
],
data: {
permission: 'Closing Stock',
@@ -30,17 +30,9 @@
<mat-datepicker-toggle matSuffix [for]="dateInput"></mat-datepicker-toggle>
<mat-datepicker #dateInput></mat-datepicker>
</mat-form-field>
<button mat-raised-button color="primary" (click)="show()" class="flex-auto basis-1/5">
Show
</button>
<button mat-raised-button color="primary" (click)="show()" class="flex-auto basis-1/5">Show</button>
</div>
<mat-table
#table
[dataSource]="dataSource"
matSort
aria-label="Elements"
formArrayName="stocks"
>
<mat-table #table [dataSource]="dataSource" matSort aria-label="Elements" formArrayName="stocks">
<!-- Product Column -->
<ng-container matColumnDef="product" class="first">
<mat-header-cell *matHeaderCellDef mat-sort-header class="first">Product</mat-header-cell>
@@ -55,12 +47,8 @@
<!-- Quantity Column -->
<ng-container matColumnDef="quantity">
<mat-header-cell *matHeaderCellDef mat-sort-header class="right middle"
>Closing Stock</mat-header-cell
>
<mat-cell *matCellDef="let row" class="right middle">{{
row.quantity | number: '0.2-2'
}}</mat-cell>
<mat-header-cell *matHeaderCellDef mat-sort-header class="right middle">Closing Stock</mat-header-cell>
<mat-cell *matCellDef="let row" class="right middle">{{ row.quantity | number: '0.2-2' }}</mat-cell>
</ng-container>
<!-- Physical Column -->
@@ -69,12 +57,7 @@
<mat-cell *matCellDef="let row; let i = index" [formGroupName]="i" class="middle">
<mat-form-field class="flex-auto">
<mat-label>Physical</mat-label>
<input
matInput
type="number"
formControlName="physical"
(change)="updatePhysical($event, row)"
/>
<input matInput type="number" formControlName="physical" (change)="updatePhysical($event, row)" />
</mat-form-field>
</mat-cell>
</ng-container>
@@ -108,12 +91,8 @@
<!-- Amount Column -->
<ng-container matColumnDef="amount" class="last">
<mat-header-cell *matHeaderCellDef mat-sort-header class="right last"
>Amount</mat-header-cell
>
<mat-cell *matCellDef="let row" class="right">{{
row.amount | currency: 'INR'
}}</mat-cell>
<mat-header-cell *matHeaderCellDef mat-sort-header class="right last">Amount</mat-header-cell>
<mat-cell *matCellDef="let row" class="right">{{ row.amount | currency: 'INR' }}</mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
@@ -131,9 +110,7 @@
</form>
</mat-card-content>
<mat-card-actions>
<button mat-raised-button color="primary" (click)="save()" [disabled]="form.pristine">
Save
</button>
<button mat-raised-button color="primary" (click)="save()" [disabled]="form.pristine">Save</button>
<button
mat-raised-button
(click)="post()"
@@ -142,13 +119,7 @@
>
{{ info.posted ? 'Posted' : 'Post' }}
</button>
<button
mat-raised-button
color="warn"
(click)="confirmDelete()"
*ngIf="canDelete()"
[disabled]="!canSave()"
>
<button mat-raised-button color="warn" (click)="confirmDelete()" *ngIf="canDelete()" [disabled]="!canSave()">
Delete
</button>
</mat-card-actions>
@@ -41,15 +41,7 @@ export class ClosingStockComponent implements OnInit {
}>;
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
displayedColumns = [
'product',
'group',
'quantity',
'physical',
'variance',
'department',
'amount',
];
displayedColumns = ['product', 'group', 'quantity', 'physical', 'variance', 'department', 'amount'];
costCentres: CostCentre[];
@@ -66,9 +58,9 @@ export class ClosingStockComponent implements OnInit {
this.form = new FormGroup({
date: new FormControl(new Date(), { nonNullable: true }),
costCentre: new FormControl<string | null>(null),
stocks: new FormArray<
FormGroup<{ physical: FormControl<number>; costCentre: FormControl<string | undefined> }>
>([]),
stocks: new FormArray<FormGroup<{ physical: FormControl<number>; costCentre: FormControl<string | undefined> }>>(
[],
),
});
}
@@ -181,10 +173,7 @@ export class ClosingStockComponent implements OnInit {
if (this.info.posted && this.auth.allowed('edit-posted-vouchers')) {
return true;
}
return (
this.info.user.id === (this.auth.user as User).id ||
this.auth.allowed("edit-other-user's-vouchers")
);
return this.info.user.id === (this.auth.user as User).id || this.auth.allowed("edit-other-user's-vouchers");
}
post() {
@@ -6,12 +6,7 @@ import { ReactiveFormsModule } from '@angular/forms';
import { MatButtonModule } from '@angular/material/button';
import { MatCardModule } from '@angular/material/card';
import { MatCheckboxModule } from '@angular/material/checkbox';
import {
DateAdapter,
MAT_DATE_FORMATS,
MAT_DATE_LOCALE,
MatNativeDateModule,
} from '@angular/material/core';
import { DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE, MatNativeDateModule } from '@angular/material/core';
import { MatDatepickerModule } from '@angular/material/datepicker';
import { MatIconModule } from '@angular/material/icon';
import { MatInputModule } from '@angular/material/input';
@@ -40,17 +40,13 @@ export class ClosingStockService {
const options = { params: new HttpParams().set('d', costCentre) };
return this.http
.post<ClosingStock>(`${url}/${date}`, {}, options)
.pipe(
catchError(this.log.handleError(serviceName, 'Post Voucher')),
) as Observable<ClosingStock>;
.pipe(catchError(this.log.handleError(serviceName, 'Post Voucher'))) as Observable<ClosingStock>;
}
delete(date: string, costCentre: string): Observable<ClosingStock> {
const options = { params: new HttpParams().set('d', costCentre) };
return this.http
.delete<ClosingStock>(`${url}/${date}`, options)
.pipe(
catchError(this.log.handleError(serviceName, 'Delete Voucher')),
) as Observable<ClosingStock>;
.pipe(catchError(this.log.handleError(serviceName, 'Delete Voucher'))) as Observable<ClosingStock>;
}
}