From de4d248de7b587080c94c2f391f9cd9d6aa4e3f8 Mon Sep 17 00:00:00 2001 From: tanshu Date: Tue, 12 May 2020 11:53:20 +0530 Subject: [PATCH] Done: Issue Grid Batch --- brewman/main.py | 12 +++- .../{Management => management}/__init__.py | 0 .../db_integrity.py | 0 .../{Management => management}/rebase.py | 0 .../{Management => management}/settings.py | 0 .../{Management => management}/stock.py | 0 brewman/routers/reports/balance_sheet.py | 8 +-- brewman/routers/services/__init__.py | 0 brewman/routers/services/batch.py | 46 ---------------- .../{services => }/voucher/__init__.py | 0 brewman/routers/voucher/batch.py | 55 +++++++++++++++++++ .../{services => }/voucher/credit_salary.py | 0 .../{services => }/voucher/emptyvoucher.py | 0 .../routers/{services => }/voucher/issue.py | 0 .../cost_centre.py => voucher/issue_grid.py} | 38 ++++++++++--- .../routers/{services => }/voucher/journal.py | 0 .../{services => }/voucher/purchase.py | 0 .../{services => }/voucher/purchase_return.py | 0 .../voucher/salary_deduction.py | 0 .../{services => }/voucher/savevoucher.py | 0 .../{services => }/voucher/service_charge.py | 0 .../{services => }/voucher/updatevoucher.py | 0 overlord/src/app/core/batch.service.ts | 2 +- 23 files changed, 100 insertions(+), 61 deletions(-) rename brewman/routers/{Management => management}/__init__.py (100%) rename brewman/routers/{Management => management}/db_integrity.py (100%) rename brewman/routers/{Management => management}/rebase.py (100%) rename brewman/routers/{Management => management}/settings.py (100%) rename brewman/routers/{Management => management}/stock.py (100%) delete mode 100644 brewman/routers/services/__init__.py delete mode 100644 brewman/routers/services/batch.py rename brewman/routers/{services => }/voucher/__init__.py (100%) create mode 100644 brewman/routers/voucher/batch.py rename brewman/routers/{services => }/voucher/credit_salary.py (100%) rename brewman/routers/{services => }/voucher/emptyvoucher.py (100%) rename brewman/routers/{services => }/voucher/issue.py (100%) rename brewman/routers/{services/cost_centre.py => voucher/issue_grid.py} (55%) rename brewman/routers/{services => }/voucher/journal.py (100%) rename brewman/routers/{services => }/voucher/purchase.py (100%) rename brewman/routers/{services => }/voucher/purchase_return.py (100%) rename brewman/routers/{services => }/voucher/salary_deduction.py (100%) rename brewman/routers/{services => }/voucher/savevoucher.py (100%) rename brewman/routers/{services => }/voucher/service_charge.py (100%) rename brewman/routers/{services => }/voucher/updatevoucher.py (100%) diff --git a/brewman/main.py b/brewman/main.py index 89d35653..83dddd00 100644 --- a/brewman/main.py +++ b/brewman/main.py @@ -35,8 +35,13 @@ from .routers.reports import ( trial_balance, unposted, ) + +from .routers.voucher import ( + issue_grid, + batch, +) from .db.base_class import Base -from .config import Settings as settings +from .config import Settings from .db.session import engine Base.metadata.create_all(bind=engine) @@ -93,6 +98,9 @@ app.include_router(stock_movement.router, prefix="/api/stock-movement", tags=["r app.include_router(trial_balance.router, prefix="/api/trial-balance", tags=["reports"]) app.include_router(unposted.router, prefix="/api/unposted", tags=["reports"]) +app.include_router(issue_grid.router, prefix="/api/issue-grid", tags=["vouchers"]) +app.include_router(batch.router, prefix="/api/batch", tags=["vouchers"]) + def init(): - uvicorn.run(app, host=settings.host, port=settings.port) + uvicorn.run(app, host=Settings.host, port=Settings.port) diff --git a/brewman/routers/Management/__init__.py b/brewman/routers/management/__init__.py similarity index 100% rename from brewman/routers/Management/__init__.py rename to brewman/routers/management/__init__.py diff --git a/brewman/routers/Management/db_integrity.py b/brewman/routers/management/db_integrity.py similarity index 100% rename from brewman/routers/Management/db_integrity.py rename to brewman/routers/management/db_integrity.py diff --git a/brewman/routers/Management/rebase.py b/brewman/routers/management/rebase.py similarity index 100% rename from brewman/routers/Management/rebase.py rename to brewman/routers/management/rebase.py diff --git a/brewman/routers/Management/settings.py b/brewman/routers/management/settings.py similarity index 100% rename from brewman/routers/Management/settings.py rename to brewman/routers/management/settings.py diff --git a/brewman/routers/Management/stock.py b/brewman/routers/management/stock.py similarity index 100% rename from brewman/routers/Management/stock.py rename to brewman/routers/management/stock.py diff --git a/brewman/routers/reports/balance_sheet.py b/brewman/routers/reports/balance_sheet.py index 1f66aa71..db5e34bf 100644 --- a/brewman/routers/reports/balance_sheet.py +++ b/brewman/routers/reports/balance_sheet.py @@ -39,10 +39,10 @@ def report_blank( @router.get("/{date}") def report_data( - date: str, - request: Request, - db: Session = Depends(get_db), - user: UserToken = Security(get_user, scopes=["balance-sheet"]), + date: str, + request: Request, + db: Session = Depends(get_db), + user: UserToken = Security(get_user, scopes=["balance-sheet"]), ): body, footer = build_balance_sheet(date, db) set_period(get_start_date(request.session), date, request.session) diff --git a/brewman/routers/services/__init__.py b/brewman/routers/services/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/brewman/routers/services/batch.py b/brewman/routers/services/batch.py deleted file mode 100644 index 89ac26b0..00000000 --- a/brewman/routers/services/batch.py +++ /dev/null @@ -1,46 +0,0 @@ -import datetime - -from brewman.models.voucher import Batch - - -@router.get("/api/batch") # "Authenticated" -def batch_term(request): - filter_ = request.GET.get("t", None) - filter_ = filter_ if filter_ is not None and filter_.strip() is not "" else None - count = request.GET.get("c", None) - count = None if count is None or count == "" else int(count) - date = request.GET.get("d", None) - date = ( - None - if date is None or date == "" - else datetime.datetime.strptime(date, "%d-%b-%Y") - ) - list_ = [] - for index, item in enumerate( - Batch.list(filter_, include_nil=False, date=date, dbsession=request.dbsession) - ): - text = "{0} ({1}) {2:.2f}@{3:.2f} from {4}".format( - item.product.name, - item.product.units, - item.quantity_remaining, - item.rate, - item.name.strftime("%d-%b-%Y"), - ) - list_.append( - { - "id": item.id, - "name": text, - "quantityRemaining": item.quantity_remaining, - "rate": item.rate, - "tax": item.tax, - "discount": item.discount, - "product": { - "id": item.product.id, - "name": item.product.name, - "units": item.product.units, - }, - } - ) - if count is not None and index == count - 1: - break - return list_ diff --git a/brewman/routers/services/voucher/__init__.py b/brewman/routers/voucher/__init__.py similarity index 100% rename from brewman/routers/services/voucher/__init__.py rename to brewman/routers/voucher/__init__.py diff --git a/brewman/routers/voucher/batch.py b/brewman/routers/voucher/batch.py new file mode 100644 index 00000000..141d0d39 --- /dev/null +++ b/brewman/routers/voucher/batch.py @@ -0,0 +1,55 @@ +import datetime + +from fastapi import APIRouter, Depends +from sqlalchemy.orm import Session + +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 Batch + +router = APIRouter() + + +# Dependency +def get_db() -> Session: + try: + db = SessionLocal() + yield db + finally: + db.close() + + +@router.get("") +def batch_term( + q: str, + c: int = None, + d: str = None, + db: Session = Depends(get_db), + current_user: UserToken = Depends(get_user), +): + filter_ = q if q is not None and q.strip() is not "" else None + date = None if not d else datetime.datetime.strptime(d, "%d-%b-%Y") + list_ = [] + for index, item in enumerate( + Batch.list(filter_, include_nil=False, date=date, dbsession=db) + ): + text = f"{item.product.name} ({item.product.units}) {item.quantity_remaining:.2f}@{item.rate:.2f} from {item.name.strftime('%d-%b-%Y')}" + list_.append( + { + "id": item.id, + "name": text, + "quantityRemaining": item.quantity_remaining, + "rate": item.rate, + "tax": item.tax, + "discount": item.discount, + "product": { + "id": item.product.id, + "name": item.product.name, + "units": item.product.units, + }, + } + ) + if c is not None and index == c - 1: + break + return list_ diff --git a/brewman/routers/services/voucher/credit_salary.py b/brewman/routers/voucher/credit_salary.py similarity index 100% rename from brewman/routers/services/voucher/credit_salary.py rename to brewman/routers/voucher/credit_salary.py diff --git a/brewman/routers/services/voucher/emptyvoucher.py b/brewman/routers/voucher/emptyvoucher.py similarity index 100% rename from brewman/routers/services/voucher/emptyvoucher.py rename to brewman/routers/voucher/emptyvoucher.py diff --git a/brewman/routers/services/voucher/issue.py b/brewman/routers/voucher/issue.py similarity index 100% rename from brewman/routers/services/voucher/issue.py rename to brewman/routers/voucher/issue.py diff --git a/brewman/routers/services/cost_centre.py b/brewman/routers/voucher/issue_grid.py similarity index 55% rename from brewman/routers/services/cost_centre.py rename to brewman/routers/voucher/issue_grid.py index 9815e2e9..4edd42db 100644 --- a/brewman/routers/services/cost_centre.py +++ b/brewman/routers/voucher/issue_grid.py @@ -1,23 +1,45 @@ -import datetime +from datetime import datetime + +from fastapi import APIRouter, Depends, Security, Request +from sqlalchemy.orm import Session from sqlalchemy.orm.util import aliased +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 - -@router.get("/api/issue-grid/{date}") # "Issue" -def grid_date(request): - date = datetime.datetime.strptime(request.matchdict["date"], "%d-%b-%Y") - return get_grid(date, request.dbsession) +router = APIRouter() -def get_grid(date, dbsession): +# Dependency +def get_db() -> Session: + try: + db = SessionLocal() + yield db + finally: + db.close() + + +@router.get("/{date}") +def grid_date( + date: str, + request: Request, + db: Session = Depends(get_db), + user: UserToken = Security(get_user, scopes=["issue"]), +): + date = datetime.strptime(date, "%d-%b-%Y") + return get_grid(date, db) + + +def get_grid(date, db): list_ = [] source_journal = aliased(Journal) destination_journal = aliased(Journal) query = ( - dbsession.query(Voucher, source_journal.amount) + db.query(Voucher, source_journal.amount) .join(source_journal, Voucher.journals) .join(destination_journal, Voucher.journals) .filter(Voucher.date == date) diff --git a/brewman/routers/services/voucher/journal.py b/brewman/routers/voucher/journal.py similarity index 100% rename from brewman/routers/services/voucher/journal.py rename to brewman/routers/voucher/journal.py diff --git a/brewman/routers/services/voucher/purchase.py b/brewman/routers/voucher/purchase.py similarity index 100% rename from brewman/routers/services/voucher/purchase.py rename to brewman/routers/voucher/purchase.py diff --git a/brewman/routers/services/voucher/purchase_return.py b/brewman/routers/voucher/purchase_return.py similarity index 100% rename from brewman/routers/services/voucher/purchase_return.py rename to brewman/routers/voucher/purchase_return.py diff --git a/brewman/routers/services/voucher/salary_deduction.py b/brewman/routers/voucher/salary_deduction.py similarity index 100% rename from brewman/routers/services/voucher/salary_deduction.py rename to brewman/routers/voucher/salary_deduction.py diff --git a/brewman/routers/services/voucher/savevoucher.py b/brewman/routers/voucher/savevoucher.py similarity index 100% rename from brewman/routers/services/voucher/savevoucher.py rename to brewman/routers/voucher/savevoucher.py diff --git a/brewman/routers/services/voucher/service_charge.py b/brewman/routers/voucher/service_charge.py similarity index 100% rename from brewman/routers/services/voucher/service_charge.py rename to brewman/routers/voucher/service_charge.py diff --git a/brewman/routers/services/voucher/updatevoucher.py b/brewman/routers/voucher/updatevoucher.py similarity index 100% rename from brewman/routers/services/voucher/updatevoucher.py rename to brewman/routers/voucher/updatevoucher.py diff --git a/overlord/src/app/core/batch.service.ts b/overlord/src/app/core/batch.service.ts index dda407f7..eddca03f 100644 --- a/overlord/src/app/core/batch.service.ts +++ b/overlord/src/app/core/batch.service.ts @@ -15,7 +15,7 @@ export class BatchService { } autocomplete(date: string, term: string): Observable { - const options = {params: new HttpParams().set('t', term).set('d', date)}; + const options = {params: new HttpParams().set('q', term).set('d', date)}; return >this.http.get(url, options) .pipe( catchError(this.log.handleError(serviceName, 'autocomplete'))