Fix: Receive Payment
Since the amount Behaviour Subject pipe was not being subscribed to and the original Behaviour Subject as being subscribed, amountVal was not being populated. Now it will be. This was creating problem where amount in receive payment was always 0 Added a check in the backend so that if any part of bill remains unsettled, it will give an error instead of silently accepting and removing the entry.
This commit is contained in:
parent
36915b41c1
commit
8bb6235e67
@ -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:
|
||||
|
@ -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()
|
||||
|
@ -15,7 +15,7 @@ class ReceivePaymentItem(BaseModel):
|
||||
|
||||
|
||||
class ReceivePayment(BaseModel):
|
||||
name: str
|
||||
reason: str
|
||||
amounts: List[ReceivePaymentItem]
|
||||
|
||||
class Config:
|
||||
|
@ -30,9 +30,10 @@ export class BillService {
|
||||
public netAmount: BehaviorSubject<number>;
|
||||
public discountAmount: BehaviorSubject<number>;
|
||||
public taxAmount: BehaviorSubject<number>;
|
||||
public amount: BehaviorSubject<number>;
|
||||
public amount: Observable<number>;
|
||||
public amountVal: number;
|
||||
public selection = new SelectionModel<string>(true, []);
|
||||
private amountBs: BehaviorSubject<number>;
|
||||
|
||||
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<boolean> {
|
||||
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) =>
|
||||
|
@ -117,12 +117,12 @@ export class VoucherService {
|
||||
receivePayment(
|
||||
id: string,
|
||||
amounts: { id: number; name: string; amount: number }[],
|
||||
name: string,
|
||||
reason: string,
|
||||
updateTable: boolean,
|
||||
): Observable<boolean> {
|
||||
const options = { params: new HttpParams().set('u', updateTable.toString()) };
|
||||
return this.http
|
||||
.post<boolean>(`${url}/receive-payment/${id}`, { name, amounts }, options)
|
||||
.post<boolean>(`${url}/receive-payment/${id}`, { reason, amounts }, options)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'receivePayment'))) as Observable<boolean>;
|
||||
}
|
||||
|
||||
|
@ -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: {
|
||||
|
Loading…
x
Reference in New Issue
Block a user