Fix: Save/Update voucher - timedelta was days instead of minutes
Fix: Product list for sale was sending product_version_id instead of version_id this was borking on products with multiple versions Change: Update Product Prices initially does not show list. Only the date and Menu Category List
This commit is contained in:
parent
9317150bde
commit
67cb1e3d80
barker/barker/routers
bookie/src/app
@ -1,5 +1,10 @@
|
||||
from datetime import date, datetime
|
||||
from typing import Optional
|
||||
|
||||
|
||||
def query_date(d: str = None) -> date:
|
||||
return date.today() if d is None else datetime.strptime(d, "%d-%b-%Y").date()
|
||||
|
||||
|
||||
def optional_query_date(d: str = None) -> Optional[date]:
|
||||
return None if d is None else datetime.strptime(d, "%d-%b-%Y").date()
|
||||
|
@ -366,7 +366,7 @@ def show_id(
|
||||
|
||||
def query_product_info(item: ProductVersion, happy_hour: bool):
|
||||
return {
|
||||
"id": item.id,
|
||||
"id": item.product_id,
|
||||
"name": ("H H " if happy_hour else "") + item.full_name,
|
||||
"saleCategory": {
|
||||
"id": item.sale_category_id,
|
||||
|
@ -13,7 +13,7 @@ from ..db.session import SessionLocal
|
||||
from ..models import MenuCategory, ProductVersion
|
||||
from ..schemas.auth import UserToken
|
||||
from ..schemas.update_product_prices import UpdateProductPrices, UpdateProductPricesItem
|
||||
from . import query_date
|
||||
from . import optional_query_date
|
||||
|
||||
|
||||
router = APIRouter()
|
||||
@ -30,10 +30,15 @@ def get_db() -> Session:
|
||||
|
||||
@router.get("", response_model=UpdateProductPrices)
|
||||
def get_update_product_prices(
|
||||
date_: date = Depends(query_date),
|
||||
date_: Optional[date] = Depends(optional_query_date),
|
||||
db: Session = Depends(get_db),
|
||||
user: UserToken = Security(get_user, scopes=["products"]),
|
||||
) -> UpdateProductPrices:
|
||||
if date_ is None:
|
||||
return UpdateProductPrices(
|
||||
date=date.today(),
|
||||
items=[],
|
||||
)
|
||||
return UpdateProductPrices(
|
||||
date=date_,
|
||||
items=update_product_prices_list(None, date_, db),
|
||||
@ -43,10 +48,16 @@ def get_update_product_prices(
|
||||
@router.get("/{id_}", response_model=UpdateProductPrices)
|
||||
def get_update_product_prices_id(
|
||||
id_: uuid.UUID,
|
||||
date_: date = Depends(query_date),
|
||||
date_: Optional[date] = Depends(optional_query_date),
|
||||
db: Session = Depends(get_db),
|
||||
user: UserToken = Security(get_user, scopes=["products"]),
|
||||
) -> UpdateProductPrices:
|
||||
if date_ is None:
|
||||
return UpdateProductPrices(
|
||||
date=date.today(),
|
||||
menuCategoryId=id_,
|
||||
items=[],
|
||||
)
|
||||
return UpdateProductPrices(
|
||||
date=date_,
|
||||
menuCategoryId=id_,
|
||||
|
@ -85,7 +85,7 @@ def do_save(
|
||||
user: UserToken,
|
||||
):
|
||||
now = datetime.now()
|
||||
product_date = (now - timedelta(days=settings.NEW_DAY_OFFSET_MINUTES)).date()
|
||||
product_date = (now - timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES)).date()
|
||||
check_permissions(None, voucher_type, user.permissions)
|
||||
|
||||
bill_id = get_bill_id(voucher_type, db)
|
||||
|
@ -57,7 +57,7 @@ def update(
|
||||
):
|
||||
try:
|
||||
now = datetime.now()
|
||||
product_date = (now - timedelta(days=settings.NEW_DAY_OFFSET_MINUTES)).date()
|
||||
product_date = (now - timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES)).date()
|
||||
update_table = u
|
||||
voucher_type = VoucherType[p]
|
||||
guest_book = get_guest_book(g, db)
|
||||
|
@ -10,4 +10,8 @@ export class MenuCategory {
|
||||
sortOrder: number;
|
||||
products: Product[];
|
||||
enabled?: boolean;
|
||||
|
||||
public constructor(init?: Partial<MenuCategory>) {
|
||||
Object.assign(this, init);
|
||||
}
|
||||
}
|
||||
|
@ -12,9 +12,8 @@ export class UpdateProductPricesResolver implements Resolve<UpdateProductPrices>
|
||||
constructor(private ser: UpdateProductPricesService) {}
|
||||
|
||||
resolve(route: ActivatedRouteSnapshot): Observable<UpdateProductPrices> {
|
||||
const startDate = route.queryParamMap.get('startDate') || null;
|
||||
const finishDate = route.queryParamMap.get('finishDate') || null;
|
||||
const date = route.queryParamMap.get('date') || null;
|
||||
const id = route.paramMap.get('id');
|
||||
return this.ser.get(id, startDate, finishDate);
|
||||
return this.ser.get(id, date);
|
||||
}
|
||||
}
|
||||
|
@ -27,8 +27,8 @@
|
||||
<mat-datepicker #date></mat-datepicker>
|
||||
</mat-form-field>
|
||||
<mat-form-field fxFlex>
|
||||
<mat-label>Section</mat-label>
|
||||
<mat-select placeholder="Section" formControlName="menuCategory">
|
||||
<mat-label>Menu Category</mat-label>
|
||||
<mat-select placeholder="Menu Category" formControlName="menuCategory">
|
||||
<mat-option *ngFor="let s of menuCategories" [value]="s.id">
|
||||
{{ s.name }}
|
||||
</mat-option>
|
||||
|
@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core';
|
||||
import { FormArray, FormBuilder, FormGroup } from '@angular/forms';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import * as moment from 'moment';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
import { MenuCategory } from '../core/menu-category';
|
||||
import { ToasterService } from '../core/toaster.service';
|
||||
@ -37,12 +38,17 @@ export class UpdateProductPricesComponent implements OnInit {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data.subscribe(
|
||||
(data: { menuCategories: MenuCategory[]; info: UpdateProductPrices }) => {
|
||||
this.route.data
|
||||
.pipe(
|
||||
map((data: { menuCategories: MenuCategory[]; info: UpdateProductPrices }) => {
|
||||
data.menuCategories.unshift(new MenuCategory({ id: null, name: '-- All Categories --' }));
|
||||
return data;
|
||||
}),
|
||||
)
|
||||
.subscribe((data: { menuCategories: MenuCategory[]; info: UpdateProductPrices }) => {
|
||||
this.menuCategories = data.menuCategories;
|
||||
this.loadData(data.info);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
loadData(info: UpdateProductPrices) {
|
||||
@ -67,7 +73,7 @@ export class UpdateProductPricesComponent implements OnInit {
|
||||
show() {
|
||||
const info = this.getInfo();
|
||||
const route = ['update-product-prices'];
|
||||
if (info.menuCategoryId !== undefined) route.push(info.menuCategoryId);
|
||||
if (info.menuCategoryId !== null) route.push(info.menuCategoryId);
|
||||
this.router.navigate(route, {
|
||||
queryParams: {
|
||||
date: info.date,
|
||||
|
@ -17,14 +17,11 @@ const serviceName = 'UpdateProductPricesService';
|
||||
export class UpdateProductPricesService {
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
|
||||
|
||||
get(id: string, startDate: string, finishDate): Observable<UpdateProductPrices> {
|
||||
get(id: string, date: string): Observable<UpdateProductPrices> {
|
||||
const getUrl: string = id === null ? url : `${url}/${id}`;
|
||||
const options = { params: new HttpParams() };
|
||||
if (startDate !== null) {
|
||||
options.params = options.params.set('s', startDate);
|
||||
}
|
||||
if (finishDate !== null) {
|
||||
options.params = options.params.set('f', finishDate);
|
||||
if (date !== null) {
|
||||
options.params = options.params.set('d', date);
|
||||
}
|
||||
return <Observable<UpdateProductPrices>>(
|
||||
this.http
|
||||
|
Loading…
x
Reference in New Issue
Block a user