Dates and times should now be handled properly once the server is set on UTC time and the proper timezone offset environment variable is set.

This commit is contained in:
Amritanshu Agrawal 2021-04-02 06:58:38 +05:30
parent 0da16e9548
commit 97579ea9d3
13 changed files with 104 additions and 78 deletions

View File

@ -94,8 +94,11 @@ def design_bill(
s += "\n\r" s += "\n\r"
# Products # Products
date = voucher.date + timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES) product_date = (
s += "\n\r" + f"Bill No: {voucher.full_bill_id:>12} {date:%d-%b-%Y %H:%M}" voucher.date + timedelta(minutes=settings.TIMEZONE_OFFSET_MINUTES - settings.NEW_DAY_OFFSET_MINUTES)
).date()
voucher_date = voucher.date + timedelta(minutes=settings.TIMEZONE_OFFSET_MINUTES)
s += "\n\r" + f"Bill No: {voucher.full_bill_id:>12} {voucher_date:%d-%b-%Y %H:%M}"
s += "\n\r" + "Table No.: " + voucher.food_table.name s += "\n\r" + "Table No.: " + voucher.food_table.name
s += "\n\r" + "-" * 42 s += "\n\r" + "-" * 42
s += "\n\r" + "Qty. Particulars Price Amount" s += "\n\r" + "Qty. Particulars Price Amount"
@ -108,13 +111,11 @@ def design_bill(
ProductVersion.product_id == item.product_id, ProductVersion.product_id == item.product_id,
or_( or_(
ProductVersion.valid_from == None, # noqa: E711 ProductVersion.valid_from == None, # noqa: E711
ProductVersion.valid_from ProductVersion.valid_from <= product_date,
<= (voucher.date - timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES)).date(),
), ),
or_( or_(
ProductVersion.valid_till == None, # noqa: E711 ProductVersion.valid_till == None, # noqa: E711
ProductVersion.valid_till ProductVersion.valid_till >= product_date,
>= (voucher.date - timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES)).date(),
), ),
) )
) )

View File

@ -2,13 +2,14 @@ import asyncio
import locale import locale
import uuid import uuid
from datetime import datetime from datetime import datetime, timedelta
from arq import ArqRedis, create_pool from arq import ArqRedis, create_pool
from barker.schemas.cashier_report import CashierReport from barker.schemas.cashier_report import CashierReport
from sqlalchemy.orm import Session from sqlalchemy.orm import Session
from ..core.arq import settings as redis_settings from ..core.arq import settings as redis_settings
from ..core.config import settings
from ..models.device import Device from ..models.device import Device
from ..models.printer import Printer from ..models.printer import Printer
from ..models.section_printer import SectionPrinter from ..models.section_printer import SectionPrinter
@ -36,7 +37,8 @@ def print_cashier_report(report: CashierReport, device_id: uuid.UUID, db: Sessio
def design_cashier_report(report: CashierReport): def design_cashier_report(report: CashierReport):
s = f"{report.cashier.name} Checkout By {report.user.name} @ {datetime.now():%d-%b-%Y %H:%M}".center(42) now = datetime.now() + timedelta(minutes=settings.TIMEZONE_OFFSET_MINUTES)
s = f"{report.cashier.name} Checkout By {report.user.name} @ {now:%d-%b-%Y %H:%M}".center(42)
s += "\n\r" + "-" * 42 s += "\n\r" + "-" * 42
s += "\n\r" f"{report.start_date:%d-%b-%Y} To {report.finish_date:%d-%b-%Y}".center(42) s += "\n\r" f"{report.start_date:%d-%b-%Y} To {report.finish_date:%d-%b-%Y}".center(42)
s += "\n\r" + "-" * 42 s += "\n\r" + "-" * 42

View File

@ -19,7 +19,10 @@ from ..models.voucher import Voucher
def design_kot(voucher: Voucher, kot: Kot, items: List[Inventory], copy_number: int, db: Session) -> str: def design_kot(voucher: Voucher, kot: Kot, items: List[Inventory], copy_number: int, db: Session) -> str:
date = voucher.date + timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES) date_ = voucher.date + timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES)
product_date = (
voucher.date + timedelta(minutes=settings.TIMEZONE_OFFSET_MINUTES - settings.NEW_DAY_OFFSET_MINUTES)
).date()
s = ( s = (
"KOT / BOT".center(42) "KOT / BOT".center(42)
+ "\n\r" + "\n\r"
@ -27,7 +30,7 @@ def design_kot(voucher: Voucher, kot: Kot, items: List[Inventory], copy_number:
+ "\n\r" + "\n\r"
+ "".ljust(42, "-") + "".ljust(42, "-")
+ "\n\r" + "\n\r"
+ f"KOT ID : K-{voucher.kot_id:>5}/S-{kot.code:>5} {date:%d-%b-%Y %H:%M}" + f"KOT ID : K-{voucher.kot_id:>5}/S-{kot.code:>5} {date_:%d-%b-%Y %H:%M}"
+ "\n\r" + "\n\r"
+ f"Table No.: {voucher.food_table.name}" + f"Table No.: {voucher.food_table.name}"
+ "\n\r" + "\n\r"
@ -45,13 +48,11 @@ def design_kot(voucher: Voucher, kot: Kot, items: List[Inventory], copy_number:
ProductVersion.product_id == item.product_id, ProductVersion.product_id == item.product_id,
or_( or_(
ProductVersion.valid_from == None, # noqa: E711 ProductVersion.valid_from == None, # noqa: E711
ProductVersion.valid_from ProductVersion.valid_from <= product_date,
<= (voucher.date - timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES)).date(),
), ),
or_( or_(
ProductVersion.valid_till == None, # noqa: E711 ProductVersion.valid_till == None, # noqa: E711
ProductVersion.valid_till ProductVersion.valid_till >= product_date,
>= (voucher.date - timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES)).date(),
), ),
) )
) )
@ -69,6 +70,9 @@ def print_kot(voucher_id: uuid.UUID, db: Session):
voucher: Voucher = db.query(Voucher).filter(Voucher.id == voucher_id).first() voucher: Voucher = db.query(Voucher).filter(Voucher.id == voucher_id).first()
my_hash = {} my_hash = {}
kot: Kot = voucher.kots[-1] kot: Kot = voucher.kots[-1]
product_date = (
voucher.date + timedelta(minutes=settings.TIMEZONE_OFFSET_MINUTES - settings.NEW_DAY_OFFSET_MINUTES)
).date()
for item in kot.inventories: for item in kot.inventories:
product: ProductVersion = ( product: ProductVersion = (
db.query(ProductVersion) db.query(ProductVersion)
@ -77,13 +81,11 @@ def print_kot(voucher_id: uuid.UUID, db: Session):
ProductVersion.product_id == item.product_id, ProductVersion.product_id == item.product_id,
or_( or_(
ProductVersion.valid_from == None, # noqa: E711 ProductVersion.valid_from == None, # noqa: E711
ProductVersion.valid_from ProductVersion.valid_from <= product_date,
<= (voucher.date - timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES)).date(),
), ),
or_( or_(
ProductVersion.valid_till == None, # noqa: E711 ProductVersion.valid_till == None, # noqa: E711
ProductVersion.valid_till ProductVersion.valid_till >= product_date,
>= (voucher.date - timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES)).date(),
), ),
) )
) )

View File

@ -2,12 +2,13 @@ import asyncio
import locale import locale
import uuid import uuid
from datetime import datetime from datetime import datetime, timedelta
from arq import ArqRedis, create_pool from arq import ArqRedis, create_pool
from sqlalchemy.orm import Session from sqlalchemy.orm import Session
from ..core.arq import settings as redis_settings from ..core.arq import settings as redis_settings
from ..core.config import settings
from ..models.device import Device from ..models.device import Device
from ..models.printer import Printer from ..models.printer import Printer
from ..models.section_printer import SectionPrinter from ..models.section_printer import SectionPrinter
@ -36,7 +37,8 @@ def print_sale_report(report: SaleReport, device_id: uuid.UUID, db: Session):
def design_sale_report(report: SaleReport): def design_sale_report(report: SaleReport):
s = f"{report.user.name} @ {datetime.now():%d-%b-%Y %H:%M}".center(42) now = datetime.now() + timedelta(minutes=settings.TIMEZONE_OFFSET_MINUTES)
s = f"{report.user.name} @ {now:%d-%b-%Y %H:%M}".center(42)
s += "\n\r" + "-" * 42 s += "\n\r" + "-" * 42
s += "\n\r" f"{report.start_date:%d-%b-%Y} To {report.finish_date:%d-%b-%Y}".center(42) s += "\n\r" f"{report.start_date:%d-%b-%Y} To {report.finish_date:%d-%b-%Y}".center(42)
s += "\n\r" + "-" * 42 s += "\n\r" + "-" * 42

View File

@ -1,6 +1,6 @@
import uuid import uuid
from datetime import date, timedelta from datetime import date, datetime, time, timedelta
from typing import Dict, List from typing import Dict, List
from fastapi import APIRouter, Cookie, Depends, HTTPException, Security, status from fastapi import APIRouter, Cookie, Depends, HTTPException, Security, status
@ -45,8 +45,8 @@ def active_cashiers(
db: Session = Depends(get_db), db: Session = Depends(get_db),
user: UserToken = Security(get_user, scopes=["cashier-report"]), user: UserToken = Security(get_user, scopes=["cashier-report"]),
) -> List[UserLink]: ) -> List[UserLink]:
today = (datetime.now() + timedelta(minutes=settings.TIMEZONE_OFFSET_MINUTES)).date()
if (date.today() - start_date).days > 5 and "audit" not in user.permissions: if (today - start_date).days > 5 and "audit" not in user.permissions:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN, status_code=status.HTTP_403_FORBIDDEN,
detail="Accounts Audit", detail="Accounts Audit",
@ -55,13 +55,19 @@ def active_cashiers(
def get_active_cashiers(start_date: date, finish_date: date, db: Session) -> List[UserLink]: def get_active_cashiers(start_date: date, finish_date: date, db: Session) -> List[UserLink]:
start_datetime = datetime.combine(start_date, time()) + timedelta(
minutes=settings.TIMEZONE_OFFSET_MINUTES - settings.NEW_DAY_OFFSET_MINUTES
)
finish_datetime = datetime.combine(finish_date, time()) + timedelta(
days=1, minutes=settings.TIMEZONE_OFFSET_MINUTES - settings.NEW_DAY_OFFSET_MINUTES
)
users = ( users = (
db.query(User) db.query(User)
.filter( .filter(
User.id.in_( User.id.in_(
db.query(distinct(Voucher.user_id)).filter( db.query(distinct(Voucher.user_id)).filter(
Voucher.date >= start_date + timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES), Voucher.date >= start_datetime,
Voucher.date <= finish_date + timedelta(days=1, minutes=settings.NEW_DAY_OFFSET_MINUTES), Voucher.date <= finish_datetime,
) )
) )
) )
@ -79,7 +85,8 @@ def show_id(
db: Session = Depends(get_db), db: Session = Depends(get_db),
user: UserToken = Security(get_user, scopes=["cashier-report"]), user: UserToken = Security(get_user, scopes=["cashier-report"]),
) -> CashierReport: ) -> CashierReport:
if (date.today() - start_date).days > 5 and "audit" not in user.permissions: today = (datetime.now() + timedelta(minutes=settings.TIMEZONE_OFFSET_MINUTES)).date()
if (today - start_date).days > 5 and "audit" not in user.permissions:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN, status_code=status.HTTP_403_FORBIDDEN,
detail="Accounts Audit", detail="Accounts Audit",
@ -90,12 +97,18 @@ def show_id(
def get_id(id_: uuid.UUID, start_date: date, finish_date: date, user: UserLink, db: Session) -> CashierReport: def get_id(id_: uuid.UUID, start_date: date, finish_date: date, user: UserLink, db: Session) -> CashierReport:
cashier: str = db.query(User.name).filter(User.id == id_).scalar() cashier: str = db.query(User.name).filter(User.id == id_).scalar()
start_datetime = datetime.combine(start_date, time()) + timedelta(
minutes=settings.TIMEZONE_OFFSET_MINUTES - settings.NEW_DAY_OFFSET_MINUTES
)
finish_datetime = datetime.combine(finish_date, time()) + timedelta(
days=1, minutes=settings.TIMEZONE_OFFSET_MINUTES - settings.NEW_DAY_OFFSET_MINUTES
)
vouchers = ( vouchers = (
db.query(Voucher) db.query(Voucher)
.options(joinedload(Voucher.settlements, innerjoin=True).joinedload(Settlement.settle_option, innerjoin=True)) .options(joinedload(Voucher.settlements, innerjoin=True).joinedload(Settlement.settle_option, innerjoin=True))
.filter( .filter(
Voucher.date >= start_date + timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES), Voucher.date >= start_datetime,
Voucher.date <= finish_date + timedelta(days=1, minutes=settings.NEW_DAY_OFFSET_MINUTES), Voucher.date <= finish_datetime,
Voucher.user_id == id_, Voucher.user_id == id_,
) )
.order_by(Voucher.voucher_type) .order_by(Voucher.voucher_type)
@ -142,7 +155,8 @@ def print_report(
db: Session = Depends(get_db), db: Session = Depends(get_db),
user: UserToken = Security(get_user, scopes=["cashier-report"]), user: UserToken = Security(get_user, scopes=["cashier-report"]),
) -> bool: ) -> bool:
if (date.today() - start_date).days > 5 and "audit" not in user.permissions: today = (datetime.now() + timedelta(minutes=settings.TIMEZONE_OFFSET_MINUTES)).date()
if (today - start_date).days > 5 and "audit" not in user.permissions:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN, status_code=status.HTTP_403_FORBIDDEN,
detail="Accounts Audit", detail="Accounts Audit",
@ -159,7 +173,8 @@ def show_blank(
db: Session = Depends(get_db), db: Session = Depends(get_db),
user: UserToken = Security(get_user, scopes=["cashier-report"]), user: UserToken = Security(get_user, scopes=["cashier-report"]),
) -> CashierReport: ) -> CashierReport:
if (date.today() - start_date).days > 5 and "audit" not in user.permissions: today = (datetime.now() + timedelta(minutes=settings.TIMEZONE_OFFSET_MINUTES)).date()
if (today - start_date).days > 5 and "audit" not in user.permissions:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN, status_code=status.HTTP_403_FORBIDDEN,
detail="Accounts Audit", detail="Accounts Audit",

View File

@ -1,6 +1,6 @@
import uuid import uuid
from datetime import date, timedelta from datetime import date, datetime, time, timedelta
from typing import List from typing import List
from fastapi import APIRouter, Cookie, Depends, HTTPException, Security, status from fastapi import APIRouter, Cookie, Depends, HTTPException, Security, status
@ -41,7 +41,8 @@ def discount_report(
db: Session = Depends(get_db), db: Session = Depends(get_db),
user: UserToken = Security(get_user, scopes=["discount-report"]), user: UserToken = Security(get_user, scopes=["discount-report"]),
) -> DiscountReport: ) -> DiscountReport:
if (date.today() - start_date).days > 5 and "audit" not in user.permissions: today = (datetime.now() + timedelta(minutes=settings.TIMEZONE_OFFSET_MINUTES)).date()
if (today - start_date).days > 5 and "audit" not in user.permissions:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN, status_code=status.HTTP_403_FORBIDDEN,
detail="Accounts Audit", detail="Accounts Audit",
@ -54,8 +55,8 @@ def discount_report(
def get_discount_report(s: date, f: date, db: Session) -> List[DiscountReportItem]: def get_discount_report(s: date, f: date, db: Session) -> List[DiscountReportItem]:
start_date = s + timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES) start_date = datetime.combine(s, time()) + timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES)
finish_date = f + timedelta(days=1, minutes=settings.NEW_DAY_OFFSET_MINUTES) finish_date = datetime.combine(f, time()) + timedelta(days=1, minutes=settings.NEW_DAY_OFFSET_MINUTES)
day = func.date_trunc("day", Voucher.date - timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES)).label("day") day = func.date_trunc("day", Voucher.date - timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES)).label("day")
amount = func.sum(Inventory.quantity * Inventory.effective_price * Inventory.discount).label("Amount") amount = func.sum(Inventory.quantity * Inventory.effective_price * Inventory.discount).label("Amount")
@ -95,7 +96,8 @@ def print_report(
db: Session = Depends(get_db), db: Session = Depends(get_db),
user: UserToken = Security(get_user, scopes=["discount-report"]), user: UserToken = Security(get_user, scopes=["discount-report"]),
) -> bool: ) -> bool:
if (date.today() - start_date).days > 5 and "audit" not in user.permissions: today = (datetime.now() + timedelta(minutes=settings.TIMEZONE_OFFSET_MINUTES)).date()
if (today - start_date).days > 5 and "audit" not in user.permissions:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN, status_code=status.HTTP_403_FORBIDDEN,
detail="Accounts Audit", detail="Accounts Audit",

View File

@ -1,6 +1,6 @@
import uuid import uuid
from datetime import date, timedelta from datetime import date, datetime, time, timedelta
from typing import List from typing import List
from fastapi import APIRouter, Cookie, Depends, HTTPException, Security, status from fastapi import APIRouter, Cookie, Depends, HTTPException, Security, status
@ -45,7 +45,8 @@ def get_sale_analysis(
db: Session = Depends(get_db), db: Session = Depends(get_db),
user: UserToken = Security(get_user, scopes=["sale-report"]), user: UserToken = Security(get_user, scopes=["sale-report"]),
) -> SaleReport: ) -> SaleReport:
if (date.today() - start_date).days > 5 and "audit" not in user.permissions: today = (datetime.now() + timedelta(minutes=settings.TIMEZONE_OFFSET_MINUTES)).date()
if (today - start_date).days > 5 and "audit" not in user.permissions:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN, status_code=status.HTTP_403_FORBIDDEN,
detail="Accounts Audit", detail="Accounts Audit",
@ -66,8 +67,8 @@ def get_sale_analysis(
def get_sale(s: date, f: date, db: Session) -> List[SaleReportItem]: def get_sale(s: date, f: date, db: Session) -> List[SaleReportItem]:
start_date = s + timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES) start_date = datetime.combine(s, time()) + timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES)
finish_date = f + timedelta(days=1, minutes=settings.NEW_DAY_OFFSET_MINUTES) finish_date = datetime.combine(f, time()) + timedelta(days=1, minutes=settings.NEW_DAY_OFFSET_MINUTES)
day = func.date_trunc("day", Voucher.date - timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES)).label("day") day = func.date_trunc("day", Voucher.date - timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES)).label("day")
list_ = ( list_ = (
@ -102,8 +103,8 @@ def get_sale(s: date, f: date, db: Session) -> List[SaleReportItem]:
def get_settlements(s: date, f: date, db: Session) -> List[SaleReportItem]: def get_settlements(s: date, f: date, db: Session) -> List[SaleReportItem]:
start_date = s + timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES) start_date = datetime.combine(s, time()) + timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES)
finish_date = f + timedelta(days=1, minutes=settings.NEW_DAY_OFFSET_MINUTES) finish_date = datetime.combine(f, time()) + timedelta(days=1, minutes=settings.NEW_DAY_OFFSET_MINUTES)
list_ = ( list_ = (
db.query(SettleOption.name, func.sum(Settlement.amount)) db.query(SettleOption.name, func.sum(Settlement.amount))
@ -130,7 +131,8 @@ def print_report(
db: Session = Depends(get_db), db: Session = Depends(get_db),
user: UserToken = Security(get_user, scopes=["discount-report"]), user: UserToken = Security(get_user, scopes=["discount-report"]),
) -> bool: ) -> bool:
if (date.today() - start_date).days > 5 and "audit" not in user.permissions: today = (datetime.now() + timedelta(minutes=settings.TIMEZONE_OFFSET_MINUTES)).date()
if (today - start_date).days > 5 and "audit" not in user.permissions:
raise HTTPException( raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN, status_code=status.HTTP_403_FORBIDDEN,
detail="Accounts Audit", detail="Accounts Audit",

View File

@ -86,7 +86,7 @@ def do_save(
user: UserToken, user: UserToken,
): ):
now = datetime.now() now = datetime.now()
product_date = (now - timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES)).date() product_date = (now + timedelta(minutes=settings.TIMEZONE_OFFSET_MINUTES - settings.NEW_DAY_OFFSET_MINUTES)).date()
check_permissions(None, voucher_type, user.permissions) check_permissions(None, voucher_type, user.permissions)
bill_id = get_bill_id(voucher_type, db) bill_id = get_bill_id(voucher_type, db)

View File

@ -1,13 +1,14 @@
import re import re
import uuid import uuid
from datetime import date from datetime import datetime, timedelta
from typing import Optional from typing import Optional
from fastapi import APIRouter, Depends, HTTPException, Security, status from fastapi import APIRouter, Depends, HTTPException, Security, status
from sqlalchemy import and_, or_ from sqlalchemy import and_, or_
from sqlalchemy.orm import Session from sqlalchemy.orm import Session
from ...core.config import settings
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 ...models.food_table import FoodTable from ...models.food_table import FoodTable
@ -113,7 +114,10 @@ def from_table(
return voucher_blank(table, guest) return voucher_blank(table, guest)
def voucher_product(product_id: uuid.UUID, date_: date, is_happy_hour: bool, db: Session): def voucher_product(product_id: uuid.UUID, date_: datetime, is_happy_hour: bool, db: Session):
product_date = (
date_ + timedelta(minutes=settings.TIMEZONE_OFFSET_MINUTES - settings.NEW_DAY_OFFSET_MINUTES)
).date()
product: ProductVersion = ( product: ProductVersion = (
db.query(ProductVersion) db.query(ProductVersion)
.filter( .filter(
@ -121,11 +125,11 @@ def voucher_product(product_id: uuid.UUID, date_: date, is_happy_hour: bool, db:
ProductVersion.product_id == product_id, ProductVersion.product_id == product_id,
or_( or_(
ProductVersion.valid_from == None, # noqa: E711 ProductVersion.valid_from == None, # noqa: E711
ProductVersion.valid_from <= date_, ProductVersion.valid_from <= product_date,
), ),
or_( or_(
ProductVersion.valid_till == None, # noqa: E711 ProductVersion.valid_till == None, # noqa: E711
ProductVersion.valid_till >= date_, ProductVersion.valid_till >= product_date,
), ),
) )
) )
@ -158,14 +162,14 @@ def voucher_info(item: Voucher, db: Session):
"creationDateTip": item.creation_date.strftime("%d-%b-%Y %H:%M:%S"), "creationDateTip": item.creation_date.strftime("%d-%b-%Y %H:%M:%S"),
"lastEditDate": item.last_edit_date.strftime("%H:%M"), "lastEditDate": item.last_edit_date.strftime("%H:%M"),
"lastEditDateTip": item.last_edit_date.strftime("%d-%b-%Y %H:%M:%S"), "lastEditDateTip": item.last_edit_date.strftime("%d-%b-%Y %H:%M:%S"),
"kotId": item.kot_id,
"billId": item.full_bill_id, "billId": item.full_bill_id,
"table": {"id": item.food_table_id, "name": item.food_table.name}, "table": {"id": item.food_table_id, "name": item.food_table.name},
"customer": {"id": item.customer_id, "name": item.customer.name} if item.customer is not None else None, "customer": {"id": item.customer_id, "name": item.customer.name} if item.customer is not None else None,
"settlements": [], "guest": None, # TODO: Wire this functionality
"narration": item.narration, "narration": item.narration, # TODO: Wire this functionality
"reason": item.reason, "reason": item.reason,
"voucherType": item.voucher_type, "voucherType": item.voucher_type,
"kotId": item.kot_id,
"kots": [ "kots": [
{ {
"id": k.id, "id": k.id,
@ -176,7 +180,7 @@ def voucher_info(item: Voucher, db: Session):
{ {
"id": i.id, "id": i.id,
"sortOrder": i.sort_order, "sortOrder": i.sort_order,
"product": voucher_product(i.product_id, item.date.date(), i.is_happy_hour, db), "product": voucher_product(i.product_id, item.date, i.is_happy_hour, db),
"quantity": i.quantity, "quantity": i.quantity,
"price": i.price, "price": i.price,
"isHappyHour": i.is_happy_hour, "isHappyHour": i.is_happy_hour,
@ -197,7 +201,6 @@ def voucher_info(item: Voucher, db: Session):
} }
for k in item.kots for k in item.kots
], ],
"reprints": [],
} }

View File

@ -59,7 +59,9 @@ def update(
): ):
try: try:
now = datetime.now() now = datetime.now()
product_date = (now - timedelta(minutes=settings.NEW_DAY_OFFSET_MINUTES)).date() product_date = (
now + timedelta(minutes=settings.TIMEZONE_OFFSET_MINUTES - settings.NEW_DAY_OFFSET_MINUTES)
).date()
update_table = u update_table = u
voucher_type = VoucherType(p) voucher_type = VoucherType(p)
guest_book = get_guest_book(g, db) guest_book = get_guest_book(g, db)

View File

@ -8,49 +8,39 @@ import { VoucherType } from './voucher-type';
export class Bill { export class Bill {
id: string | undefined; id: string | undefined;
date: string; date: string;
dateTip: string;
pax: number; pax: number;
customer?: { id: string; name: string };
user: User; user: User;
creationDate: string; creationDate: string;
creationDateTip: string;
lastEditDate: string; lastEditDate: string;
billId: string; lastEditDateTip: string;
kotId: string; kotId: string;
billId: string;
table: Table; table: Table;
customer?: { id: string; name: string };
guest: GuestBook; guest: GuestBook;
// settlements: any[]; reason: string;
voidReason: string;
voucherType: VoucherType; voucherType: VoucherType;
serial: number;
kots: Kot[]; kots: Kot[];
// reprints: any[];
get dateTip(): string {
return this.date;
}
get creationDateTip(): string {
return this.date;
}
get lastEditDateTip(): string {
return this.date;
}
public constructor(init?: Partial<Bill>) { public constructor(init?: Partial<Bill>) {
this.id = undefined; this.id = undefined;
this.date = ''; this.date = '';
this.dateTip = '';
this.pax = 0; this.pax = 0;
this.user = new User(); this.user = new User();
this.creationDate = ''; this.creationDate = '';
this.creationDateTip = '';
this.lastEditDate = ''; this.lastEditDate = '';
this.lastEditDateTip = '';
this.billId = ''; this.billId = '';
this.kotId = ''; this.kotId = '';
this.table = new Table(); this.table = new Table();
this.guest = new GuestBook(); this.guest = new GuestBook();
// this.settlements = []; // this.settlements = [];
this.voidReason = ''; this.reason = '';
this.voucherType = VoucherType.Kot; this.voucherType = VoucherType.Kot;
this.serial = 0;
this.kots = []; this.kots = [];
// this.reprints = []; // this.reprints = [];
Object.assign(this, init); Object.assign(this, init);

View File

@ -27,12 +27,12 @@
</ng-container> </ng-container>
<ng-container matColumnDef="time-details"> <ng-container matColumnDef="time-details">
<mat-header-cell *matHeaderCellDef class="deep-purple-100 bold right-align" <mat-header-cell *matHeaderCellDef class="deep-purple-100 bold right-align"
><span [matTooltip]="bs.bill.dateTip">{{ bs.bill.date }}</span ><span [matTooltip]="bs.bill.dateTip | localTime">{{ bs.bill.date | localTime }}</span
>&nbsp;/&nbsp;<span [matTooltip]="bs.bill.creationDateTip">{{ >&nbsp;/&nbsp;<span [matTooltip]="bs.bill.creationDateTip | localTime">{{
bs.bill.creationDate bs.bill.creationDate | localTime
}}</span }}</span
>&nbsp;/&nbsp;<span [matTooltip]="bs.bill.lastEditDateTip">{{ >&nbsp;/&nbsp;<span [matTooltip]="bs.bill.lastEditDateTip | localTime">{{
bs.bill.lastEditDate bs.bill.lastEditDate | localTime
}}</span></mat-header-cell }}</span></mat-header-cell
> >
</ng-container> </ng-container>

View File

@ -9,6 +9,11 @@ export class LocalTimePipe implements PipeTransform {
if (value === undefined) { if (value === undefined) {
return ''; return '';
} }
if (value.length === 5) {
return moment(value, 'HH:mm')
.subtract(new Date().getTimezoneOffset(), 'minutes')
.format('HH:mm');
}
return moment(value, 'DD-MMM-YYYY HH:mm') return moment(value, 'DD-MMM-YYYY HH:mm')
.subtract(new Date().getTimezoneOffset(), 'minutes') .subtract(new Date().getTimezoneOffset(), 'minutes')
.format('DD-MMM-YYYY HH:mm'); .format('DD-MMM-YYYY HH:mm');