diff --git a/barker/barker/routers/voucher/__init__.py b/barker/barker/routers/voucher/__init__.py index 847babc..7b9c00f 100644 --- a/barker/barker/routers/voucher/__init__.py +++ b/barker/barker/routers/voucher/__init__.py @@ -90,7 +90,8 @@ def get_guest_book(id_: uuid.UUID, db: Session): return db.query(GuestBook).filter(GuestBook.id == id_).first() -def do_update_settlements(voucher: Voucher, others: List[SettleSchema], db: Session): +def do_update_settlements(voucher: Voucher, others: List[SettleSchema], db: Session) -> bool: + fully_settled = True settlements: List[SettleSchema] = [] settlements += others total_amount = voucher.amount @@ -106,6 +107,7 @@ def do_update_settlements(voucher: Voucher, others: List[SettleSchema], db: Sess ) if unsettled != 0: settlements.append(SettleSchema(id=SettleOption.UNSETTLED(), amount=unsettled)) + fully_settled = False for i in settlements: old = [s for s in voucher.settlements if s.settled == i.id_] @@ -119,6 +121,7 @@ def do_update_settlements(voucher: Voucher, others: List[SettleSchema], db: Sess for i in (i for i in voucher.settlements if i.settled not in [x.id_ for x in settlements]): voucher.settlements.remove(i) db.delete(i) + return fully_settled def happy_hour_items_balanced(inventories: List[schemas.Inventory]) -> bool: diff --git a/barker/barker/routers/voucher/receive_payment.py b/barker/barker/routers/voucher/receive_payment.py index 1921d42..a7e7705 100644 --- a/barker/barker/routers/voucher/receive_payment.py +++ b/barker/barker/routers/voucher/receive_payment.py @@ -44,9 +44,13 @@ def update( item: Voucher = db.query(Voucher).filter(Voucher.id == id_).first() if item.voucher_type in [VoucherType.NO_CHARGE, VoucherType.STAFF]: - item.reason = data.name.title() + item.reason = data.reason.title() - do_update_settlements(item, amounts, db) + if not do_update_settlements(item, amounts, db): + raise HTTPException( + status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, + detail="Bill amount not fully settled", + ) if update_table: db.query(Overview).filter(Overview.voucher_id == item.id).delete() diff --git a/barker/barker/schemas/receive_payment.py b/barker/barker/schemas/receive_payment.py index c92b22e..ff43de6 100644 --- a/barker/barker/schemas/receive_payment.py +++ b/barker/barker/schemas/receive_payment.py @@ -15,7 +15,7 @@ class ReceivePaymentItem(BaseModel): class ReceivePayment(BaseModel): - name: str + reason: str amounts: List[ReceivePaymentItem] class Config: diff --git a/bookie/src/app/sales/bill.service.ts b/bookie/src/app/sales/bill.service.ts index cbc474f..3f64136 100644 --- a/bookie/src/app/sales/bill.service.ts +++ b/bookie/src/app/sales/bill.service.ts @@ -30,9 +30,10 @@ export class BillService { public netAmount: BehaviorSubject; public discountAmount: BehaviorSubject; public taxAmount: BehaviorSubject; - public amount: BehaviorSubject; + public amount: Observable; public amountVal: number; public selection = new SelectionModel(true, []); + private amountBs: BehaviorSubject; constructor( private dialog: MatDialog, @@ -44,9 +45,9 @@ export class BillService { this.netAmount = new BehaviorSubject(0); this.discountAmount = new BehaviorSubject(0); this.taxAmount = new BehaviorSubject(0); - this.amount = new BehaviorSubject(0); + this.amountBs = new BehaviorSubject(0); this.amountVal = 0; - this.amount.pipe(tap((x) => (this.amountVal = x))); + this.amount = this.amountBs.pipe(tap((x) => (this.amountVal = x))); } displayBill(): void { @@ -248,10 +249,6 @@ export class BillService { return this.ser.saveOrUpdate(item, voucherType, guest_book_id, true); } - type() { - return this.bill.voucherType; - } - receivePayment(value: { choices: ReceivePaymentItem[]; reason: string }): Observable { return this.ser.receivePayment(this.bill.id as string, value.choices, value.reason, true); } @@ -311,7 +308,7 @@ export class BillService { ), ), ); - this.amount.next( + this.amountBs.next( round( this.bill.kots.reduce( (t, k) => diff --git a/bookie/src/app/sales/bills/voucher.service.ts b/bookie/src/app/sales/bills/voucher.service.ts index ca1884b..a6e7f9c 100644 --- a/bookie/src/app/sales/bills/voucher.service.ts +++ b/bookie/src/app/sales/bills/voucher.service.ts @@ -117,12 +117,12 @@ export class VoucherService { receivePayment( id: string, amounts: { id: number; name: string; amount: number }[], - name: string, + reason: string, updateTable: boolean, ): Observable { const options = { params: new HttpParams().set('u', updateTable.toString()) }; return this.http - .post(`${url}/receive-payment/${id}`, { name, amounts }, options) + .post(`${url}/receive-payment/${id}`, { reason, amounts }, options) .pipe(catchError(this.log.handleError(serviceName, 'receivePayment'))) as Observable; } diff --git a/bookie/src/app/sales/home/sales-home.component.ts b/bookie/src/app/sales/home/sales-home.component.ts index d634f79..b6e7f9f 100644 --- a/bookie/src/app/sales/home/sales-home.component.ts +++ b/bookie/src/app/sales/home/sales-home.component.ts @@ -192,7 +192,7 @@ export class SalesHomeComponent { return; } const amount = this.bs.amountVal; - const type = this.bs.type(); + const type = this.bs.bill.voucherType; this.dialog .open(ReceivePaymentComponent, { data: {