From 4fffdd85d6d13148000d3a17ad22136798712507 Mon Sep 17 00:00:00 2001 From: Amritanshu Date: Mon, 13 Mar 2023 20:38:55 +0530 Subject: [PATCH] Fix: Merge table did not delete the old bills and fucked up. Fix: Bill settlement report was not in order --- barker/barker/routers/reports/bill_settlement_report.py | 2 +- barker/barker/routers/voucher/merge_move.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/barker/barker/routers/reports/bill_settlement_report.py b/barker/barker/routers/reports/bill_settlement_report.py index 76a0d5e..28104bc 100644 --- a/barker/barker/routers/reports/bill_settlement_report.py +++ b/barker/barker/routers/reports/bill_settlement_report.py @@ -48,7 +48,7 @@ def settlements(s: date, f: date, db: Session) -> list[BillSettlementItem]: .join(Voucher.settlements) .join(Settlement.settle_option) .where(Voucher.date >= start_date, Voucher.date <= finish_date) - .order_by(Voucher.voucher_type) + .order_by(Voucher.voucher_type, Voucher.date) ) .unique() .scalars() diff --git a/barker/barker/routers/voucher/merge_move.py b/barker/barker/routers/voucher/merge_move.py index 8e7f66d..97616cf 100644 --- a/barker/barker/routers/voucher/merge_move.py +++ b/barker/barker/routers/voucher/merge_move.py @@ -1,3 +1,4 @@ +import traceback import uuid from datetime import datetime @@ -11,6 +12,7 @@ from sqlalchemy.orm import Session from ...core.security import get_current_active_user as get_user from ...db.session import SessionFuture +from ...models.bill import Bill from ...models.kot import Kot from ...models.overview import Overview from ...models.settlement import Settlement @@ -127,12 +129,14 @@ def merge_table( check_if_voucher_is_unprinted(data.voucher_id, db) check_if_voucher_is_unprinted(data.new_voucher_id, db) db.execute(update(Kot).where(Kot.voucher_id == data.voucher_id).values(voucher_id=data.new_voucher_id)) + db.execute(delete(Bill).where(Bill.voucher_id == data.voucher_id)) db.execute(delete(Overview).where(Overview.voucher_id == data.voucher_id)) db.execute(delete(Settlement).where(Settlement.voucher_id == data.voucher_id)) db.execute(delete(Voucher).where(Voucher.id == data.voucher_id)) update_settlements([data.new_voucher_id], db) db.commit() except SQLAlchemyError as e: + traceback.print_exc() raise HTTPException( status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(e),