async def get_receipt_data(receipt_id, *, session):
    async with get(f"/receipts/{receipt_id}", session=session) as response:
        receipt_url = (await response.json())["tax_url"]
    receipt_qr = await get_receipt_qrcode(receipt_id, session=session)
    receipt_text = await get_receipt_text(receipt_id, session=session)

    return receipt_qr, receipt_url, receipt_text
Exemple #2
0
async def open_shift(*, session):
    async with post("/shifts", session=session, lic=True) as response:
        try:
            await raise_for_status(response)
        except ClientResponseError:
            raise CheckboxShiftError("Не вдалось відкрити зміну")
        shift = await response.json()

    shift_id = shift["id"]

    for _ in range(10):
        async with get("/cashier/shift", session=session) as response:
            try:
                shift = await response.json()
            except JSONDecodeError:
                pass
            else:
                if shift["status"] == "OPENED":
                    log.info("shift: %s", shift_id)
                    return shift_id

        await asyncio.sleep(1)

    log.error("shift error: %s", shift)
    raise CheckboxShiftError("Не вдалось підписати зміну")
Exemple #3
0
async def shift_close(*, session):
    await service_out(session=session)

    async with post("/shifts/close", session=session) as response:
        await raise_for_status(response)
        shift = await response.json()

    shift_id = shift["id"]
    balance = shift["balance"]["service_out"] / 100

    for _ in range(60):
        async with get("/cashier/shift", session=session) as response:
            try:
                shift = await response.json()
            except JSONDecodeError:
                pass
            else:
                if shift is None:
                    log.info("shift closed: %s", shift_id)
                    return balance

        await asyncio.sleep(1)

    log.error("shift close error: %s", shift)
    raise CheckboxShiftError("Не вдалось підписати закриття зміни")
Exemple #4
0
async def get_receipt_data(receipt_id):
    async with aiohttp.ClientSession() as session:
        async with get(session, f"/receipts/{receipt_id}") as response:
            receipt_url = (await response.json())["tax_url"]
        receipt_qr = await get_receipt_qrcode(session, receipt_id)
        receipt_text = await get_receipt_text(session, receipt_id)

    return receipt_qr, receipt_url, receipt_text
async def search_receipt(fiscal_code, *, session):
    async with get(
            "/receipts/search",
            session=session,
            fiscal_code=fiscal_code,
    ) as response:
        await raise_for_status(response)
        results = (await response.json())["results"]

    if results:
        return results[0]["id"]
Exemple #6
0
async def search_receipt(fiscal_code):
    async with aiohttp.ClientSession() as session:
        async with get(
            session,
            "/receipts/search",
            fiscal_code=fiscal_code,
        ) as response:
            await raise_for_status(response)
            results = (await response.json())["results"]

    if results:
        return results[0]["id"]
Exemple #7
0
async def wait_receipt_sign(receipt_id):
    async with aiohttp.ClientSession() as session:
        for _ in range(10):
            async with get(session, f"/receipts/{receipt_id}") as response:
                try:
                    receipt = await response.json()
                except JSONDecodeError:
                    pass
                else:
                    if receipt["status"] == "DONE":
                        return receipt["tax_url"]

            await asyncio.sleep(1)

    log.error("receipt signing error: %s", receipt)
    raise CheckboxReceiptError("Не вдалось підписати чек")
Exemple #8
0
async def service_out(session):
    shift = await current_shift(session)

    if not shift:
        raise CheckboxShiftError("Зміна закрита")

    balance = shift["balance"]["balance"]
    payment = {
        "type": "CASH",
        "value": -balance,
        "label": "Готівка",
    }

    async with post(session, "/receipts/service", payment=payment) as response:
        try:
            await raise_for_status(response)
        except ClientResponseError:
            raise CheckboxReceiptError("Не вдалось здійснити службову видачу")

        receipt = await response.json()

    receipt_id = receipt["id"]
    log.info("service out: %s", receipt_id)

    for _ in range(10):
        async with get(session, f"/receipts/{receipt_id}") as response:
            try:
                receipt = await response.json()
            except JSONDecodeError:
                pass
            else:
                if receipt["status"] == "DONE":
                    return receipt_id

        await asyncio.sleep(1)

    log.error("service out signing error: %s", receipt)
    raise CheckboxReceiptError("Не вдалось підписати службову видачу")
Exemple #9
0
async def current_shift(*, session):
    async with get("/cashier/shift", session=session) as response:
        await raise_for_status(response)
        result = await response.json()

    return result