diff --git a/.env.dev b/.env.dev index e2f0c57..803e52e 100644 --- a/.env.dev +++ b/.env.dev @@ -13,7 +13,9 @@ DB_PASSWORD=pfLIVXupbDetvFMt2gUvxLXUL9b4HIOHaPcKXsBEZ1i8zl0iLUjmhUfXlGfJKcTV ENV RUNNING_IN_DOCKER=1 -CORS_ALLOWED_ORIGINS=http://localhost:8080,http://127.0.0.1:8080,http://127.0.0.1:3000,http://localhost:3000,http://192.168.88.130:3000,https://rasadyar.net,https://rasaddam-front.liara.run,https://dam.rasadyar.net,https://api.dam.rasadyar.com +CORS_ALLOWED_ORIGINS=http://localhost:8080,http://127.0.0.1:8080,http://127.0.0.1:3000,http://localhost:3000,http://192.168.88.130:3000,https://rasadyar.net,https://rasaddam-front.liara.run,https://dam.rasadyar.net,https://dam.rasadyar.com,https://api.dam.rasadyar.com + +REDIS_URL=rediss://default:wHM2fSW8EXtsoTjHxLZyyaRsD8IJm4tOU108252rizfmUYrp709PuCLUhr9mmYDK@31.7.78.133:14353/0 CELERY_BROKER_URL=rediss://default:wHM2fSW8EXtsoTjHxLZyyaRsD8IJm4tOU108252rizfmUYrp709PuCLUhr9mmYDK@31.7.78.133:14353/0 CELERY_RESULT_BACKEND=rediss://default:wHM2fSW8EXtsoTjHxLZyyaRsD8IJm4tOU108252rizfmUYrp709PuCLUhr9mmYDK@31.7.78.133:14353/0 diff --git a/.env.local b/.env.local index 4fe9361..67aaaa8 100644 --- a/.env.local +++ b/.env.local @@ -15,6 +15,8 @@ ENV RUNNING_IN_DOCKER= CORS_ALLOWED_ORIGINS=http://localhost:8080,http://127.0.0.1:8080,http://127.0.0.1:3000,http://localhost:3000,http://192.168.88.130:3000,https://rasadyar.net,https://rasaddam-front.liara.run,https://dam.rasadyar.net,https://api.dam.rasadyar.com +REDIS_URL=rediss://default:wHM2fSW8EXtsoTjHxLZyyaRsD8IJm4tOU108252rizfmUYrp709PuCLUhr9mmYDK@31.7.78.133:14353/0 + CELERY_BROKER_URL=rediss://default:wHM2fSW8EXtsoTjHxLZyyaRsD8IJm4tOU108252rizfmUYrp709PuCLUhr9mmYDK@31.7.78.133:14353/0 CELERY_RESULT_BACKEND=rediss://default:wHM2fSW8EXtsoTjHxLZyyaRsD8IJm4tOU108252rizfmUYrp709PuCLUhr9mmYDK@31.7.78.133:14353/0 CELERY_CACHE_BACKEND=default diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..a55e7a1 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/Rasaddam_Backend/settings.py b/Rasaddam_Backend/settings.py index b0c656e..2ca33d7 100644 --- a/Rasaddam_Backend/settings.py +++ b/Rasaddam_Backend/settings.py @@ -9,12 +9,13 @@ https://docs.djangoproject.com/en/5.2/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/5.2/ref/settings/ """ +import os import os.path from datetime import timedelta from pathlib import Path -import os -from dotenv import load_dotenv + from django.conf import settings +from dotenv import load_dotenv # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -235,7 +236,7 @@ SIMPLE_JWT = { CACHES = { "default": { "BACKEND": "django_redis.cache.RedisCache", - "LOCATION": "redis://:ydnW4hwzuDRYcTX3FWCHgQ1f@apo.liara.cloud:33740/0", + "LOCATION": os.environ.get("REDIS_URL"), "OPTIONS": { "CLIENT_CLASS": "django_redis.client.DefaultClient", }, @@ -251,7 +252,7 @@ CHANNEL_LAYERS = { "default": { "BACKEND": "channels_redis.core.RedisChannelLayer", "CONFIG": { - "hosts": [("redis://:ydnW4hwzuDRYcTX3FWCHgQ1f@apo.liara.cloud:33740/0")], # noqa + "hosts": [(os.environ.get("REDIS_URL"))], # noqa }, }, } @@ -394,7 +395,7 @@ JAZZMIN_SETTINGS = { # noqa "topmenu_links": [ # Url that gets reversed (Permissions can be added) - {"name": "Home", "url": "admin:index", "permissions": ["auth.view_user"]}, + {"name": "Home", "url": "admin:index", "permissions": ["auth.view_user"]}, # external url that opens in a new window (Permissions can be added) {"name": "Support", "url": "https://github.com/farridav/django-jazzmin/issues", "new_window": True}, diff --git a/apps/product/models.py b/apps/product/models.py index 46fe966..036dc51 100644 --- a/apps/product/models.py +++ b/apps/product/models.py @@ -1,13 +1,16 @@ -from apps.authentication.models import OrganizationType, Organization +from datetime import datetime + +import jdatetime from django.contrib.postgres.fields import ArrayField +from django.db import models +from django.db import transaction from simple_history.models import HistoricalRecords + +from apps.authentication.models import OrganizationType, Organization from apps.authorization.models import UserRelations -from apps.livestock.models import LiveStockType from apps.core.models import BaseModel from apps.herd.models import Rancher -from datetime import datetime -from django.db import models -import jdatetime +from apps.livestock.models import LiveStockType class LivestockGroup(models.TextChoices): @@ -406,12 +409,16 @@ class Quota(BaseModel): def generate_quota_id(self): # noqa """ generate id for quota from 1001 """ - last = Quota.objects.filter(quota_id__gte=1001, quota_id__lte=1999).order_by('-quota_id').first() - if last: - next_code = last.quota_id + 1 - else: - next_code = 1001 - return next_code + with transaction.atomic(): + last = Quota.objects.filter( + quota_id__gte=10001, + quota_id__lte=19999 + ).select_for_update().order_by('-quota_id').first() + if last: + next_code = last.quota_id + 1 + else: + next_code = 1001 + return next_code def calculate_final_price(self): """ calculate final price of quota """ diff --git a/apps/warehouse/pos/api/v1/serializers.py b/apps/warehouse/pos/api/v1/serializers.py index 62e7ad0..4e09cb2 100644 --- a/apps/warehouse/pos/api/v1/serializers.py +++ b/apps/warehouse/pos/api/v1/serializers.py @@ -1,38 +1,30 @@ +from django.db import models +from django.db.models import Q +from django.db.transaction import atomic +from rest_framework import serializers + +from apps.herd.models import Rancher +from apps.herd.pos.api.v1.serializers import RancherSerializer from apps.herd.services.services import get_rancher_statistics, rancher_quota_weight +from apps.pos_device.models import POSFreeProducts +from apps.pos_device.pos.api.v1.serializers.device import DeviceSerializer +from apps.pos_device.services.services import pos_organizations_sharing_information +from apps.product.exceptions import DistributionWeightException +from apps.product.models import ( + QuotaDistribution, + Product +) from apps.product.services.services import ( quota_live_stock_allocation_info, quota_incentive_plans_info, - quota_brokers_value, quota_attribute_value ) -from apps.pos_device.services.services import pos_organizations_sharing_information +from apps.warehouse import models as warehouse_models from apps.warehouse.services.quota_usage_services import QuotaUsageService -from apps.pos_device.pos.api.v1.serializers.device import DeviceSerializer -from apps.product.exceptions import DistributionWeightException -from apps.pos_device.models import POSFreeProducts from apps.warehouse.services.services import ( create_extra_sale, create_pre_sale ) -from apps.herd.pos.api.v1.serializers import RancherSerializer -from apps.product.models import ( - QuotaDistribution, - Product, - QuotaUsage, - IncentivePlan -) -from apps.warehouse import models as warehouse_models -from apps.livestock.models import LiveStockType -from django.db.models.signals import post_save -from apps.core.models import SystemConfig -from django.db.transaction import atomic -from apps.warehouse.exceptions import ( - TotalInventorySaleException -) -from rest_framework import serializers -from apps.herd.models import Rancher -from django.db.models import Q -from django.db import models class InventoryEntrySerializer(serializers.ModelSerializer): @@ -66,6 +58,7 @@ class InventoryEntrySerializer(serializers.ModelSerializer): 'sale_unit': instance.distribution.quota.sale_unit.unit, 'id': instance.distribution.id } + representation['quota'] = { 'quota_identity': instance.distribution.quota.quota_id, 'quota_weight': instance.distribution.quota.quota_weight, @@ -74,6 +67,7 @@ class InventoryEntrySerializer(serializers.ModelSerializer): ), 'quota_incentive_plans': quota_incentive_plans_info(instance.distribution.quota) } + representation['product'] = { 'image': instance.distribution.quota.product.img, 'name': instance.distribution.quota.product.name,