Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[flake8]
max-line-length = 120
exclude =
.git,
__pycache__,
build,
dist
select = E9,F63,F7,F82
22 changes: 11 additions & 11 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,26 @@ jobs:

steps:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[dev]"

- name: Lint with flake8
run: |
flake8 fiscguy --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 fiscguy --count --exit-zero --max-complexity=10 --max-line-length=100 --statistics

- name: Test with pytest
run: |
pytest --cov=fiscguy --cov-report=xml --cov-report=term-missing
pytest fiscguy/tests --cov=fiscguy --cov-report=xml --cov-report=term-missing

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
Expand All @@ -46,21 +46,21 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies

- name: Install formatting tools
run: |
python -m pip install --upgrade pip
pip install black isort

- name: Check code formatting with Black
run: |
black --check fiscguy

- name: Check import sorting with isort
run: |
isort --check-only fiscguy
17 changes: 17 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
repos:
- repo: https://github.com/pre-commit/mirrors-isort
rev: v5.10.1
hooks:
- id: isort
name: isort (python import sorter)
entry: isort
language: system
types: [python]

- repo: https://github.com/psf/black
rev: 23.9.1
hooks:
- id: black
name: black (python code formatter)
language: system
types: [python]
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ buyer feature crud via endpoint and via api (a user can now attach buyer data on
- ZIMRA online heartbeat scheduler
- Background ping execution without Redis
- Engine-level scheduled task module (tasks.py)
- flake8 config

### Changed
- Internal structure of ping_device
Expand Down
10 changes: 4 additions & 6 deletions fiscguy/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,16 @@
providing a clean library interface for both API and programmatic use.
"""

from typing import Dict, Any
from typing import Any, Dict

from loguru import logger

from fiscguy.models import Device, FiscalDay, Taxes
from fiscguy.models import Configuration, Device, FiscalDay, Taxes
from fiscguy.serializers import ConfigurationSerializer, TaxSerializer
from fiscguy.services.closing_day_service import ClosingDayService
from fiscguy.services.receipt_service import ReceiptService
from fiscguy.zimra_base import ZIMRAClient
from fiscguy.zimra_receipt_handler import ZIMRAReceiptHandler
from fiscguy.models import Configuration
from fiscguy.serializers import ConfigurationSerializer
from fiscguy.serializers import TaxSerializer


# Module-level instances
_device = None
Expand Down
12 changes: 5 additions & 7 deletions fiscguy/management/commands/init_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from loguru import logger

from fiscguy.models import Certs, Device, Taxes
from fiscguy.zimra_crypto import ZIMRACrypto
from fiscguy.services.configuration_service import create_or_update_config
from fiscguy.zimra_crypto import ZIMRACrypto

"""
Management command to register a ZIMRA fiscal device and fetch its
Expand Down Expand Up @@ -62,10 +62,8 @@ def handle(self, *args, **options):
print("*" * 75)
print("\nDeveloped by Casper Moyo")
print("Version 0.1.5\n")
print(
"Welcome to device registration please input the following provided\
information as proveded by ZIMRA\n"
)
print("Welcome to device registration please input the following provided\
information as proveded by ZIMRA\n")

environment = input(
"Enter yes for production environment and no for test enviroment: "
Expand Down Expand Up @@ -193,11 +191,11 @@ def delete_all_test_data(self) -> None:
"""
try:
from fiscguy.models import (
FiscalDay,
Configuration,
FiscalCounter,
FiscalDay,
Receipt,
ReceiptLine,
Configuration,
)

with transaction.atomic():
Expand Down
14 changes: 8 additions & 6 deletions fiscguy/management/commands/ping_zimra.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
from django.core.management.base import BaseCommand
from zimra_base import ZIMRAClient
import time
from fiscguy.models import Device

from django.core.management.base import BaseCommand
from loguru import logger
from zimra_base import ZIMRAClient

from fiscguy.api import _get_client
from fiscguy.models import Device


class Command(BaseCommand):
help = "Ping ZIMRA periodically"

def handle(self, *arg, **optioons):
def handle(self, *arg, **optioons):
logger.info("Ping for Initiatiated")
while True:
try:
res = _get_client().ping()
time.sleep(res['reportingFrequency'])
res = _get_client().ping()
time.sleep(res["reportingFrequency"])
except Exception as e:
logger.error(f"Failed to ping zimra: {e}")
Loading