Daybook done!!
This commit is contained in:
parent
01cf6c2da1
commit
5f783e1f45
@ -7,6 +7,7 @@ from ...schemas.auth import UserToken
|
|||||||
from ...core.security import get_current_active_user as get_user
|
from ...core.security import get_current_active_user as get_user
|
||||||
from ...db.session import SessionLocal
|
from ...db.session import SessionLocal
|
||||||
from brewman.models.voucher import Voucher, Journal, VoucherType
|
from brewman.models.voucher import Voucher, Journal, VoucherType
|
||||||
|
import brewman.schemas.reports as schemas
|
||||||
from ...core.session import (
|
from ...core.session import (
|
||||||
set_period,
|
set_period,
|
||||||
get_start_date,
|
get_start_date,
|
||||||
@ -25,7 +26,7 @@ def get_db() -> Session:
|
|||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
|
|
||||||
@router.get("")
|
@router.get("", response_model=schemas.Daybook)
|
||||||
def report_blank(
|
def report_blank(
|
||||||
request: Request,
|
request: Request,
|
||||||
user: UserToken = Security(get_user, scopes=["daybook"]),
|
user: UserToken = Security(get_user, scopes=["daybook"]),
|
||||||
@ -37,7 +38,7 @@ def report_blank(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@router.get("/{start}/{finish}")
|
@router.get("/{start}/{finish}", response_model=schemas.Daybook)
|
||||||
def report_data(
|
def report_data(
|
||||||
start: str,
|
start: str,
|
||||||
finish: str,
|
finish: str,
|
||||||
@ -83,6 +84,7 @@ def build_report(start_date, finish_date, db):
|
|||||||
{
|
{
|
||||||
"id": voucher.id,
|
"id": voucher.id,
|
||||||
"date": voucher.date.strftime("%d-%b-%Y"),
|
"date": voucher.date.strftime("%d-%b-%Y"),
|
||||||
|
"url": ['/', VoucherType.by_id(voucher.type).name.replace(" ", "-").lower(), str(voucher.id)],
|
||||||
"type": VoucherType.by_id(voucher.type).name,
|
"type": VoucherType.by_id(voucher.type).name,
|
||||||
"narration": voucher.narration,
|
"narration": voucher.narration,
|
||||||
"posted": voucher.posted,
|
"posted": voucher.posted,
|
||||||
|
@ -177,3 +177,55 @@ class ClosingStock(BaseModel):
|
|||||||
).date()
|
).date()
|
||||||
|
|
||||||
|
|
||||||
|
class DaybookItem(BaseModel):
|
||||||
|
id_: Optional[uuid.UUID]
|
||||||
|
date_: date
|
||||||
|
url: List[str]
|
||||||
|
type_: str
|
||||||
|
narration: str
|
||||||
|
debit_text: Optional[str]
|
||||||
|
debit: Optional[Decimal] = Field(multiple_of=0.01)
|
||||||
|
credit_text: Optional[str]
|
||||||
|
credit: Optional[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
|
||||||
|
json_encoders = {
|
||||||
|
date: lambda v: v.strftime("%d-%b-%Y")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class Daybook(BaseModel):
|
||||||
|
start_date: date
|
||||||
|
finish_date: date
|
||||||
|
body: List[DaybookItem]
|
||||||
|
|
||||||
|
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()
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
<!-- Date Column -->
|
<!-- Date Column -->
|
||||||
<ng-container matColumnDef="date">
|
<ng-container matColumnDef="date">
|
||||||
<mat-header-cell *matHeaderCellDef mat-sort-header>Date</mat-header-cell>
|
<mat-header-cell *matHeaderCellDef mat-sort-header>Date</mat-header-cell>
|
||||||
<mat-cell *matCellDef="let row"><a [routerLink]="['/', row.url, row.id]">{{row.date}}</a></mat-cell>
|
<mat-cell *matCellDef="let row"><a [routerLink]="row.url">{{row.date}}</a></mat-cell>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
|
|
||||||
<!-- Type Column -->
|
<!-- Type Column -->
|
||||||
|
@ -34,12 +34,7 @@ export class DaybookComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.route.data.pipe(map(
|
this.route.data.subscribe((data: { info: Daybook }) => {
|
||||||
(data: { info: Daybook }) => {
|
|
||||||
data.info.body = data.info.body.map(x => ({...x, url: x['type'].replace(/ /g, '-').toLowerCase()}));
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
)).subscribe((data: { info: Daybook }) => {
|
|
||||||
this.info = data.info;
|
this.info = data.info;
|
||||||
this.form.setValue({
|
this.form.setValue({
|
||||||
startDate: moment(this.info.startDate, 'DD-MMM-YYYY').toDate(),
|
startDate: moment(this.info.startDate, 'DD-MMM-YYYY').toDate(),
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
export class DaybookItem {
|
export class DaybookItem {
|
||||||
|
id: string;
|
||||||
date: string;
|
date: string;
|
||||||
type: string;
|
type: string;
|
||||||
narration: string;
|
narration: string;
|
||||||
@ -8,7 +9,7 @@ export class DaybookItem {
|
|||||||
creditText: string;
|
creditText: string;
|
||||||
creditAmount: number;
|
creditAmount: number;
|
||||||
posted: boolean;
|
posted: boolean;
|
||||||
url: string;
|
url: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Daybook {
|
export class Daybook {
|
||||||
|
Loading…
Reference in New Issue
Block a user