From d4e14a1e51b42c88a0bea0bb02e8f7e022f2b098 Mon Sep 17 00:00:00 2001 From: Mojtaba-z Date: Sat, 18 Oct 2025 10:46:54 +0330 Subject: [PATCH] remove liara.json & workflow/liara.yaml - add Dockerfile & docker-compose file --- .env.dev | 15 ++++++++ .github/workflows/liara.yaml | 20 ---------- Dockerfile | 24 ++++++++++++ Rasaddam_Backend/settings.py | 8 ++-- apps/pos_device/services/services.py | 57 +++++++++++++++++++++------- docker-compose.yml | 10 +++++ liara.json | 8 ---- requirements.txt | 1 - 8 files changed, 97 insertions(+), 46 deletions(-) create mode 100644 .env.dev delete mode 100644 .github/workflows/liara.yaml create mode 100644 Dockerfile create mode 100644 docker-compose.yml delete mode 100644 liara.json diff --git a/.env.dev b/.env.dev new file mode 100644 index 0000000..ebf3670 --- /dev/null +++ b/.env.dev @@ -0,0 +1,15 @@ +# Django secrets +SECRET_KEY=super-insecure-django-key +DEBUG=True +ALLOWED_HOSTS=* +ENV_NAME=DEV + +# Datbase secrets +DB_HOST=localhost +DB_PORT=5432 +DB_NAME=example_db +DB_USERNAME=postgres +DB_PASSWORD=12345678 + +# Super user information +SUPERUSER_EMAIL=superuser@example.com diff --git a/.github/workflows/liara.yaml b/.github/workflows/liara.yaml deleted file mode 100644 index e769f87..0000000 --- a/.github/workflows/liara.yaml +++ /dev/null @@ -1,20 +0,0 @@ -name: CD-Liara -on: - push: - branches: - - main -jobs: - deploy: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: "22" - - name: update-liara - env: - LIARA_TOKEN: ${{ secrets.LIARA_API_TOKEN }} - run: | - npm i -g @liara/cli@7 - liara deploy --app="apidam" --api-token="$LIARA_TOKEN" --no-app-logs diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9ada4a5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,24 @@ +# pull official base image +FROM python:3.10.0-slim-buster + +# Create the app directory +RUN mkdir /app + +# set work directory +WORKDIR app/ + +# set environment variables +ENV PYTHONDONTWRITEBYTECODE 1 +ENV PYTHONUNBUFFERED 1 + +# install dependencies +RUN pip install --upgrade pip +COPY ./requirements.txt /app/ +RUN pip install -r requirements.txt + +# copy project +COPY . /app/ + +EXPOSE 5000 + +CMD ["python", "manage.py", "runserver", "0.0.0.0:5000"] \ No newline at end of file diff --git a/Rasaddam_Backend/settings.py b/Rasaddam_Backend/settings.py index 9714704..08867c5 100644 --- a/Rasaddam_Backend/settings.py +++ b/Rasaddam_Backend/settings.py @@ -39,7 +39,8 @@ ALLOWED_HOSTS = [ 'https://dam.rasadyar.net' 'http://localhost:3000', 'http://192.168.88.130:3000', - 'https://rasaddam-front.liara.run' + 'https://rasaddam-front.liara.run', + 'ns0ck4ksk0koks8ksw0ss08g.31.7.78.133.sslip.io' # noqa ] # Application definition @@ -346,7 +347,8 @@ CORS_ALLOWED_ORIGINS = ( 'http://192.168.88.130:3000', 'https://rasadyar.net', 'https://rasaddam-front.liara.run', - 'https://dam.rasadyar.net' + 'https://dam.rasadyar.net', + 'http://ns0ck4ksk0koks8ksw0ss08g.31.7.78.133.sslip.io' # noqa ) SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') @@ -354,7 +356,7 @@ SECURE_SSL_REDIRECT = False SESSION_COOKIE_SECURE = False CSRF_COOKIE_SECURE = False -JAZZMIN_SETTINGS = { +JAZZMIN_SETTINGS = { # noqa # title of the window (Will default to current_admin_site.site_title if absent or None) "site_title": "Library Admin", diff --git a/apps/pos_device/services/services.py b/apps/pos_device/services/services.py index fcfb474..3465862 100644 --- a/apps/pos_device/services/services.py +++ b/apps/pos_device/services/services.py @@ -47,22 +47,51 @@ def pos_organizations_sharing_information( }) # if device owner is an agency organization - # if owner_org.type.name == 'AGC': - agc_share_amount = owner_org.pos_stake_holders.filter( + if owner_org.type.name == 'AGC': + sharing_information_list = agency_organization_pos_info( + agency=owner_org, + pos_sharing_list=sharing_information_list, + device=device, + distribution=distribution + ) + + return sharing_information_list + + +def agency_organization_pos_info( + agency: Organization = None, + pos_sharing_list: list = None, + device: Device = None, + distribution: QuotaDistribution = None +) -> typing.Any: + """ + if pos org owner is an agency, calculate share amount of agency + and share amount of parent organization + """ + + # get agency share amount + agc_share_amount = agency.pos_stake_holders.filter( device=device, ).first().holders_share_amount.filter( quota_distribution=distribution ) - sharing_information_list.append({ - "organization_name": owner_org.name, - "bank_account": { - "credit_card": owner_org.bank_information.first().card, - "sheba": owner_org.bank_information.first().sheba, - "account": owner_org.bank_information.first().account, - } if owner_org.bank_information.exists() else {}, - "amount": agc_share_amount.first().share_amount if agc_share_amount else None, - "agency": True, - "default_account": True - }) + agc_share_amount = agc_share_amount.first().share_amount if agc_share_amount else None - return sharing_information_list + # calculate agency parent share amount + agc_parent_amount = next((item for item in pos_sharing_list if item.get('default_account')), None) + if agc_parent_amount and agc_share_amount: + agc_parent_amount['amount'] = agc_parent_amount['amount'] - agc_share_amount + + pos_sharing_list.append({ + "organization_name": agency.name, + "bank_account": { + "credit_card": agency.bank_information.first().card, + "sheba": agency.bank_information.first().sheba, + "account": agency.bank_information.first().account, + } if agency.bank_information.exists() else {}, + "amount": agc_share_amount, + "agency": True, + "default_account": True + }) + + return pos_sharing_list diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..bfd2918 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,10 @@ +version: '3.10' + +services: + web: + build: ./ + command: python manage.py runserver 0.0.0.0:5000 + volumes: + - ./app/:/usr/src/app/ + ports: + - "5000:5000" \ No newline at end of file diff --git a/liara.json b/liara.json deleted file mode 100644 index 9dd0fb1..0000000 --- a/liara.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "app": "apidam", - "port": 80, - "build": { - "location": "iran" - }, - "disks": [] -} \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 78896cb..0a671a4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -40,7 +40,6 @@ openpyxl packaging pillow==9.5.0 prompt-toolkit -psycopg2 psycopg2-binary pyasn1 pycparser