Unposted Done!!
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
from typing import List
|
||||
|
||||
from fastapi import APIRouter, Depends, Security, Request
|
||||
from sqlalchemy.orm import joinedload_all, Session
|
||||
|
||||
@ -5,6 +7,7 @@ from ...schemas.auth import UserToken
|
||||
from ...core.security import get_current_active_user as get_user
|
||||
from ...db.session import SessionLocal
|
||||
from brewman.models.voucher import Voucher, Journal, VoucherType
|
||||
import brewman.schemas.reports as schemas
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@ -18,7 +21,7 @@ def get_db() -> Session:
|
||||
db.close()
|
||||
|
||||
|
||||
@router.get("")
|
||||
@router.get("", response_model=List[schemas.Unposted])
|
||||
def report_data(
|
||||
request: Request,
|
||||
db: Session = Depends(get_db),
|
||||
@ -59,7 +62,8 @@ def build_report(db: Session):
|
||||
{
|
||||
"id": voucher.id,
|
||||
"date": voucher.date.strftime("%d-%b-%Y"),
|
||||
"voucherType": VoucherType.by_id(voucher.type).name,
|
||||
"url": ['/', VoucherType.by_id(voucher.type).name.replace(" ", "-").lower(), str(voucher.id)],
|
||||
"type": VoucherType.by_id(voucher.type).name,
|
||||
"narration": voucher.narration,
|
||||
"debitName": name_debit,
|
||||
"debitAmount": debit,
|
||||
|
||||
@ -478,3 +478,26 @@ class TrialBalance(BaseModel):
|
||||
if isinstance(value, date):
|
||||
return value
|
||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||
|
||||
|
||||
class Unposted(BaseModel):
|
||||
id_: uuid.UUID
|
||||
date_: date
|
||||
url: List[str]
|
||||
type_: str
|
||||
narration: str
|
||||
debit_name: str
|
||||
debit_amount: Decimal
|
||||
credit_name: str
|
||||
credit_amount: Decimal
|
||||
|
||||
@validator("date_", pre=True)
|
||||
def parse_date(cls, value):
|
||||
if isinstance(value, date):
|
||||
return value
|
||||
return datetime.strptime(value, "%d-%b-%Y").date()
|
||||
|
||||
class Config:
|
||||
anystr_strip_whitespace = True
|
||||
alias_generator = to_camel
|
||||
json_encoders = {date: lambda v: v.strftime("%d-%b-%Y")}
|
||||
|
||||
Reference in New Issue
Block a user