Nothing much
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
[flake8]
|
[flake8]
|
||||||
ignore = E203
|
ignore = E203, W503
|
||||||
max-line-length = 120
|
max-line-length = 120
|
||||||
exclude = .git,__pycache__,__init__.py,.mypy_cache,.pytest_cache
|
exclude = .git,__pycache__,__init__.py,.mypy_cache,.pytest_cache
|
||||||
|
|||||||
@ -171,7 +171,7 @@ def balance(id_: uuid.UUID, date, db: Session) -> Decimal:
|
|||||||
bal = bal.where(Voucher.date <= date)
|
bal = bal.where(Voucher.date <= date)
|
||||||
|
|
||||||
bal = bal.where(Voucher.voucher_type != VoucherType.ISSUE).where(Journal.account_id == id_)
|
bal = bal.where(Voucher.voucher_type != VoucherType.ISSUE).where(Journal.account_id == id_)
|
||||||
result: Decimal = db.execute(bal).scalar()
|
result: Decimal = db.execute(bal).scalar_one_or_none()
|
||||||
return Decimal(0) if result is None else result
|
return Decimal(0) if result is None else result
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
from datetime import datetime
|
from datetime import date, datetime
|
||||||
|
from typing import List
|
||||||
|
|
||||||
from fastapi import APIRouter, Security
|
from fastapi import APIRouter, Security
|
||||||
from sqlalchemy import select
|
from sqlalchemy import select
|
||||||
@ -8,29 +9,30 @@ from ..core.security import get_current_active_user as get_user
|
|||||||
from ..db.session import SessionFuture
|
from ..db.session import SessionFuture
|
||||||
from ..models.voucher import Voucher
|
from ..models.voucher import Voucher
|
||||||
from ..models.voucher_type import VoucherType
|
from ..models.voucher_type import VoucherType
|
||||||
|
from ..schemas.issue_grid_item import IssueGridItem
|
||||||
from ..schemas.user import UserToken
|
from ..schemas.user import UserToken
|
||||||
|
|
||||||
|
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
||||||
|
|
||||||
@router.get("/{date}")
|
@router.get("/{date_}", response_model=List[IssueGridItem])
|
||||||
def grid_date(
|
def grid_date(
|
||||||
date: str,
|
date_: str,
|
||||||
user: UserToken = Security(get_user, scopes=["issue"]),
|
user: UserToken = Security(get_user, scopes=["issue"]),
|
||||||
):
|
) -> List[IssueGridItem]:
|
||||||
date = datetime.strptime(date, "%d-%b-%Y")
|
date_obj = datetime.strptime(date_, "%d-%b-%Y")
|
||||||
with SessionFuture() as db:
|
with SessionFuture() as db:
|
||||||
return get_grid(date, db)
|
return get_grid(date_obj, db)
|
||||||
|
|
||||||
|
|
||||||
def get_grid(date, db: Session):
|
def get_grid(date_: date, db: Session) -> List[IssueGridItem]:
|
||||||
list_ = []
|
list_: List[IssueGridItem] = []
|
||||||
query = (
|
query = (
|
||||||
db.execute(
|
db.execute(
|
||||||
select(Voucher)
|
select(Voucher)
|
||||||
.join(Voucher.journals)
|
.join(Voucher.journals)
|
||||||
.where(Voucher.date == date, Voucher.voucher_type == VoucherType.ISSUE)
|
.where(Voucher.date == date_, Voucher.voucher_type == VoucherType.ISSUE)
|
||||||
.order_by(Voucher.creation_date)
|
.order_by(Voucher.creation_date)
|
||||||
)
|
)
|
||||||
.unique()
|
.unique()
|
||||||
@ -41,11 +43,11 @@ def get_grid(date, db: Session):
|
|||||||
for voucher in query:
|
for voucher in query:
|
||||||
amount = voucher.journals[0].amount
|
amount = voucher.journals[0].amount
|
||||||
list_.append(
|
list_.append(
|
||||||
{
|
IssueGridItem(
|
||||||
"id": str(voucher.id),
|
id=str(voucher.id),
|
||||||
"amount": amount,
|
amount=amount,
|
||||||
"source": [j.cost_centre.name for j in voucher.journals if j.debit == -1],
|
source=next(j.cost_centre.name for j in voucher.journals if j.debit == -1),
|
||||||
"destination": [j.cost_centre.name for j in voucher.journals if j.debit == 1],
|
destination=next(j.cost_centre.name for j in voucher.journals if j.debit == 1),
|
||||||
}
|
)
|
||||||
)
|
)
|
||||||
return list_
|
return list_
|
||||||
|
|||||||
15
brewman/brewman/schemas/issue_grid_item.py
Normal file
15
brewman/brewman/schemas/issue_grid_item.py
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import uuid
|
||||||
|
|
||||||
|
from decimal import Decimal
|
||||||
|
|
||||||
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
|
||||||
|
class IssueGridItem(BaseModel):
|
||||||
|
id_: uuid.UUID
|
||||||
|
amount: Decimal
|
||||||
|
source: str
|
||||||
|
destination: str
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
fields = {"id_": "id"}
|
||||||
Reference in New Issue
Block a user