From e35db8144b881ca5e984d1ebb8a355259ba28b3c Mon Sep 17 00:00:00 2001 From: Amritanshu Date: Tue, 15 Jul 2025 15:29:44 +0000 Subject: [PATCH] Fix: Error messages were not properly captured in the frontend. Feature: F5,6,7 to change between Receipt, Payment and Journal voucher. --- brewman/brewman/schemas/attendance_type.py | 4 +--- brewman/brewman/schemas/batch.py | 4 +--- brewman/brewman/schemas/incentive.py | 4 +--- brewman/brewman/schemas/inventory.py | 4 +--- brewman/brewman/schemas/issue_grid_item.py | 4 +--- brewman/brewman/schemas/journal.py | 4 +--- brewman/brewman/schemas/product_sku.py | 4 +--- brewman/brewman/schemas/rate_contract_item.py | 4 +--- brewman/brewman/schemas/recipe_item.py | 4 +--- brewman/brewman/schemas/role.py | 1 - brewman/pyproject.toml | 4 ++-- .../src/app/auth/login/login.component.ts | 4 +++- overlord/src/app/core/auth.interceptor.ts | 6 +++--- overlord/src/app/journal/journal.component.ts | 17 +++++++++++++++ overlord/src/app/payment/payment.component.ts | 21 +++++++++++++++++++ overlord/src/app/receipt/receipt.component.ts | 21 +++++++++++++++++++ 16 files changed, 76 insertions(+), 34 deletions(-) diff --git a/brewman/brewman/schemas/attendance_type.py b/brewman/brewman/schemas/attendance_type.py index f19bf7aa..34094049 100644 --- a/brewman/brewman/schemas/attendance_type.py +++ b/brewman/brewman/schemas/attendance_type.py @@ -1,8 +1,6 @@ from pydantic import BaseModel, ConfigDict -from . import to_camel - -from . import Daf +from . import Daf, to_camel class AttendanceType(BaseModel): diff --git a/brewman/brewman/schemas/batch.py b/brewman/brewman/schemas/batch.py index d39aa922..6961dea8 100644 --- a/brewman/brewman/schemas/batch.py +++ b/brewman/brewman/schemas/batch.py @@ -2,11 +2,9 @@ import uuid from pydantic import BaseModel, ConfigDict -from . import to_camel +from . import Daf, to_camel from .product import ProductLink -from . import Daf - class Batch(BaseModel): id_: uuid.UUID | None = None diff --git a/brewman/brewman/schemas/incentive.py b/brewman/brewman/schemas/incentive.py index 069d42bb..322de648 100644 --- a/brewman/brewman/schemas/incentive.py +++ b/brewman/brewman/schemas/incentive.py @@ -2,9 +2,7 @@ import uuid from pydantic import BaseModel, ConfigDict, Field -from . import to_camel - -from . import Daf +from . import Daf, to_camel class Incentive(BaseModel): diff --git a/brewman/brewman/schemas/inventory.py b/brewman/brewman/schemas/inventory.py index b64d5921..4695c0a1 100644 --- a/brewman/brewman/schemas/inventory.py +++ b/brewman/brewman/schemas/inventory.py @@ -2,11 +2,9 @@ import uuid from pydantic import BaseModel, ConfigDict, Field -from . import to_camel +from . import Daf, to_camel from .batch import Batch -from . import Daf - class Inventory(BaseModel): id_: uuid.UUID | None = None diff --git a/brewman/brewman/schemas/issue_grid_item.py b/brewman/brewman/schemas/issue_grid_item.py index 41b6d046..6adfd830 100644 --- a/brewman/brewman/schemas/issue_grid_item.py +++ b/brewman/brewman/schemas/issue_grid_item.py @@ -2,9 +2,7 @@ import uuid from pydantic import BaseModel, ConfigDict -from . import to_camel - -from . import Daf +from . import Daf, to_camel class IssueGridItem(BaseModel): diff --git a/brewman/brewman/schemas/journal.py b/brewman/brewman/schemas/journal.py index 4147c25c..2973c115 100644 --- a/brewman/brewman/schemas/journal.py +++ b/brewman/brewman/schemas/journal.py @@ -2,12 +2,10 @@ import uuid from pydantic import BaseModel, ConfigDict, Field -from . import to_camel +from . import Daf, to_camel from .account import AccountLink from .cost_centre import CostCentreLink -from . import Daf - class Journal(BaseModel): id_: uuid.UUID | None = None diff --git a/brewman/brewman/schemas/product_sku.py b/brewman/brewman/schemas/product_sku.py index 6f54c256..b50bcc91 100644 --- a/brewman/brewman/schemas/product_sku.py +++ b/brewman/brewman/schemas/product_sku.py @@ -2,9 +2,7 @@ import uuid from pydantic import BaseModel, ConfigDict, Field -from . import to_camel - -from . import Daf +from . import Daf, to_camel class ProductSku(BaseModel): diff --git a/brewman/brewman/schemas/rate_contract_item.py b/brewman/brewman/schemas/rate_contract_item.py index 2f9e3a99..ebdc7b36 100644 --- a/brewman/brewman/schemas/rate_contract_item.py +++ b/brewman/brewman/schemas/rate_contract_item.py @@ -2,11 +2,9 @@ import uuid from pydantic import BaseModel, ConfigDict, Field -from . import to_camel +from . import Daf, to_camel from .product import ProductLink -from . import Daf - class RateContractItem(BaseModel): id_: uuid.UUID | None = None diff --git a/brewman/brewman/schemas/recipe_item.py b/brewman/brewman/schemas/recipe_item.py index 3ecece50..fb58038d 100644 --- a/brewman/brewman/schemas/recipe_item.py +++ b/brewman/brewman/schemas/recipe_item.py @@ -2,11 +2,9 @@ import uuid from pydantic import BaseModel, ConfigDict -from . import to_camel +from . import Daf, to_camel from .product import ProductLink -from . import Daf - class RecipeItem(BaseModel): id_: uuid.UUID | None = None diff --git a/brewman/brewman/schemas/role.py b/brewman/brewman/schemas/role.py index aae247a0..7fcd4191 100644 --- a/brewman/brewman/schemas/role.py +++ b/brewman/brewman/schemas/role.py @@ -3,7 +3,6 @@ import uuid from pydantic import BaseModel, ConfigDict, Field from . import to_camel - from .permission import PermissionItem diff --git a/brewman/pyproject.toml b/brewman/pyproject.toml index c2d3e76f..3c803961 100644 --- a/brewman/pyproject.toml +++ b/brewman/pyproject.toml @@ -36,8 +36,8 @@ build-backend = "poetry.core.masonry.api" [tool.ruff] line-length = 120 -# Assume Python 3.12. -target-version = "py312" +# Assume Python 3.13. +target-version = "py313" exclude = [ ".eggs", ".git", diff --git a/overlord/src/app/auth/login/login.component.ts b/overlord/src/app/auth/login/login.component.ts index edd6be7e..e00bac71 100644 --- a/overlord/src/app/auth/login/login.component.ts +++ b/overlord/src/app/auth/login/login.component.ts @@ -1,4 +1,4 @@ -import { AfterViewInit, Component, ElementRef, inject, OnInit, ViewChild } from '@angular/core'; +import { AfterViewInit, ChangeDetectorRef, Component, ElementRef, inject, OnInit, ViewChild } from '@angular/core'; import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms'; import { MatButton } from '@angular/material/button'; import { MatCard, MatCardActions, MatCardContent, MatCardHeader, MatCardTitle } from '@angular/material/card'; @@ -38,6 +38,7 @@ export class LoginComponent implements OnInit, AfterViewInit { private router = inject(Router); private snackBar = inject(MatSnackBar); private cs = inject(CookieService); + private cd = inject(ChangeDetectorRef); @ViewChild('nameElement', { static: true }) nameElement!: ElementRef; form: FormGroup<{ @@ -87,6 +88,7 @@ export class LoginComponent implements OnInit, AfterViewInit { if (error.status === 401 && error.error.detail === 'Client is not registered') { this.showOtp = true; this.clientId = this.cs.getCookie('client_id'); + this.cd.detectChanges(); } this.snackBar.open(error.error.details, 'Danger'); }, diff --git a/overlord/src/app/core/auth.interceptor.ts b/overlord/src/app/core/auth.interceptor.ts index 02575c43..c3cba7ad 100644 --- a/overlord/src/app/core/auth.interceptor.ts +++ b/overlord/src/app/core/auth.interceptor.ts @@ -20,13 +20,13 @@ export const authInterceptor: HttpInterceptorFn = (req, next) => { if (req.url.includes('/refresh')) { inject(AuthService).logout(); } - return throwError(() => new Error(err)); + return throwError(() => err); } // If error status is different than 401 we want to skip refresh token // So we check that and throw the error if it's the case if (err.status !== 401) { const error = err.error.message || err.error.detail || err.statusText; - return throwError(() => new Error(error)); + return throwError(() => error); } // auto logout if 401 response returned from api inject(AuthService).logout(); @@ -46,7 +46,7 @@ export const authInterceptor: HttpInterceptorFn = (req, next) => { inject(Router).navigate(['login']); } }); - return throwError(() => new Error(err)); + return throwError(() => err); }), ); }; diff --git a/overlord/src/app/journal/journal.component.ts b/overlord/src/app/journal/journal.component.ts index 78f90c8e..76bd75d3 100644 --- a/overlord/src/app/journal/journal.component.ts +++ b/overlord/src/app/journal/journal.component.ts @@ -132,6 +132,23 @@ export class JournalComponent implements OnInit, AfterViewInit { this.dateElement.nativeElement.select(); } + @HostListener('window:keydown.f5', ['$event']) + redirectToPayment(event: KeyboardEvent) { + event.preventDefault(); + this.router.navigate(['payment']); + } + + @HostListener('window:keydown.f6', ['$event']) + redirectToReciept(event: KeyboardEvent) { + event.preventDefault(); + this.router.navigate(['receipt']); + } + + @HostListener('window:keydown.f7', ['$event']) + redirectToJournal(event: KeyboardEvent) { + event.preventDefault(); + } + @HostListener('window:keydown.control.s', ['$event']) saveListner(event: KeyboardEvent) { event.preventDefault(); diff --git a/overlord/src/app/payment/payment.component.ts b/overlord/src/app/payment/payment.component.ts index 747b5a2d..89f13927 100644 --- a/overlord/src/app/payment/payment.component.ts +++ b/overlord/src/app/payment/payment.component.ts @@ -132,6 +132,27 @@ export class PaymentComponent implements OnInit, AfterViewInit { this.dateElement.nativeElement.select(); } + @HostListener('window:keydown.f5', ['$event']) + redirectToPayment(event: KeyboardEvent) { + event.preventDefault(); + } + + @HostListener('window:keydown.f6', ['$event']) + redirectToReciept(event: KeyboardEvent) { + event.preventDefault(); + this.router.navigate(['receipt'], { + queryParams: { + a: this.form.controls.paymentAccount.value, + }, + }); + } + + @HostListener('window:keydown.f7', ['$event']) + redirectToJournal(event: KeyboardEvent) { + event.preventDefault(); + this.router.navigate(['journal']); + } + @HostListener('window:keydown.control.s', ['$event']) saveListner(event: KeyboardEvent) { event.preventDefault(); diff --git a/overlord/src/app/receipt/receipt.component.ts b/overlord/src/app/receipt/receipt.component.ts index 637aefdd..f2048185 100644 --- a/overlord/src/app/receipt/receipt.component.ts +++ b/overlord/src/app/receipt/receipt.component.ts @@ -132,6 +132,27 @@ export class ReceiptComponent implements OnInit, AfterViewInit { this.dateElement.nativeElement.select(); } + @HostListener('window:keydown.f5', ['$event']) + redirectToPayment(event: KeyboardEvent) { + event.preventDefault(); + this.router.navigate(['payment'], { + queryParams: { + a: this.form.controls.receiptAccount.value, + }, + }); + } + + @HostListener('window:keydown.f6', ['$event']) + redirectToReciept(event: KeyboardEvent) { + event.preventDefault(); + } + + @HostListener('window:keydown.f7', ['$event']) + redirectToJournal(event: KeyboardEvent) { + event.preventDefault(); + this.router.navigate(['journal']); + } + @HostListener('window:keydown.control.s', ['$event']) saveListner(event: KeyboardEvent) { event.preventDefault();