Choose / Edit / Create customers during billing.
This commit is contained in:
@ -5,7 +5,7 @@ from typing import List
|
||||
import barker.schemas.customer as schemas
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Security, status
|
||||
from sqlalchemy import or_, select
|
||||
from sqlalchemy import delete, or_, select
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
@ -62,7 +62,7 @@ def update_route(
|
||||
)
|
||||
|
||||
|
||||
def add_discounts(customer: Customer, discounts: List[schemas.DiscountItem], db: Session):
|
||||
def add_discounts(customer: Customer, discounts: List[schemas.DiscountItem], db: Session) -> None:
|
||||
for discount in discounts:
|
||||
cd = next((d for d in customer.discounts if d.sale_category_id == discount.id_), None)
|
||||
if cd is None:
|
||||
@ -77,10 +77,10 @@ def add_discounts(customer: Customer, discounts: List[schemas.DiscountItem], db:
|
||||
def delete_route(
|
||||
id_: uuid.UUID,
|
||||
user: UserToken = Security(get_user, scopes=["customers"]),
|
||||
):
|
||||
) -> None:
|
||||
with SessionFuture() as db:
|
||||
item: Customer = db.execute(select(Customer).where(Customer.id == id_)).scalar_one()
|
||||
db.delete(item)
|
||||
db.execute(delete(CustomerDiscount).where(CustomerDiscount.customer_id == id_))
|
||||
db.execute(delete(Customer).where(Customer.id == id_))
|
||||
db.commit()
|
||||
|
||||
|
||||
@ -88,7 +88,8 @@ def delete_route(
|
||||
def show_blank(
|
||||
user: UserToken = Security(get_user, scopes=["customers"]),
|
||||
) -> schemas.CustomerBlank:
|
||||
return blank_customer_info()
|
||||
with SessionFuture() as db:
|
||||
return blank_customer_info(db)
|
||||
|
||||
|
||||
@router.get("/list", response_model=List[schemas.Customer])
|
||||
@ -162,5 +163,18 @@ def customer_info_for_list(item: Customer) -> schemas.Customer:
|
||||
)
|
||||
|
||||
|
||||
def blank_customer_info() -> schemas.CustomerBlank:
|
||||
return schemas.CustomerBlank(name="", address="", phone="", printInBill=False, discounts=[])
|
||||
def blank_customer_info(db: Session) -> schemas.CustomerBlank:
|
||||
return schemas.CustomerBlank(
|
||||
name="",
|
||||
address="",
|
||||
phone="",
|
||||
printInBill=False,
|
||||
discounts=[
|
||||
{
|
||||
"id": sc.id,
|
||||
"name": sc.name,
|
||||
"discount": 0,
|
||||
}
|
||||
for sc in db.execute(select(SaleCategory).order_by(SaleCategory.name)).scalars().all()
|
||||
],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user