Fix: Show section wise settlement and tax

This commit is contained in:
Amritanshu Agrawal 2024-12-17 09:46:44 +05:30
parent 3bfa00364c
commit 85a939b761
2 changed files with 23 additions and 15 deletions

View File

@ -48,9 +48,9 @@ def get_sale_report(
amounts=(
get_sale(start_date, finish_date, section, db)
+ [SaleReportItem(name="--", amount=Decimal(0))]
+ get_settlements(start_date, finish_date, db)
+ get_settlements(start_date, finish_date, section, db)
+ [SaleReportItem(name="--", amount=Decimal(0))]
+ [SaleReportItem(name=i.name, amount=i.amount) for i in get_tax(start_date, finish_date, db)]
+ [SaleReportItem(name=i.name, amount=i.amount) for i in get_tax(start_date, finish_date, section, db)]
),
user=UserLink(id_=user.id_, name=user.name),
)
@ -100,7 +100,7 @@ def get_sale(s: date, f: date, id_: uuid.UUID | None, db: Session) -> list[SaleR
return info + [SaleReportItem(name="Total Settled", amount=total)]
def get_settlements(s: date, f: date, db: Session) -> list[SaleReportItem]:
def get_settlements(s: date, f: date, id_: uuid.UUID | None, db: Session) -> list[SaleReportItem]:
start_date = datetime.combine(s, time()) + timedelta(
minutes=settings.NEW_DAY_OFFSET_MINUTES - settings.TIMEZONE_OFFSET_MINUTES
)
@ -108,14 +108,17 @@ def get_settlements(s: date, f: date, db: Session) -> list[SaleReportItem]:
days=1, minutes=settings.NEW_DAY_OFFSET_MINUTES - settings.TIMEZONE_OFFSET_MINUTES
)
list_ = db.execute(
query = (
select(SettleOption.name, func.sum(Settlement.amount))
.join(Voucher.settlements)
.join(Settlement.settle_option)
.join(Voucher.food_table)
.where(Voucher.date >= start_date, Voucher.date <= finish_date)
.group_by(SettleOption.name)
.order_by(SettleOption.name)
).all()
)
if id_:
query = query.where(FoodTable.section_id == id_)
query = query.group_by(SettleOption.name).order_by(SettleOption.name)
list_ = db.execute(query).all()
total = Decimal(0)
info = []
for gt, am in list_:
@ -141,9 +144,9 @@ def print_report(
amounts=(
get_sale(start_date, finish_date, section, db)
+ [SaleReportItem(name="--", amount=Decimal(0))]
+ get_settlements(start_date, finish_date, db)
+ get_settlements(start_date, finish_date, section, db)
+ [SaleReportItem(name="--", amount=Decimal(0))]
+ [SaleReportItem(name=i.name, amount=i.amount) for i in get_tax(start_date, finish_date, db)]
+ [SaleReportItem(name=i.name, amount=i.amount) for i in get_tax(start_date, finish_date, section, db)]
),
user=UserLink(id_=user.id_, name=user.name),
)

View File

@ -1,4 +1,5 @@
import re
import uuid
from datetime import date, datetime, time, timedelta
from decimal import Decimal
@ -10,6 +11,7 @@ from sqlalchemy.orm import Session
from ...core.config import settings
from ...core.security import get_current_active_user as get_user
from ...db.session import SessionFuture
from ...models.food_table import FoodTable
from ...models.inventory import Inventory
from ...models.kot import Kot
from ...models.tax import Tax
@ -34,11 +36,11 @@ def get_tax_report(
return TaxReport(
start_date=start_date,
finish_date=finish_date,
amounts=get_tax(start_date, finish_date, db),
amounts=get_tax(start_date, finish_date, None, db),
)
def get_tax(s: date, f: date, db: Session) -> list[TaxReportItem]:
def get_tax(s: date, f: date, id_: uuid.UUID | None, db: Session) -> list[TaxReportItem]:
start_date = datetime.combine(s, time()) + timedelta(
minutes=settings.NEW_DAY_OFFSET_MINUTES - settings.TIMEZONE_OFFSET_MINUTES
)
@ -46,7 +48,7 @@ def get_tax(s: date, f: date, db: Session) -> list[TaxReportItem]:
days=1, minutes=settings.NEW_DAY_OFFSET_MINUTES - settings.TIMEZONE_OFFSET_MINUTES
)
amounts = db.execute(
query = (
select(
Tax.name,
Inventory.tax_rate,
@ -56,14 +58,17 @@ def get_tax(s: date, f: date, db: Session) -> list[TaxReportItem]:
.join(Voucher.kots)
.join(Kot.inventories)
.join(Inventory.tax)
.join(Voucher.food_table)
.where(
Voucher.date >= start_date,
Voucher.date <= finish_date,
Voucher.voucher_type == VoucherType.REGULAR_BILL,
)
.group_by(Tax.name, Inventory.tax_rate)
.order_by(Tax.name, Inventory.tax_rate)
).all()
)
if id_:
query = query.where(FoodTable.section_id == id_)
query = query.group_by(Tax.name, Inventory.tax_rate).order_by(Tax.name, Inventory.tax_rate)
amounts = db.execute(query).all()
return sum([get_tax_item(*i) for i in amounts], [])