commit unversioned files ;)

This commit is contained in:
2025-07-04 11:34:32 +03:00
parent 78d570ad4f
commit 844a26a287
8 changed files with 343 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
import datetime
from models.enums import ContainerLength, ContainerType
PAYMENT_SCHEMA = {
"standart": [[0, 5, 25], [5, 20, 40], [40, 1000000, 75]],
"reefer": [[0, 7, 35], [7, 30, 60], [30, 1000000, 115]],
}
def calc_storage_amount(depot, container):
result = (depot.expedited_on - depot.received_on + datetime.timedelta(days=1)).days
if container.container_type == ContainerType.ct_reefer:
data = PAYMENT_SCHEMA["reefer"]
result -= 1
else:
data = PAYMENT_SCHEMA["standart"]
for i in data:
start, end, price = i
if start <= result < end:
price_per_day = price
break
if container.container_length in (
ContainerLength.cl_40_ft,
ContainerLength.cl_45_ft,
):
result *= 2
result = result * price_per_day
return result
+39
View File
@@ -0,0 +1,39 @@
from containers.models import Container
from preinfo.models import Preinfo
def filter_queryset_by_user(queryset, user):
"""
Filters the queryset based on the user's line or company.
If the user has a line, it filters by that line.
If the user has a company, it filters by all lines associated with that company.
"""
if user.line:
return queryset.filter(line=user.line)
elif user.company:
company_lines = user.company.line_company.all()
return queryset.filter(line__in=company_lines)
return queryset
def get_preinfo_by_number(number):
"""
Retrieves a PreinfoModel instance by its container number.
Returns None if no matching PreinfoModel is found.
"""
try:
return Preinfo.objects.get(container_number=number, received=False)
except Preinfo.DoesNotExist:
return None
def get_container_by_number(number):
"""
Retrieves a Container instance by its number.
Returns None if no matching Container is found.
"""
try:
return Container.objects.get(number=number, expedited=False)
except Container.DoesNotExist:
return None