Ledger now working with response_model
get_edit_url workaround found with transform clientside
This commit is contained in:
@ -83,7 +83,6 @@ def build_report(start_date, finish_date, db):
|
||||
{
|
||||
"id": voucher.id,
|
||||
"date": voucher.date.strftime("%d-%b-%Y"),
|
||||
"url": "", # get_edit_url(voucher, request),
|
||||
"type": VoucherType.by_id(voucher.type).name,
|
||||
"narration": voucher.narration,
|
||||
"posted": voucher.posted,
|
||||
|
||||
@ -10,6 +10,7 @@ from ...core.security import get_current_active_user as get_user
|
||||
from ...db.session import SessionLocal
|
||||
from brewman.models.master import AccountBase
|
||||
from brewman.models.voucher import Voucher, Journal, VoucherType
|
||||
import brewman.schemas.reports as schemas
|
||||
from ...core.session import (
|
||||
set_period,
|
||||
get_start_date,
|
||||
@ -28,7 +29,7 @@ def get_db() -> Session:
|
||||
db.close()
|
||||
|
||||
|
||||
@router.get("")
|
||||
@router.get("", response_model=schemas.Ledger)
|
||||
def show_blank(
|
||||
request: Request,
|
||||
user: UserToken = Security(get_user, scopes=["ledger"]),
|
||||
@ -41,7 +42,7 @@ def show_blank(
|
||||
}
|
||||
|
||||
|
||||
@router.get("/{id_}")
|
||||
@router.get("/{id_}", response_model=schemas.Ledger)
|
||||
def show_data(
|
||||
id_: uuid.UUID,
|
||||
request: Request,
|
||||
@ -103,7 +104,6 @@ def build_report(account_id, start_date, finish_date, db):
|
||||
"id": voucher.id,
|
||||
"date": voucher.date.strftime("%d-%b-%Y"),
|
||||
"name": name,
|
||||
"url": "", # get_edit_url(voucher, request),
|
||||
"type": VoucherType.by_id(voucher.type).name,
|
||||
"narration": voucher.narration,
|
||||
"debit": debit,
|
||||
@ -132,7 +132,7 @@ def opening_balance(account_id, start_date, db):
|
||||
credit = 0
|
||||
return {
|
||||
"date": start_date,
|
||||
"id": "OB",
|
||||
"id": None,
|
||||
"name": "Opening Balance",
|
||||
"type": "Opening Balance",
|
||||
"narration": "",
|
||||
|
||||
@ -107,7 +107,6 @@ def build_report(product_id, start_date, finish_date, db):
|
||||
"id": row.Voucher.id,
|
||||
"date": row.Voucher.date.strftime("%d-%b-%Y"),
|
||||
"name": name,
|
||||
"url": "", # get_edit_url(row.Voucher, request),
|
||||
"type": VoucherType.by_id(row.Voucher.type).name,
|
||||
"narration": row.Voucher.narration,
|
||||
"posted": row.Voucher.posted
|
||||
|
||||
@ -70,7 +70,6 @@ def build_report(start_date, finish_date, db):
|
||||
row = {
|
||||
"date": voucher.date.strftime("%d-%b-%Y"),
|
||||
"supplier": journal.account.name,
|
||||
"url": "", # get_edit_url(voucher, request),
|
||||
"products": [],
|
||||
"product": item.product.full_name,
|
||||
"quantity": item.quantity,
|
||||
|
||||
@ -113,7 +113,6 @@ def build_report(account_id, start_date, finish_date, db):
|
||||
"id": voucher.id,
|
||||
"date": voucher.date.strftime("%d-%b-%Y"),
|
||||
"name": name,
|
||||
"url": "", # get_edit_url(voucher, request),
|
||||
"type": VoucherType.by_id(voucher.type).name,
|
||||
"narration": voucher.narration,
|
||||
"debit": debit,
|
||||
|
||||
@ -57,8 +57,8 @@ def build_report(db: Session):
|
||||
|
||||
body.append(
|
||||
{
|
||||
"id": voucher.id,
|
||||
"date": voucher.date.strftime("%d-%b-%Y"),
|
||||
"Url": "", # get_edit_url(voucher, request),
|
||||
"voucherType": VoucherType.by_id(voucher.type).name,
|
||||
"narration": voucher.narration,
|
||||
"isPosted": voucher.posted,
|
||||
|
||||
@ -13,6 +13,7 @@ def to_camel(string: str) -> str:
|
||||
|
||||
class AccountLink(BaseModel):
|
||||
id_: uuid.UUID = Field(...)
|
||||
name: Optional[str]
|
||||
|
||||
class Config:
|
||||
fields = {'id_': 'id'}
|
||||
|
||||
162
brewman/schemas/reports.py
Normal file
162
brewman/schemas/reports.py
Normal file
@ -0,0 +1,162 @@
|
||||
import uuid
|
||||
from decimal import Decimal
|
||||
from typing import List, Optional
|
||||
from datetime import datetime, date
|
||||
from pydantic import BaseModel, Field, validator
|
||||
|
||||
from brewman.schemas.master import AccountLink
|
||||
|
||||
|
||||
def to_camel(string: str) -> str:
|
||||
first, *others = string.split("_")
|
||||
return "".join([first] + [word.capitalize() for word in others])
|
||||
|
||||
|
||||
class LedgerItem(BaseModel):
|
||||
id_: Optional[uuid.UUID]
|
||||
date_: date
|
||||
name: str
|
||||
url: str
|
||||
type_: str
|
||||
narration: str
|
||||
debit: Decimal = Field(multiple_of=0.01)
|
||||
credit: Decimal = Field(multiple_of=0.01)
|
||||
posted: bool
|
||||
|
||||
@validator("date_", pre=True)
|
||||
def parse_date(cls, value):
|
||||
return datetime.strptime(
|
||||
value,
|
||||
"%d-%b-%Y"
|
||||
).date()
|
||||
|
||||
class Config:
|
||||
anystr_strip_whitespace = True
|
||||
alias_generator = to_camel
|
||||
|
||||
|
||||
class Ledger(BaseModel):
|
||||
start_date: date
|
||||
finish_date: date
|
||||
account: Optional[AccountLink]
|
||||
body: List[LedgerItem]
|
||||
|
||||
class Config:
|
||||
anystr_strip_whitespace = True
|
||||
alias_generator = to_camel
|
||||
json_encoders = {
|
||||
date: lambda v: v.strftime("%d-%b-%Y")
|
||||
}
|
||||
|
||||
@validator("start_date", pre=True)
|
||||
def parse_start_date(cls, value):
|
||||
return datetime.strptime(
|
||||
value,
|
||||
"%d-%b-%Y"
|
||||
).date()
|
||||
|
||||
@validator("finish_date", pre=True)
|
||||
def parse_finish_date(cls, value):
|
||||
return datetime.strptime(
|
||||
value,
|
||||
"%d-%b-%Y"
|
||||
).date()
|
||||
|
||||
|
||||
class ClientIn(BaseModel):
|
||||
name: str
|
||||
enabled: bool
|
||||
otp: Optional[int]
|
||||
|
||||
|
||||
class Client(ClientIn):
|
||||
id_: uuid.UUID
|
||||
code: int
|
||||
creation_date: datetime
|
||||
|
||||
|
||||
class LoginHistory(BaseModel):
|
||||
id_: uuid.UUID
|
||||
user_id: uuid.UUID
|
||||
client_id: uuid.UUID
|
||||
date: datetime
|
||||
|
||||
class Config:
|
||||
fields = {"id_": "id"}
|
||||
anystr_strip_whitespace = True
|
||||
alias_generator = to_camel
|
||||
|
||||
|
||||
class PermissionItem(BaseModel):
|
||||
id_: uuid.UUID
|
||||
name: str
|
||||
enabled: bool
|
||||
|
||||
class Config:
|
||||
fields = {"id_": "id"}
|
||||
|
||||
|
||||
class RoleIn(BaseModel):
|
||||
name: str
|
||||
permissions: List[PermissionItem]
|
||||
|
||||
class Config:
|
||||
fields = {"id_": "id"}
|
||||
anystr_strip_whitespace = True
|
||||
|
||||
|
||||
class Role(RoleIn):
|
||||
id_: uuid.UUID
|
||||
|
||||
|
||||
class RoleList(BaseModel):
|
||||
id_: uuid.UUID
|
||||
name: str
|
||||
permissions: List[str]
|
||||
|
||||
class Config:
|
||||
fields = {"id_": "id"}
|
||||
anystr_strip_whitespace = True
|
||||
|
||||
|
||||
class RoleItem(BaseModel):
|
||||
id_: uuid.UUID
|
||||
name: str
|
||||
enabled: bool
|
||||
|
||||
class Config:
|
||||
fields = {"id_": "id"}
|
||||
|
||||
|
||||
class UserIn(BaseModel):
|
||||
name: str
|
||||
password: str
|
||||
locked_out: bool
|
||||
roles: List[RoleItem]
|
||||
|
||||
class Config:
|
||||
fields = {"id_": "id"}
|
||||
anystr_strip_whitespace = True
|
||||
alias_generator = to_camel
|
||||
|
||||
|
||||
class User(UserIn):
|
||||
id_: uuid.UUID
|
||||
|
||||
|
||||
class UserList(BaseModel):
|
||||
id_: uuid.UUID
|
||||
name: str
|
||||
roles: List[str]
|
||||
|
||||
class Config:
|
||||
fields = {"id_": "id"}
|
||||
anystr_strip_whitespace = True
|
||||
|
||||
|
||||
class UserToken(BaseModel):
|
||||
id_: uuid.UUID
|
||||
name: str
|
||||
locked_out: bool = None
|
||||
password: str
|
||||
permissions: List[str]
|
||||
Reference in New Issue
Block a user