dfsa
This commit is contained in:
@@ -8,8 +8,9 @@ PROJECT_NAME=barker
|
|||||||
|
|
||||||
MAX_WORKERS=4
|
MAX_WORKERS=4
|
||||||
|
|
||||||
REDIS_HOST=localhost
|
NATS_URL=nats://localhost:4222
|
||||||
REDIS_PORT=6379
|
SUBJECT="barker.print"
|
||||||
|
STREAM="barker_print_stream"
|
||||||
|
|
||||||
# openssl rand -hex 32
|
# openssl rand -hex 32
|
||||||
SECRET_KEY=611f9393e58f85521d16d9497bfd847ced70f2b99e12a9c6af40b7bd05cc7b1d
|
SECRET_KEY=611f9393e58f85521d16d9497bfd847ced70f2b99e12a9c6af40b7bd05cc7b1d
|
||||||
@@ -24,6 +25,5 @@ TIMEZONE_OFFSET_MINUTES=330
|
|||||||
ALEMBIC_LOG_LEVEL=INFO
|
ALEMBIC_LOG_LEVEL=INFO
|
||||||
ALEMBIC_SQLALCHEMY_LOG_LEVEL=WARN
|
ALEMBIC_SQLALCHEMY_LOG_LEVEL=WARN
|
||||||
|
|
||||||
WORKER_REDIS_HOST=
|
|
||||||
WORKER_REDIS_PORT=6379
|
FASTAPI_ENV=development
|
||||||
WORKER_QUEUE_NAME=""
|
|
||||||
|
|||||||
Vendored
+2
-2
@@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"python.defaultInterpreterPath": "/home/tanshu/programming/barker/barker/.venv/bin/python",
|
"python.defaultInterpreterPath": "barker/.venv/bin/python",
|
||||||
"python.terminal.useEnvFile": true,
|
"python.terminal.useEnvFile": true,
|
||||||
"python.interpreterPath": "/home/tanshu/programming/barker/barker/.venv/bin/python",
|
|
||||||
"python.venvFolders": [
|
"python.venvFolders": [
|
||||||
"barker/.venv",
|
"barker/.venv",
|
||||||
|
"frank/.venv",
|
||||||
".venv"
|
".venv"
|
||||||
],
|
],
|
||||||
"python.venvPath": "${workspaceFolder}/barker",
|
"python.venvPath": "${workspaceFolder}/barker",
|
||||||
|
|||||||
@@ -22,7 +22,8 @@ class Settings(BaseSettings):
|
|||||||
ALEMBIC_SQLALCHEMY_LOG_LEVEL: str = "WARN"
|
ALEMBIC_SQLALCHEMY_LOG_LEVEL: str = "WARN"
|
||||||
|
|
||||||
NATS_URL: str = "nats://127.0.0.1:4222"
|
NATS_URL: str = "nats://127.0.0.1:4222"
|
||||||
WORKER_QUEUE_NAME: str = "arq:queue"
|
SUBJECT: str = "barker.print"
|
||||||
|
STREAM: str = "barker_print_stream"
|
||||||
model_config = SettingsConfigDict(case_sensitive=True, env_file=".env")
|
model_config = SettingsConfigDict(case_sensitive=True, env_file=".env")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -19,24 +19,24 @@ class RoutedJetStreamBroker(PullBasedJetStreamBroker):
|
|||||||
|
|
||||||
broker = RoutedJetStreamBroker(
|
broker = RoutedJetStreamBroker(
|
||||||
settings.NATS_URL,
|
settings.NATS_URL,
|
||||||
subject="barker.print.>",
|
subject=f"{settings.SUBJECT}.>",
|
||||||
stream_name="barker_print_stream",
|
stream_name=f"{settings.STREAM}",
|
||||||
stream_config=StreamConfig(
|
stream_config=StreamConfig(
|
||||||
name="barker_print_stream",
|
name=f"{settings.STREAM}",
|
||||||
subjects=["barker.print.>"],
|
subjects=[f"{settings.SUBJECT}.>"],
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
main_loop: asyncio.AbstractEventLoop | None = None
|
main_loop: asyncio.AbstractEventLoop | None = None
|
||||||
|
|
||||||
|
|
||||||
@broker.task(task_name="sent_to_printer")
|
@broker.task(task_name="nat_print")
|
||||||
async def sent_to_printer(data: str, address: str, cut_code: str) -> None:
|
async def nat_print(data: str, cut_code: str) -> None:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def enqueue_print_job_sync(printer_name: str, data: str, address: str, cut_code: str) -> None:
|
def enqueue_print_job_sync(printer_name: str, data: str, cut_code: str) -> None:
|
||||||
coro = sent_to_printer.kicker().with_labels(queue=f"barker.print.{printer_name}").kiq(data, address, cut_code)
|
coro = nat_print.kicker().with_labels(queue=f"{settings.SUBJECT}.{printer_name}").kiq(data, cut_code)
|
||||||
|
|
||||||
if main_loop is not None and main_loop.is_running():
|
if main_loop is not None and main_loop.is_running():
|
||||||
asyncio.run_coroutine_threadsafe(coro, main_loop)
|
asyncio.run_coroutine_threadsafe(coro, main_loop)
|
||||||
|
|||||||
@@ -49,9 +49,9 @@ def print_bill(voucher_id: uuid.UUID, db: Session) -> None:
|
|||||||
|
|
||||||
if len(bills) > 1:
|
if len(bills) > 1:
|
||||||
total = design_total(voucher, regimes, db)
|
total = design_total(voucher, regimes, db)
|
||||||
enqueue_print_job_sync(printer.name, total, printer.address, printer.cut_code)
|
enqueue_print_job_sync(printer.name, total, printer.cut_code)
|
||||||
for bill in bills:
|
for bill in bills:
|
||||||
enqueue_print_job_sync(printer.name, bill, printer.address, printer.cut_code)
|
enqueue_print_job_sync(printer.name, bill, printer.cut_code)
|
||||||
|
|
||||||
|
|
||||||
def get_inventories(voucher: Voucher) -> list[Inventory]:
|
def get_inventories(voucher: Voucher) -> list[Inventory]:
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ def print_cashier_report(report: CashierReport, device_id: uuid.UUID, db: Sessio
|
|||||||
.where(SectionPrinter.sale_category_id == None) # noqa: E711
|
.where(SectionPrinter.sale_category_id == None) # noqa: E711
|
||||||
).scalar_one()
|
).scalar_one()
|
||||||
|
|
||||||
enqueue_print_job_sync(printer.name, summary, printer.address, printer.cut_code)
|
enqueue_print_job_sync(printer.name, summary, printer.cut_code)
|
||||||
enqueue_print_job_sync(printer.name, details, printer.address, printer.cut_code)
|
enqueue_print_job_sync(printer.name, details, printer.cut_code)
|
||||||
|
|
||||||
|
|
||||||
def design_cashier_report_summary(report: CashierReport) -> str:
|
def design_cashier_report_summary(report: CashierReport) -> str:
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ def print_discount_report(report: DiscountReport, device_id: uuid.UUID, db: Sess
|
|||||||
.where(SectionPrinter.sale_category_id == None) # noqa: E711
|
.where(SectionPrinter.sale_category_id == None) # noqa: E711
|
||||||
).scalar_one()
|
).scalar_one()
|
||||||
|
|
||||||
enqueue_print_job_sync(printer.name, data, printer.address, printer.cut_code)
|
enqueue_print_job_sync(printer.name, data, printer.cut_code)
|
||||||
|
|
||||||
|
|
||||||
def design_discount_report(report: DiscountReport) -> str:
|
def design_discount_report(report: DiscountReport) -> str:
|
||||||
|
|||||||
@@ -83,4 +83,4 @@ def print_kot(voucher_id: uuid.UUID, db: Session) -> None:
|
|||||||
printer, items = value
|
printer, items = value
|
||||||
for c in range(int(copies)):
|
for c in range(int(copies)):
|
||||||
data = design_kot(voucher, kot, items, c)
|
data = design_kot(voucher, kot, items, c)
|
||||||
enqueue_print_job_sync(printer.name, data, printer.address, printer.cut_code)
|
enqueue_print_job_sync(printer.name, data, printer.cut_code)
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ def print_product_sale_report(report: ProductSaleReport, device_id: uuid.UUID, d
|
|||||||
.where(SectionPrinter.sale_category_id == None) # noqa: E711
|
.where(SectionPrinter.sale_category_id == None) # noqa: E711
|
||||||
).scalar_one()
|
).scalar_one()
|
||||||
|
|
||||||
enqueue_print_job_sync(printer.name, data, printer.address, printer.cut_code)
|
enqueue_print_job_sync(printer.name, data, printer.cut_code)
|
||||||
|
|
||||||
|
|
||||||
def design_product_sale_report(report: ProductSaleReport) -> str:
|
def design_product_sale_report(report: ProductSaleReport) -> str:
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ def print_sale_report(report: SaleReport, device_id: uuid.UUID, db: Session) ->
|
|||||||
.where(SectionPrinter.sale_category_id == None) # noqa: E711
|
.where(SectionPrinter.sale_category_id == None) # noqa: E711
|
||||||
).scalar_one()
|
).scalar_one()
|
||||||
|
|
||||||
enqueue_print_job_sync(printer.name, data, printer.address, printer.cut_code)
|
enqueue_print_job_sync(printer.name, data, printer.cut_code)
|
||||||
|
|
||||||
|
|
||||||
def design_sale_report(report: SaleReport) -> str:
|
def design_sale_report(report: SaleReport) -> str:
|
||||||
|
|||||||
@@ -82,15 +82,6 @@ def check_gaps(data: TemporalProduct) -> None:
|
|||||||
skus: dict[uuid.UUID, list[SkuModel]] = defaultdict(list)
|
skus: dict[uuid.UUID, list[SkuModel]] = defaultdict(list)
|
||||||
for sku in data.skus:
|
for sku in data.skus:
|
||||||
skus[sku.id_].append(sku)
|
skus[sku.id_].append(sku)
|
||||||
for sku_list in skus.values():
|
|
||||||
if (
|
|
||||||
data.products[0].valid_from != sku_list[0].valid_from
|
|
||||||
or data.products[-1].valid_till != sku_list[-1].valid_till
|
|
||||||
):
|
|
||||||
raise HTTPException(
|
|
||||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
|
||||||
detail="Product and SKU versions validity do not match",
|
|
||||||
)
|
|
||||||
for i, p_item in enumerate(data.products[1:], start=1):
|
for i, p_item in enumerate(data.products[1:], start=1):
|
||||||
if data.products[i - 1].valid_till + timedelta(days=1) != p_item.valid_from: # type: ignore[operator]
|
if data.products[i - 1].valid_till + timedelta(days=1) != p_item.valid_from: # type: ignore[operator]
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
|
|||||||
Reference in New Issue
Block a user