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()
|
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: List[SettleSchema] = []
|
||||||
settlements += others
|
settlements += others
|
||||||
total_amount = voucher.amount
|
total_amount = voucher.amount
|
||||||
@ -106,6 +107,7 @@ def do_update_settlements(voucher: Voucher, others: List[SettleSchema], db: Sess
|
|||||||
)
|
)
|
||||||
if unsettled != 0:
|
if unsettled != 0:
|
||||||
settlements.append(SettleSchema(id=SettleOption.UNSETTLED(), amount=unsettled))
|
settlements.append(SettleSchema(id=SettleOption.UNSETTLED(), amount=unsettled))
|
||||||
|
fully_settled = False
|
||||||
|
|
||||||
for i in settlements:
|
for i in settlements:
|
||||||
old = [s for s in voucher.settlements if s.settled == i.id_]
|
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]):
|
for i in (i for i in voucher.settlements if i.settled not in [x.id_ for x in settlements]):
|
||||||
voucher.settlements.remove(i)
|
voucher.settlements.remove(i)
|
||||||
db.delete(i)
|
db.delete(i)
|
||||||
|
return fully_settled
|
||||||
|
|
||||||
|
|
||||||
def happy_hour_items_balanced(inventories: List[schemas.Inventory]) -> bool:
|
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()
|
item: Voucher = db.query(Voucher).filter(Voucher.id == id_).first()
|
||||||
|
|
||||||
if item.voucher_type in [VoucherType.NO_CHARGE, VoucherType.STAFF]:
|
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:
|
if update_table:
|
||||||
db.query(Overview).filter(Overview.voucher_id == item.id).delete()
|
db.query(Overview).filter(Overview.voucher_id == item.id).delete()
|
||||||
|
@ -15,7 +15,7 @@ class ReceivePaymentItem(BaseModel):
|
|||||||
|
|
||||||
|
|
||||||
class ReceivePayment(BaseModel):
|
class ReceivePayment(BaseModel):
|
||||||
name: str
|
reason: str
|
||||||
amounts: List[ReceivePaymentItem]
|
amounts: List[ReceivePaymentItem]
|
||||||
|
|
||||||
class Config:
|
class Config:
|
||||||
|
@ -30,9 +30,10 @@ export class BillService {
|
|||||||
public netAmount: BehaviorSubject<number>;
|
public netAmount: BehaviorSubject<number>;
|
||||||
public discountAmount: BehaviorSubject<number>;
|
public discountAmount: BehaviorSubject<number>;
|
||||||
public taxAmount: BehaviorSubject<number>;
|
public taxAmount: BehaviorSubject<number>;
|
||||||
public amount: BehaviorSubject<number>;
|
public amount: Observable<number>;
|
||||||
public amountVal: number;
|
public amountVal: number;
|
||||||
public selection = new SelectionModel<string>(true, []);
|
public selection = new SelectionModel<string>(true, []);
|
||||||
|
private amountBs: BehaviorSubject<number>;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private dialog: MatDialog,
|
private dialog: MatDialog,
|
||||||
@ -44,9 +45,9 @@ export class BillService {
|
|||||||
this.netAmount = new BehaviorSubject(0);
|
this.netAmount = new BehaviorSubject(0);
|
||||||
this.discountAmount = new BehaviorSubject(0);
|
this.discountAmount = new BehaviorSubject(0);
|
||||||
this.taxAmount = new BehaviorSubject(0);
|
this.taxAmount = new BehaviorSubject(0);
|
||||||
this.amount = new BehaviorSubject(0);
|
this.amountBs = new BehaviorSubject(0);
|
||||||
this.amountVal = 0;
|
this.amountVal = 0;
|
||||||
this.amount.pipe(tap((x) => (this.amountVal = x)));
|
this.amount = this.amountBs.pipe(tap((x) => (this.amountVal = x)));
|
||||||
}
|
}
|
||||||
|
|
||||||
displayBill(): void {
|
displayBill(): void {
|
||||||
@ -248,10 +249,6 @@ export class BillService {
|
|||||||
return this.ser.saveOrUpdate(item, voucherType, guest_book_id, true);
|
return this.ser.saveOrUpdate(item, voucherType, guest_book_id, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
type() {
|
|
||||||
return this.bill.voucherType;
|
|
||||||
}
|
|
||||||
|
|
||||||
receivePayment(value: { choices: ReceivePaymentItem[]; reason: string }): Observable<boolean> {
|
receivePayment(value: { choices: ReceivePaymentItem[]; reason: string }): Observable<boolean> {
|
||||||
return this.ser.receivePayment(this.bill.id as string, value.choices, value.reason, true);
|
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(
|
round(
|
||||||
this.bill.kots.reduce(
|
this.bill.kots.reduce(
|
||||||
(t, k) =>
|
(t, k) =>
|
||||||
|
@ -117,12 +117,12 @@ export class VoucherService {
|
|||||||
receivePayment(
|
receivePayment(
|
||||||
id: string,
|
id: string,
|
||||||
amounts: { id: number; name: string; amount: number }[],
|
amounts: { id: number; name: string; amount: number }[],
|
||||||
name: string,
|
reason: string,
|
||||||
updateTable: boolean,
|
updateTable: boolean,
|
||||||
): Observable<boolean> {
|
): Observable<boolean> {
|
||||||
const options = { params: new HttpParams().set('u', updateTable.toString()) };
|
const options = { params: new HttpParams().set('u', updateTable.toString()) };
|
||||||
return this.http
|
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>;
|
.pipe(catchError(this.log.handleError(serviceName, 'receivePayment'))) as Observable<boolean>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,7 +192,7 @@ export class SalesHomeComponent {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const amount = this.bs.amountVal;
|
const amount = this.bs.amountVal;
|
||||||
const type = this.bs.type();
|
const type = this.bs.bill.voucherType;
|
||||||
this.dialog
|
this.dialog
|
||||||
.open(ReceivePaymentComponent, {
|
.open(ReceivePaymentComponent, {
|
||||||
data: {
|
data: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user