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
@ -1,5 +1,10 @@
|
|||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
|
||||||
def query_date(d: str = None) -> date:
|
def query_date(d: str = None) -> date:
|
||||||
return date.today() if d is None else datetime.strptime(d, "%d-%b-%Y").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):
|
def query_product_info(item: ProductVersion, happy_hour: bool):
|
||||||
return {
|
return {
|
||||||
"id": item.id,
|
"id": item.product_id,
|
||||||
"name": ("H H " if happy_hour else "") + item.full_name,
|
"name": ("H H " if happy_hour else "") + item.full_name,
|
||||||
"saleCategory": {
|
"saleCategory": {
|
||||||
"id": item.sale_category_id,
|
"id": item.sale_category_id,
|
||||||
|
@ -13,7 +13,7 @@ from ..db.session import SessionLocal
|
|||||||
from ..models import MenuCategory, ProductVersion
|
from ..models import MenuCategory, ProductVersion
|
||||||
from ..schemas.auth import UserToken
|
from ..schemas.auth import UserToken
|
||||||
from ..schemas.update_product_prices import UpdateProductPrices, UpdateProductPricesItem
|
from ..schemas.update_product_prices import UpdateProductPrices, UpdateProductPricesItem
|
||||||
from . import query_date
|
from . import optional_query_date
|
||||||
|
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
@ -30,10 +30,15 @@ def get_db() -> Session:
|
|||||||
|
|
||||||
@router.get("", response_model=UpdateProductPrices)
|
@router.get("", response_model=UpdateProductPrices)
|
||||||
def get_update_product_prices(
|
def get_update_product_prices(
|
||||||
date_: date = Depends(query_date),
|
date_: Optional[date] = Depends(optional_query_date),
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
user: UserToken = Security(get_user, scopes=["products"]),
|
user: UserToken = Security(get_user, scopes=["products"]),
|
||||||
) -> UpdateProductPrices:
|
) -> UpdateProductPrices:
|
||||||
|
if date_ is None:
|
||||||
|
return UpdateProductPrices(
|
||||||
|
date=date.today(),
|
||||||
|
items=[],
|
||||||
|
)
|
||||||
return UpdateProductPrices(
|
return UpdateProductPrices(
|
||||||
date=date_,
|
date=date_,
|
||||||
items=update_product_prices_list(None, date_, db),
|
items=update_product_prices_list(None, date_, db),
|
||||||
@ -43,10 +48,16 @@ def get_update_product_prices(
|
|||||||
@router.get("/{id_}", response_model=UpdateProductPrices)
|
@router.get("/{id_}", response_model=UpdateProductPrices)
|
||||||
def get_update_product_prices_id(
|
def get_update_product_prices_id(
|
||||||
id_: uuid.UUID,
|
id_: uuid.UUID,
|
||||||
date_: date = Depends(query_date),
|
date_: Optional[date] = Depends(optional_query_date),
|
||||||
db: Session = Depends(get_db),
|
db: Session = Depends(get_db),
|
||||||
user: UserToken = Security(get_user, scopes=["products"]),
|
user: UserToken = Security(get_user, scopes=["products"]),
|
||||||
) -> UpdateProductPrices:
|
) -> UpdateProductPrices:
|
||||||
|
if date_ is None:
|
||||||
|
return UpdateProductPrices(
|
||||||
|
date=date.today(),
|
||||||
|
menuCategoryId=id_,
|
||||||
|
items=[],
|
||||||
|
)
|
||||||
return UpdateProductPrices(
|
return UpdateProductPrices(
|
||||||
date=date_,
|
date=date_,
|
||||||
menuCategoryId=id_,
|
menuCategoryId=id_,
|
||||||
|
@ -85,7 +85,7 @@ def do_save(
|
|||||||
user: UserToken,
|
user: UserToken,
|
||||||
):
|
):
|
||||||
now = datetime.now()
|
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)
|
check_permissions(None, voucher_type, user.permissions)
|
||||||
|
|
||||||
bill_id = get_bill_id(voucher_type, db)
|
bill_id = get_bill_id(voucher_type, db)
|
||||||
|
@ -57,7 +57,7 @@ def update(
|
|||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
now = datetime.now()
|
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
|
update_table = u
|
||||||
voucher_type = VoucherType[p]
|
voucher_type = VoucherType[p]
|
||||||
guest_book = get_guest_book(g, db)
|
guest_book = get_guest_book(g, db)
|
||||||
|
@ -10,4 +10,8 @@ export class MenuCategory {
|
|||||||
sortOrder: number;
|
sortOrder: number;
|
||||||
products: Product[];
|
products: Product[];
|
||||||
enabled?: boolean;
|
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) {}
|
constructor(private ser: UpdateProductPricesService) {}
|
||||||
|
|
||||||
resolve(route: ActivatedRouteSnapshot): Observable<UpdateProductPrices> {
|
resolve(route: ActivatedRouteSnapshot): Observable<UpdateProductPrices> {
|
||||||
const startDate = route.queryParamMap.get('startDate') || null;
|
const date = route.queryParamMap.get('date') || null;
|
||||||
const finishDate = route.queryParamMap.get('finishDate') || null;
|
|
||||||
const id = route.paramMap.get('id');
|
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-datepicker #date></mat-datepicker>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
<mat-form-field fxFlex>
|
<mat-form-field fxFlex>
|
||||||
<mat-label>Section</mat-label>
|
<mat-label>Menu Category</mat-label>
|
||||||
<mat-select placeholder="Section" formControlName="menuCategory">
|
<mat-select placeholder="Menu Category" formControlName="menuCategory">
|
||||||
<mat-option *ngFor="let s of menuCategories" [value]="s.id">
|
<mat-option *ngFor="let s of menuCategories" [value]="s.id">
|
||||||
{{ s.name }}
|
{{ s.name }}
|
||||||
</mat-option>
|
</mat-option>
|
||||||
|
@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core';
|
|||||||
import { FormArray, FormBuilder, FormGroup } from '@angular/forms';
|
import { FormArray, FormBuilder, FormGroup } from '@angular/forms';
|
||||||
import { ActivatedRoute, Router } from '@angular/router';
|
import { ActivatedRoute, Router } from '@angular/router';
|
||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
|
import { map } from 'rxjs/operators';
|
||||||
|
|
||||||
import { MenuCategory } from '../core/menu-category';
|
import { MenuCategory } from '../core/menu-category';
|
||||||
import { ToasterService } from '../core/toaster.service';
|
import { ToasterService } from '../core/toaster.service';
|
||||||
@ -37,12 +38,17 @@ export class UpdateProductPricesComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.route.data.subscribe(
|
this.route.data
|
||||||
(data: { menuCategories: MenuCategory[]; info: UpdateProductPrices }) => {
|
.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.menuCategories = data.menuCategories;
|
||||||
this.loadData(data.info);
|
this.loadData(data.info);
|
||||||
},
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
loadData(info: UpdateProductPrices) {
|
loadData(info: UpdateProductPrices) {
|
||||||
@ -67,7 +73,7 @@ export class UpdateProductPricesComponent implements OnInit {
|
|||||||
show() {
|
show() {
|
||||||
const info = this.getInfo();
|
const info = this.getInfo();
|
||||||
const route = ['update-product-prices'];
|
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, {
|
this.router.navigate(route, {
|
||||||
queryParams: {
|
queryParams: {
|
||||||
date: info.date,
|
date: info.date,
|
||||||
|
@ -17,14 +17,11 @@ const serviceName = 'UpdateProductPricesService';
|
|||||||
export class UpdateProductPricesService {
|
export class UpdateProductPricesService {
|
||||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
|
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 getUrl: string = id === null ? url : `${url}/${id}`;
|
||||||
const options = { params: new HttpParams() };
|
const options = { params: new HttpParams() };
|
||||||
if (startDate !== null) {
|
if (date !== null) {
|
||||||
options.params = options.params.set('s', startDate);
|
options.params = options.params.set('d', date);
|
||||||
}
|
|
||||||
if (finishDate !== null) {
|
|
||||||
options.params = options.params.set('f', finishDate);
|
|
||||||
}
|
}
|
||||||
return <Observable<UpdateProductPrices>>(
|
return <Observable<UpdateProductPrices>>(
|
||||||
this.http
|
this.http
|
||||||
|
Loading…
x
Reference in New Issue
Block a user