diff --git a/brewman/routers/reports/daybook.py b/brewman/routers/reports/daybook.py index f484e041..1f252001 100644 --- a/brewman/routers/reports/daybook.py +++ b/brewman/routers/reports/daybook.py @@ -7,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 from ...core.session import ( set_period, get_start_date, @@ -25,7 +26,7 @@ def get_db() -> Session: db.close() -@router.get("") +@router.get("", response_model=schemas.Daybook) def report_blank( request: Request, 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( start: str, finish: str, @@ -83,6 +84,7 @@ def build_report(start_date, finish_date, db): { "id": voucher.id, "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, "narration": voucher.narration, "posted": voucher.posted, diff --git a/brewman/schemas/reports.py b/brewman/schemas/reports.py index c1b121da..9fb02e8e 100644 --- a/brewman/schemas/reports.py +++ b/brewman/schemas/reports.py @@ -177,3 +177,55 @@ class ClosingStock(BaseModel): ).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() diff --git a/overlord/src/app/daybook/daybook.component.html b/overlord/src/app/daybook/daybook.component.html index a730e32e..c5ff9d2f 100644 --- a/overlord/src/app/daybook/daybook.component.html +++ b/overlord/src/app/daybook/daybook.component.html @@ -26,7 +26,7 @@ Date - {{row.date}} + {{row.date}} diff --git a/overlord/src/app/daybook/daybook.component.ts b/overlord/src/app/daybook/daybook.component.ts index 5ddd65bf..63e8ab43 100644 --- a/overlord/src/app/daybook/daybook.component.ts +++ b/overlord/src/app/daybook/daybook.component.ts @@ -34,12 +34,7 @@ export class DaybookComponent implements OnInit { } ngOnInit() { - this.route.data.pipe(map( - (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.route.data.subscribe((data: { info: Daybook }) => { this.info = data.info; this.form.setValue({ startDate: moment(this.info.startDate, 'DD-MMM-YYYY').toDate(), diff --git a/overlord/src/app/daybook/daybook.ts b/overlord/src/app/daybook/daybook.ts index 0d203817..246b570d 100644 --- a/overlord/src/app/daybook/daybook.ts +++ b/overlord/src/app/daybook/daybook.ts @@ -1,5 +1,6 @@ export class DaybookItem { + id: string; date: string; type: string; narration: string; @@ -8,7 +9,7 @@ export class DaybookItem { creditText: string; creditAmount: number; posted: boolean; - url: string; + url: string[]; } export class Daybook {