diff --git a/.idea/DepoT.iml b/.idea/DepoT.iml
index 1cae4c6..776d648 100644
--- a/.idea/DepoT.iml
+++ b/.idea/DepoT.iml
@@ -16,7 +16,7 @@
-
+
diff --git a/.idea/dataSources.local.xml b/.idea/dataSources.local.xml
index 24a9a0b..7ef0a74 100644
--- a/.idea/dataSources.local.xml
+++ b/.idea/dataSources.local.xml
@@ -1,6 +1,6 @@
-
+
"
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 35c55fd..0120671 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -3,4 +3,5 @@
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 49b3ae0..d928493 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -5,14 +5,18 @@
+
+
+
+
-
-
+
-
-
+
-
+
+
+
@@ -67,6 +71,7 @@
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"nodejs_package_manager_path": "npm",
+ "settings.editor.selected.configurable": "preferences.editor",
"vue.rearranger.settings.migration": "true"
},
"keyToStringList": {
@@ -91,7 +96,7 @@
-
+
@@ -101,9 +106,10 @@
-
+
+
-
+
@@ -189,7 +195,7 @@
-
+
@@ -224,8 +230,8 @@
-
-
+
+
@@ -247,6 +253,7 @@
+
@@ -368,28 +375,18 @@
file://$PROJECT_DIR$/booking/tests.py
- 90
-
+ 97
+
file://$PROJECT_DIR$/booking/tests.py
- 76
-
-
-
- file://$PROJECT_DIR$/booking/views/client_views.py
- 40
-
-
-
- file://$PROJECT_DIR$/booking/views/client_views.py
- 46
-
+ 90
+
file://$PROJECT_DIR$/booking/tests.py
- 75
-
+ 11
+
file://$PROJECT_DIR$/static/js/container_validation.js
@@ -407,9 +404,10 @@
+
+
-
\ No newline at end of file
diff --git a/DepoT/__pycache__/__init__.cpython-313.pyc b/DepoT/__pycache__/__init__.cpython-313.pyc
index 0b30241..f6bd0e2 100644
Binary files a/DepoT/__pycache__/__init__.cpython-313.pyc and b/DepoT/__pycache__/__init__.cpython-313.pyc differ
diff --git a/DepoT/__pycache__/urls.cpython-313.pyc b/DepoT/__pycache__/urls.cpython-313.pyc
index abc2140..84db475 100644
Binary files a/DepoT/__pycache__/urls.cpython-313.pyc and b/DepoT/__pycache__/urls.cpython-313.pyc differ
diff --git a/DepoT/__pycache__/wsgi.cpython-313.pyc b/DepoT/__pycache__/wsgi.cpython-313.pyc
index c2ff2fd..bcb831c 100644
Binary files a/DepoT/__pycache__/wsgi.cpython-313.pyc and b/DepoT/__pycache__/wsgi.cpython-313.pyc differ
diff --git a/DepoT/mixins/__pycache__/LineFiltweFormMixin.cpython-313.pyc b/DepoT/mixins/__pycache__/LineFiltweFormMixin.cpython-313.pyc
index b762d3b..271523b 100644
Binary files a/DepoT/mixins/__pycache__/LineFiltweFormMixin.cpython-313.pyc and b/DepoT/mixins/__pycache__/LineFiltweFormMixin.cpython-313.pyc differ
diff --git a/accounts/__pycache__/__init__.cpython-313.pyc b/accounts/__pycache__/__init__.cpython-313.pyc
index 2407607..ff85c13 100644
Binary files a/accounts/__pycache__/__init__.cpython-313.pyc and b/accounts/__pycache__/__init__.cpython-313.pyc differ
diff --git a/accounts/__pycache__/admin.cpython-313.pyc b/accounts/__pycache__/admin.cpython-313.pyc
index 459858a..2f7b998 100644
Binary files a/accounts/__pycache__/admin.cpython-313.pyc and b/accounts/__pycache__/admin.cpython-313.pyc differ
diff --git a/accounts/__pycache__/apps.cpython-313.pyc b/accounts/__pycache__/apps.cpython-313.pyc
index 35d7e00..25d1e8b 100644
Binary files a/accounts/__pycache__/apps.cpython-313.pyc and b/accounts/__pycache__/apps.cpython-313.pyc differ
diff --git a/accounts/__pycache__/forms.cpython-313.pyc b/accounts/__pycache__/forms.cpython-313.pyc
index 96a62e0..d9f6477 100644
Binary files a/accounts/__pycache__/forms.cpython-313.pyc and b/accounts/__pycache__/forms.cpython-313.pyc differ
diff --git a/accounts/__pycache__/models.cpython-313.pyc b/accounts/__pycache__/models.cpython-313.pyc
index d8757d1..0492e37 100644
Binary files a/accounts/__pycache__/models.cpython-313.pyc and b/accounts/__pycache__/models.cpython-313.pyc differ
diff --git a/accounts/__pycache__/urls.cpython-313.pyc b/accounts/__pycache__/urls.cpython-313.pyc
index 1ab8ea4..d55f670 100644
Binary files a/accounts/__pycache__/urls.cpython-313.pyc and b/accounts/__pycache__/urls.cpython-313.pyc differ
diff --git a/accounts/__pycache__/views.cpython-313.pyc b/accounts/__pycache__/views.cpython-313.pyc
index f661bc3..f06778d 100644
Binary files a/accounts/__pycache__/views.cpython-313.pyc and b/accounts/__pycache__/views.cpython-313.pyc differ
diff --git a/accounts/migrations/__pycache__/0001_initial.cpython-313.pyc b/accounts/migrations/__pycache__/0001_initial.cpython-313.pyc
index 01413fc..dd02cf3 100644
Binary files a/accounts/migrations/__pycache__/0001_initial.cpython-313.pyc and b/accounts/migrations/__pycache__/0001_initial.cpython-313.pyc differ
diff --git a/accounts/migrations/__pycache__/0002_clientpermission_codename_clientpermission_name.cpython-313.pyc b/accounts/migrations/__pycache__/0002_clientpermission_codename_clientpermission_name.cpython-313.pyc
index 2d06789..45ec870 100644
Binary files a/accounts/migrations/__pycache__/0002_clientpermission_codename_clientpermission_name.cpython-313.pyc and b/accounts/migrations/__pycache__/0002_clientpermission_codename_clientpermission_name.cpython-313.pyc differ
diff --git a/accounts/migrations/__pycache__/0003_remove_depotuser_is_company_admin_and_more.cpython-313.pyc b/accounts/migrations/__pycache__/0003_remove_depotuser_is_company_admin_and_more.cpython-313.pyc
index 30ca170..740612d 100644
Binary files a/accounts/migrations/__pycache__/0003_remove_depotuser_is_company_admin_and_more.cpython-313.pyc and b/accounts/migrations/__pycache__/0003_remove_depotuser_is_company_admin_and_more.cpython-313.pyc differ
diff --git a/accounts/migrations/__pycache__/0004_employeepermission_depotuser_employee_permissions.cpython-313.pyc b/accounts/migrations/__pycache__/0004_employeepermission_depotuser_employee_permissions.cpython-313.pyc
index 37b9266..6846c2e 100644
Binary files a/accounts/migrations/__pycache__/0004_employeepermission_depotuser_employee_permissions.cpython-313.pyc and b/accounts/migrations/__pycache__/0004_employeepermission_depotuser_employee_permissions.cpython-313.pyc differ
diff --git a/accounts/migrations/__pycache__/0005_alter_depotuser_managers_alter_depotuser_user_type.cpython-313.pyc b/accounts/migrations/__pycache__/0005_alter_depotuser_managers_alter_depotuser_user_type.cpython-313.pyc
index 89bb1bb..c395f00 100644
Binary files a/accounts/migrations/__pycache__/0005_alter_depotuser_managers_alter_depotuser_user_type.cpython-313.pyc and b/accounts/migrations/__pycache__/0005_alter_depotuser_managers_alter_depotuser_user_type.cpython-313.pyc differ
diff --git a/accounts/migrations/__pycache__/0006_alter_clientpermission_options.cpython-313.pyc b/accounts/migrations/__pycache__/0006_alter_clientpermission_options.cpython-313.pyc
index ed6dc68..f7581e6 100644
Binary files a/accounts/migrations/__pycache__/0006_alter_clientpermission_options.cpython-313.pyc and b/accounts/migrations/__pycache__/0006_alter_clientpermission_options.cpython-313.pyc differ
diff --git a/accounts/migrations/__pycache__/0007_auto_20250725_1920.cpython-313.pyc b/accounts/migrations/__pycache__/0007_auto_20250725_1920.cpython-313.pyc
index 5876002..a48583a 100644
Binary files a/accounts/migrations/__pycache__/0007_auto_20250725_1920.cpython-313.pyc and b/accounts/migrations/__pycache__/0007_auto_20250725_1920.cpython-313.pyc differ
diff --git a/accounts/migrations/__pycache__/0008_populate_permissions.cpython-313.pyc b/accounts/migrations/__pycache__/0008_populate_permissions.cpython-313.pyc
index c235ba1..c24aa9a 100644
Binary files a/accounts/migrations/__pycache__/0008_populate_permissions.cpython-313.pyc and b/accounts/migrations/__pycache__/0008_populate_permissions.cpython-313.pyc differ
diff --git a/accounts/migrations/__pycache__/0009_create_superuser.cpython-313.pyc b/accounts/migrations/__pycache__/0009_create_superuser.cpython-313.pyc
index c98986c..0682ee9 100644
Binary files a/accounts/migrations/__pycache__/0009_create_superuser.cpython-313.pyc and b/accounts/migrations/__pycache__/0009_create_superuser.cpython-313.pyc differ
diff --git a/accounts/migrations/__pycache__/__init__.cpython-313.pyc b/accounts/migrations/__pycache__/__init__.cpython-313.pyc
index ca357de..b8cfc8b 100644
Binary files a/accounts/migrations/__pycache__/__init__.cpython-313.pyc and b/accounts/migrations/__pycache__/__init__.cpython-313.pyc differ
diff --git a/booking/__pycache__/__init__.cpython-313.pyc b/booking/__pycache__/__init__.cpython-313.pyc
index b565210..ec355b0 100644
Binary files a/booking/__pycache__/__init__.cpython-313.pyc and b/booking/__pycache__/__init__.cpython-313.pyc differ
diff --git a/booking/__pycache__/admin.cpython-313.pyc b/booking/__pycache__/admin.cpython-313.pyc
index 936c6d2..08c6ca8 100644
Binary files a/booking/__pycache__/admin.cpython-313.pyc and b/booking/__pycache__/admin.cpython-313.pyc differ
diff --git a/booking/__pycache__/apps.cpython-313.pyc b/booking/__pycache__/apps.cpython-313.pyc
index f0fc6cc..c034f57 100644
Binary files a/booking/__pycache__/apps.cpython-313.pyc and b/booking/__pycache__/apps.cpython-313.pyc differ
diff --git a/booking/__pycache__/forms.cpython-313.pyc b/booking/__pycache__/forms.cpython-313.pyc
index 8b46dcb..4af9f58 100644
Binary files a/booking/__pycache__/forms.cpython-313.pyc and b/booking/__pycache__/forms.cpython-313.pyc differ
diff --git a/booking/__pycache__/models.cpython-313.pyc b/booking/__pycache__/models.cpython-313.pyc
index 9ad9cc0..6fc7a81 100644
Binary files a/booking/__pycache__/models.cpython-313.pyc and b/booking/__pycache__/models.cpython-313.pyc differ
diff --git a/booking/__pycache__/urls.cpython-313.pyc b/booking/__pycache__/urls.cpython-313.pyc
index 27f5fc8..bb1e331 100644
Binary files a/booking/__pycache__/urls.cpython-313.pyc and b/booking/__pycache__/urls.cpython-313.pyc differ
diff --git a/booking/migrations/__pycache__/0001_initial.cpython-313.pyc b/booking/migrations/__pycache__/0001_initial.cpython-313.pyc
index 3f59789..d147510 100644
Binary files a/booking/migrations/__pycache__/0001_initial.cpython-313.pyc and b/booking/migrations/__pycache__/0001_initial.cpython-313.pyc differ
diff --git a/booking/migrations/__pycache__/0002_rename_bookingmodel_booking.cpython-313.pyc b/booking/migrations/__pycache__/0002_rename_bookingmodel_booking.cpython-313.pyc
index f805bb1..d4814d3 100644
Binary files a/booking/migrations/__pycache__/0002_rename_bookingmodel_booking.cpython-313.pyc and b/booking/migrations/__pycache__/0002_rename_bookingmodel_booking.cpython-313.pyc differ
diff --git a/booking/migrations/__pycache__/0003_booking_container_expedited_count.cpython-313.pyc b/booking/migrations/__pycache__/0003_booking_container_expedited_count.cpython-313.pyc
index c2801fb..543762e 100644
Binary files a/booking/migrations/__pycache__/0003_booking_container_expedited_count.cpython-313.pyc and b/booking/migrations/__pycache__/0003_booking_container_expedited_count.cpython-313.pyc differ
diff --git a/booking/migrations/__pycache__/0004_booking_status.cpython-313.pyc b/booking/migrations/__pycache__/0004_booking_status.cpython-313.pyc
index fea6f12..f01a92d 100644
Binary files a/booking/migrations/__pycache__/0004_booking_status.cpython-313.pyc and b/booking/migrations/__pycache__/0004_booking_status.cpython-313.pyc differ
diff --git a/booking/migrations/__pycache__/0005_alter_booking_vehicles_left.cpython-313.pyc b/booking/migrations/__pycache__/0005_alter_booking_vehicles_left.cpython-313.pyc
index 9550a28..31c6ead 100644
Binary files a/booking/migrations/__pycache__/0005_alter_booking_vehicles_left.cpython-313.pyc and b/booking/migrations/__pycache__/0005_alter_booking_vehicles_left.cpython-313.pyc differ
diff --git a/booking/migrations/__pycache__/__init__.cpython-313.pyc b/booking/migrations/__pycache__/__init__.cpython-313.pyc
index c590668..be5f6fe 100644
Binary files a/booking/migrations/__pycache__/__init__.cpython-313.pyc and b/booking/migrations/__pycache__/__init__.cpython-313.pyc differ
diff --git a/booking/models.py b/booking/models.py
index 0f55f47..8d6fe63 100644
--- a/booking/models.py
+++ b/booking/models.py
@@ -1,4 +1,8 @@
+from django.core.exceptions import ValidationError
from django.db import models
+
+from accounts.models import DepotUser
+from common.fields import ContainerNumberField, UpperCaseCharField
from common.models import ContainerTypeModel, LinesModel, OperationModel
# Create your models here.
@@ -10,15 +14,15 @@ class Booking(models.Model):
('canceled', 'Canceled'),
]
- number = models.CharField(max_length=50, unique=True)
- vehicles = models.CharField(blank=True, null=True)
+ number = UpperCaseCharField(max_length=50)
+ vehicles = UpperCaseCharField(blank=True, null=True)
container_type = models.ForeignKey(
ContainerTypeModel,
on_delete=models.CASCADE,
related_name='booking_container_types',
)
- container_count = models.IntegerField()
- container_expedited_count = models.IntegerField(default=0)
+ container_count = models.PositiveIntegerField()
+ container_expedited_count = models.PositiveIntegerField(default=0)
carrier = models.CharField(max_length=100, blank=True, null=True)
line = models.ForeignKey(
LinesModel,
@@ -27,12 +31,12 @@ class Booking(models.Model):
)
visible = models.BooleanField(default=True)
is_new = models.BooleanField(default=True)
- container_number = models.CharField(max_length=11, blank=True, null=True)
+ container_number = ContainerNumberField(max_length=11, blank=True, null=True)
vehicles_left = models.CharField(blank=True, null=True)
created_on = models.DateTimeField(auto_now_add=True)
- created_by = models.IntegerField()
+ created_by = models.ForeignKey(DepotUser, related_name='booking_user', on_delete=models.CASCADE)
updated_on = models.DateTimeField(auto_now=True)
- updated_by = models.IntegerField()
+ updated_by = models.ForeignKey(DepotUser, related_name='booking_user', on_delete=models.CASCADE)
status = models.CharField(
max_length=10,
choices=STATUS_CHOICES,
@@ -44,4 +48,8 @@ class Booking(models.Model):
return self.container_count - (self.container_expedited_count or 0)
class Meta:
- app_label = 'booking'
\ No newline at end of file
+ app_label = 'booking'
+
+ def clean(self):
+ if Booking.objects.filter(number=self.number, status='active').exclude(id=self.id).exists():
+ raise ValidationError(f'Booking with number {self.number} already exists and is active.')
diff --git a/booking/templatetags/__pycache__/__init__.cpython-313.pyc b/booking/templatetags/__pycache__/__init__.cpython-313.pyc
index f8c4aa7..84ec1da 100644
Binary files a/booking/templatetags/__pycache__/__init__.cpython-313.pyc and b/booking/templatetags/__pycache__/__init__.cpython-313.pyc differ
diff --git a/booking/templatetags/__pycache__/custom_filters.cpython-313.pyc b/booking/templatetags/__pycache__/custom_filters.cpython-313.pyc
index 7573f43..c7f3888 100644
Binary files a/booking/templatetags/__pycache__/custom_filters.cpython-313.pyc and b/booking/templatetags/__pycache__/custom_filters.cpython-313.pyc differ
diff --git a/booking/tests.py b/booking/tests.py
index 94e9d57..a282b7c 100644
--- a/booking/tests.py
+++ b/booking/tests.py
@@ -45,8 +45,8 @@ class BookingViewsTestCase(TestCase):
line=self.line,
created_by=self.user_employee_all_rights.id,
updated_by=self.user_employee_all_rights.id,
- vehicles='',
- vehicles_left='',
+ vehicles='K1,J2,K3',
+ vehicles_left='K1,J2,K3',
)
@@ -72,8 +72,8 @@ class BookingViewsTestCase(TestCase):
self.assertTemplateUsed(response, 'employee/booking-list.html')
self.assertContains(response, self.booking.number)
- def test_booking_create_view(self):
- self.assertTrue( self.user_client_all_rights.has_company_perm('can_view_booking'))
+ def test_client_create_booking__expect_redirect_to_booking_list_and_booking_in_db(self):
+ self.assertTrue( self.user_client_all_rights.has_company_perm('can_manage_booking'))
self.client.login(username=self.user_client_all_rights.username, password=self.user_password)
response = self.client.post(reverse('client_booking_create'), {
@@ -84,16 +84,17 @@ class BookingViewsTestCase(TestCase):
'vehicles': 'Truck1,Truck2',
'vehicles_left': 'Truck1,Truck2',
})
- self.assertEqual(response.status_code, 200)
+ self.assertEqual(response.status_code, 302)
self.assertTrue(Booking.objects.filter(number='BOOK456').exists())
- # def test_booking_update_view(self):
- # response = self.client.post(reverse('booking-update', args=[self.booking.id]), {
- # 'number': 'BOOK123-updated',
- # 'container_type': self.container_type.id,
- # 'container_count': 15,
- # 'line': self.line.id,
- # })
- # self.assertEqual(response.status_code, 302)
- # self.booking.refresh_from_db()
- # self.assertEqual(self.booking.number, 'BOOK123-updated')
\ No newline at end of file
+ def test_booking_update_view(self):
+ self.client.login(username=self.user_client_all_rights.username, password=self.user_password)
+ response = self.client.post(reverse('client_booking_update', args=[self.booking.id]), {
+ 'number': 'BOOK123-updated',
+ 'container_type': self.container_type.id,
+ 'container_count': 15,
+ 'line': self.line.id,
+ })
+ self.assertEqual(response.status_code, 302)
+ self.booking.refresh_from_db()
+ self.assertEqual(self.booking.number, 'BOOK123-updated')
diff --git a/booking/views/__pycache__/__init__.cpython-313.pyc b/booking/views/__pycache__/__init__.cpython-313.pyc
index de94175..dd266d9 100644
Binary files a/booking/views/__pycache__/__init__.cpython-313.pyc and b/booking/views/__pycache__/__init__.cpython-313.pyc differ
diff --git a/booking/views/__pycache__/client_views.cpython-313.pyc b/booking/views/__pycache__/client_views.cpython-313.pyc
index d96d78c..70fec42 100644
Binary files a/booking/views/__pycache__/client_views.cpython-313.pyc and b/booking/views/__pycache__/client_views.cpython-313.pyc differ
diff --git a/booking/views/__pycache__/employee_views.cpython-313.pyc b/booking/views/__pycache__/employee_views.cpython-313.pyc
index 5a946f5..1ea40bf 100644
Binary files a/booking/views/__pycache__/employee_views.cpython-313.pyc and b/booking/views/__pycache__/employee_views.cpython-313.pyc differ
diff --git a/booking/views/client_views.py b/booking/views/client_views.py
index b61bf76..22abb77 100644
--- a/booking/views/client_views.py
+++ b/booking/views/client_views.py
@@ -59,4 +59,4 @@ class ClientBookingUpdateView(LoginRequiredMixin, UserPassesTestMixin, LineFilte
return super().form_valid(form)
def test_func(self):
- return self.request.user.has_company_perm('can_edit_preinfo') or self.request.user.user_type == 'CA'
\ No newline at end of file
+ return self.request.user.has_company_perm('can_manage_booking') or self.request.user.user_type == 'CA'
diff --git a/common/__pycache__/__init__.cpython-313.pyc b/common/__pycache__/__init__.cpython-313.pyc
index 5177d5d..572f2e8 100644
Binary files a/common/__pycache__/__init__.cpython-313.pyc and b/common/__pycache__/__init__.cpython-313.pyc differ
diff --git a/common/__pycache__/admin.cpython-313.pyc b/common/__pycache__/admin.cpython-313.pyc
index cb4d4e1..e7728d2 100644
Binary files a/common/__pycache__/admin.cpython-313.pyc and b/common/__pycache__/admin.cpython-313.pyc differ
diff --git a/common/__pycache__/apps.cpython-313.pyc b/common/__pycache__/apps.cpython-313.pyc
index 1eaf16a..816ea63 100644
Binary files a/common/__pycache__/apps.cpython-313.pyc and b/common/__pycache__/apps.cpython-313.pyc differ
diff --git a/common/__pycache__/models.cpython-313.pyc b/common/__pycache__/models.cpython-313.pyc
index 19da3da..e800876 100644
Binary files a/common/__pycache__/models.cpython-313.pyc and b/common/__pycache__/models.cpython-313.pyc differ
diff --git a/common/__pycache__/urls.cpython-313.pyc b/common/__pycache__/urls.cpython-313.pyc
index 074737e..01a3855 100644
Binary files a/common/__pycache__/urls.cpython-313.pyc and b/common/__pycache__/urls.cpython-313.pyc differ
diff --git a/common/fields.py b/common/fields.py
new file mode 100644
index 0000000..6a3bdaa
--- /dev/null
+++ b/common/fields.py
@@ -0,0 +1,29 @@
+from django.core.exceptions import ValidationError
+from django.db import models
+
+
+class UpperCaseCharField(models.CharField):
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+
+ def get_prep_value(self, value):
+ value = super().get_prep_value(value)
+ if value is not None:
+ return value.upper()
+ return value
+
+
+class ContainerNumberField(UpperCaseCharField):
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+
+ def get_prep_value(self, value):
+ value = super().get_prep_value(value)
+ if value is not None:
+ return value.upper()
+ return value
+
+ def validate(self, value, model_instance):
+ super().validate(value, model_instance)
+ if value and len(value) != 11:
+ raise ValidationError('Container number must be exactly 11 characters long.')
diff --git a/common/forms/__pycache__/company.cpython-313.pyc b/common/forms/__pycache__/company.cpython-313.pyc
index 8b2c7d8..1902e14 100644
Binary files a/common/forms/__pycache__/company.cpython-313.pyc and b/common/forms/__pycache__/company.cpython-313.pyc differ
diff --git a/common/forms/__pycache__/line.cpython-313.pyc b/common/forms/__pycache__/line.cpython-313.pyc
index dba8834..2a2a798 100644
Binary files a/common/forms/__pycache__/line.cpython-313.pyc and b/common/forms/__pycache__/line.cpython-313.pyc differ
diff --git a/common/migrations/__pycache__/0001_initial.cpython-313.pyc b/common/migrations/__pycache__/0001_initial.cpython-313.pyc
index 723e4e6..f15b298 100644
Binary files a/common/migrations/__pycache__/0001_initial.cpython-313.pyc and b/common/migrations/__pycache__/0001_initial.cpython-313.pyc differ
diff --git a/common/migrations/__pycache__/0002_alter_companymodel_short_name_and_more.cpython-313.pyc b/common/migrations/__pycache__/0002_alter_companymodel_short_name_and_more.cpython-313.pyc
index 0aa2f63..4cef09b 100644
Binary files a/common/migrations/__pycache__/0002_alter_companymodel_short_name_and_more.cpython-313.pyc and b/common/migrations/__pycache__/0002_alter_companymodel_short_name_and_more.cpython-313.pyc differ
diff --git a/common/migrations/__pycache__/0003_auto_20250725_1920.cpython-313.pyc b/common/migrations/__pycache__/0003_auto_20250725_1920.cpython-313.pyc
index 5e709b3..cfc2be7 100644
Binary files a/common/migrations/__pycache__/0003_auto_20250725_1920.cpython-313.pyc and b/common/migrations/__pycache__/0003_auto_20250725_1920.cpython-313.pyc differ
diff --git a/common/migrations/__pycache__/0004_populate_initial_data.cpython-313.pyc b/common/migrations/__pycache__/0004_populate_initial_data.cpython-313.pyc
index 2cde581..9ba80d7 100644
Binary files a/common/migrations/__pycache__/0004_populate_initial_data.cpython-313.pyc and b/common/migrations/__pycache__/0004_populate_initial_data.cpython-313.pyc differ
diff --git a/common/migrations/__pycache__/0005_companymodel_active_containerkindmodel_active_and_more.cpython-313.pyc b/common/migrations/__pycache__/0005_companymodel_active_containerkindmodel_active_and_more.cpython-313.pyc
index bb5f2ea..21973e6 100644
Binary files a/common/migrations/__pycache__/0005_companymodel_active_containerkindmodel_active_and_more.cpython-313.pyc and b/common/migrations/__pycache__/0005_companymodel_active_containerkindmodel_active_and_more.cpython-313.pyc differ
diff --git a/common/migrations/__pycache__/__init__.cpython-313.pyc b/common/migrations/__pycache__/__init__.cpython-313.pyc
index 7951a71..e6b3295 100644
Binary files a/common/migrations/__pycache__/__init__.cpython-313.pyc and b/common/migrations/__pycache__/__init__.cpython-313.pyc differ
diff --git a/common/models.py b/common/models.py
index e482091..2f81ab6 100644
--- a/common/models.py
+++ b/common/models.py
@@ -1,22 +1,39 @@
from django.db import models
+from django.core.exceptions import ValidationError
+
+from common.fields import UpperCaseCharField
+
# Create your models here.
class NomenclatureBaseModel(models.Model):
- name = models.CharField(max_length=100, unique=True)
- short_name = models.CharField(max_length=5, null=True, blank=True)
+ name = UpperCaseCharField(max_length=100)
+ short_name = UpperCaseCharField(max_length=5, null=True, blank=True)
description = models.TextField(blank=True, null=True)
active = models.BooleanField(default=True)
+
class Meta:
abstract = True
ordering = ['name']
- app_label = 'common'
+
def __str__(self):
return self.name
+ def clean(self):
+ if not self.name:
+ raise ValidationError('Name cannot be empty.')
+ if self.short_name and len(self.short_name) > 5:
+ raise ValidationError('Short name cannot exceed 5 characters.')
+ if self.description and len(self.description) > 255:
+ raise ValidationError('Description cannot exceed 255 characters.')
+
class CompanyModel(NomenclatureBaseModel):
- class Meta:
- app_label = 'common'
+ def clean(self):
+ super().clean()
+ if CompanyModel.objects.filter(name=self.name, active=True).exclude(id=self.id).exists():
+ raise ValidationError(f'Company with name {self.name} already exists and is active.')
+ if CompanyModel.objects.filter(short_name=self.short_name, active=True).exclude(id=self.id).exists():
+ raise ValidationError(f'Company with short name {self.short_name} already exists and is active.')
class LinesModel(NomenclatureBaseModel):
@@ -26,8 +43,13 @@ class LinesModel(NomenclatureBaseModel):
related_name='line_company'
)
- class Meta:
- app_label = 'common'
+ def clean(self):
+ super().clean()
+ if LinesModel.objects.filter(name=self.name, active=True).exclude(id=self.id).exists():
+ raise ValidationError(f'Line with name {self.name} already exists and is active.')
+ if LinesModel.objects.filter(short_name=self.short_name, active=True).exclude(id=self.id).exists():
+ raise ValidationError(f'Line with short name {self.short_name} already exists and is active.')
+
class OperationModel(NomenclatureBaseModel):
...
@@ -50,4 +72,4 @@ class ContainerTypeModel(models.Model):
app_label = 'common'
def __str__(self):
- return self.name
\ No newline at end of file
+ return self.name
diff --git a/common/templatetags/__pycache__/__init__.cpython-313.pyc b/common/templatetags/__pycache__/__init__.cpython-313.pyc
index d5024c3..5429b45 100644
Binary files a/common/templatetags/__pycache__/__init__.cpython-313.pyc and b/common/templatetags/__pycache__/__init__.cpython-313.pyc differ
diff --git a/common/templatetags/__pycache__/filters.cpython-313.pyc b/common/templatetags/__pycache__/filters.cpython-313.pyc
index de0fbb3..43996d7 100644
Binary files a/common/templatetags/__pycache__/filters.cpython-313.pyc and b/common/templatetags/__pycache__/filters.cpython-313.pyc differ
diff --git a/common/utils/__pycache__/minio_utils.cpython-313.pyc b/common/utils/__pycache__/minio_utils.cpython-313.pyc
index ecd3702..91b4067 100644
Binary files a/common/utils/__pycache__/minio_utils.cpython-313.pyc and b/common/utils/__pycache__/minio_utils.cpython-313.pyc differ
diff --git a/common/utils/__pycache__/owncloud_utls.cpython-313.pyc b/common/utils/__pycache__/owncloud_utls.cpython-313.pyc
index 6590825..9721350 100644
Binary files a/common/utils/__pycache__/owncloud_utls.cpython-313.pyc and b/common/utils/__pycache__/owncloud_utls.cpython-313.pyc differ
diff --git a/common/utils/__pycache__/utils.cpython-313.pyc b/common/utils/__pycache__/utils.cpython-313.pyc
index 761988d..52591cf 100644
Binary files a/common/utils/__pycache__/utils.cpython-313.pyc and b/common/utils/__pycache__/utils.cpython-313.pyc differ
diff --git a/common/views/__pycache__/__init__.cpython-313.pyc b/common/views/__pycache__/__init__.cpython-313.pyc
index fe54f39..a3c3f12 100644
Binary files a/common/views/__pycache__/__init__.cpython-313.pyc and b/common/views/__pycache__/__init__.cpython-313.pyc differ
diff --git a/common/views/__pycache__/barrier_views.cpython-313.pyc b/common/views/__pycache__/barrier_views.cpython-313.pyc
index 3f7757c..cf111d4 100644
Binary files a/common/views/__pycache__/barrier_views.cpython-313.pyc and b/common/views/__pycache__/barrier_views.cpython-313.pyc differ
diff --git a/common/views/__pycache__/client_views.cpython-313.pyc b/common/views/__pycache__/client_views.cpython-313.pyc
index 1ba8af3..d51d0fe 100644
Binary files a/common/views/__pycache__/client_views.cpython-313.pyc and b/common/views/__pycache__/client_views.cpython-313.pyc differ
diff --git a/common/views/__pycache__/employee_views.cpython-313.pyc b/common/views/__pycache__/employee_views.cpython-313.pyc
index 8bc5977..772079a 100644
Binary files a/common/views/__pycache__/employee_views.cpython-313.pyc and b/common/views/__pycache__/employee_views.cpython-313.pyc differ
diff --git a/common/views/__pycache__/shared_views.cpython-313.pyc b/common/views/__pycache__/shared_views.cpython-313.pyc
index 5629e80..a8dd774 100644
Binary files a/common/views/__pycache__/shared_views.cpython-313.pyc and b/common/views/__pycache__/shared_views.cpython-313.pyc differ
diff --git a/common_api/__pycache__/__init__.cpython-313.pyc b/common_api/__pycache__/__init__.cpython-313.pyc
index 7c3e9ef..8be5662 100644
Binary files a/common_api/__pycache__/__init__.cpython-313.pyc and b/common_api/__pycache__/__init__.cpython-313.pyc differ
diff --git a/common_api/__pycache__/urls.cpython-313.pyc b/common_api/__pycache__/urls.cpython-313.pyc
index 552af24..484f76a 100644
Binary files a/common_api/__pycache__/urls.cpython-313.pyc and b/common_api/__pycache__/urls.cpython-313.pyc differ
diff --git a/common_api/__pycache__/views.cpython-313.pyc b/common_api/__pycache__/views.cpython-313.pyc
index 71ddd82..573f818 100644
Binary files a/common_api/__pycache__/views.cpython-313.pyc and b/common_api/__pycache__/views.cpython-313.pyc differ
diff --git a/containers/__pycache__/__init__.cpython-313.pyc b/containers/__pycache__/__init__.cpython-313.pyc
index 80ca216..6d172a2 100644
Binary files a/containers/__pycache__/__init__.cpython-313.pyc and b/containers/__pycache__/__init__.cpython-313.pyc differ
diff --git a/containers/__pycache__/admin.cpython-313.pyc b/containers/__pycache__/admin.cpython-313.pyc
index 52c00b4..290999e 100644
Binary files a/containers/__pycache__/admin.cpython-313.pyc and b/containers/__pycache__/admin.cpython-313.pyc differ
diff --git a/containers/__pycache__/apps.cpython-313.pyc b/containers/__pycache__/apps.cpython-313.pyc
index b2d0509..4625c2d 100644
Binary files a/containers/__pycache__/apps.cpython-313.pyc and b/containers/__pycache__/apps.cpython-313.pyc differ
diff --git a/containers/__pycache__/forms.cpython-313.pyc b/containers/__pycache__/forms.cpython-313.pyc
index 3034dd8..779ba78 100644
Binary files a/containers/__pycache__/forms.cpython-313.pyc and b/containers/__pycache__/forms.cpython-313.pyc differ
diff --git a/containers/__pycache__/models.cpython-313.pyc b/containers/__pycache__/models.cpython-313.pyc
index 7e77edc..2f163fd 100644
Binary files a/containers/__pycache__/models.cpython-313.pyc and b/containers/__pycache__/models.cpython-313.pyc differ
diff --git a/containers/__pycache__/services.cpython-313.pyc b/containers/__pycache__/services.cpython-313.pyc
index 1809b7e..cd7b799 100644
Binary files a/containers/__pycache__/services.cpython-313.pyc and b/containers/__pycache__/services.cpython-313.pyc differ
diff --git a/containers/__pycache__/urls.cpython-313.pyc b/containers/__pycache__/urls.cpython-313.pyc
index 381bcf5..ee962a3 100644
Binary files a/containers/__pycache__/urls.cpython-313.pyc and b/containers/__pycache__/urls.cpython-313.pyc differ
diff --git a/containers/migrations/__pycache__/0001_initial.cpython-313.pyc b/containers/migrations/__pycache__/0001_initial.cpython-313.pyc
index 8bdef26..33e6da3 100644
Binary files a/containers/migrations/__pycache__/0001_initial.cpython-313.pyc and b/containers/migrations/__pycache__/0001_initial.cpython-313.pyc differ
diff --git a/containers/migrations/__pycache__/0002_rename_receive_vehicles_container_receive_vehicle.cpython-313.pyc b/containers/migrations/__pycache__/0002_rename_receive_vehicles_container_receive_vehicle.cpython-313.pyc
index 079bb57..c2834fb 100644
Binary files a/containers/migrations/__pycache__/0002_rename_receive_vehicles_container_receive_vehicle.cpython-313.pyc and b/containers/migrations/__pycache__/0002_rename_receive_vehicles_container_receive_vehicle.cpython-313.pyc differ
diff --git a/containers/migrations/__pycache__/0003_alter_container_booking.cpython-313.pyc b/containers/migrations/__pycache__/0003_alter_container_booking.cpython-313.pyc
index 1fe924f..f3f0220 100644
Binary files a/containers/migrations/__pycache__/0003_alter_container_booking.cpython-313.pyc and b/containers/migrations/__pycache__/0003_alter_container_booking.cpython-313.pyc differ
diff --git a/containers/migrations/__pycache__/0004_rename_line_id_container_line.cpython-313.pyc b/containers/migrations/__pycache__/0004_rename_line_id_container_line.cpython-313.pyc
index 33979ef..3132dd4 100644
Binary files a/containers/migrations/__pycache__/0004_rename_line_id_container_line.cpython-313.pyc and b/containers/migrations/__pycache__/0004_rename_line_id_container_line.cpython-313.pyc differ
diff --git a/containers/migrations/__pycache__/0005_alter_container_expedited_by_and_more.cpython-313.pyc b/containers/migrations/__pycache__/0005_alter_container_expedited_by_and_more.cpython-313.pyc
index bcdd77b..8d31741 100644
Binary files a/containers/migrations/__pycache__/0005_alter_container_expedited_by_and_more.cpython-313.pyc and b/containers/migrations/__pycache__/0005_alter_container_expedited_by_and_more.cpython-313.pyc differ
diff --git a/containers/migrations/__pycache__/0006_containerphotos.cpython-313.pyc b/containers/migrations/__pycache__/0006_containerphotos.cpython-313.pyc
index 35f2361..efd2bf5 100644
Binary files a/containers/migrations/__pycache__/0006_containerphotos.cpython-313.pyc and b/containers/migrations/__pycache__/0006_containerphotos.cpython-313.pyc differ
diff --git a/containers/migrations/__pycache__/0007_container_preinfo.cpython-313.pyc b/containers/migrations/__pycache__/0007_container_preinfo.cpython-313.pyc
index 1195971..5ce31c4 100644
Binary files a/containers/migrations/__pycache__/0007_container_preinfo.cpython-313.pyc and b/containers/migrations/__pycache__/0007_container_preinfo.cpython-313.pyc differ
diff --git a/containers/migrations/__pycache__/__init__.cpython-313.pyc b/containers/migrations/__pycache__/__init__.cpython-313.pyc
index 8c8aed6..21f2782 100644
Binary files a/containers/migrations/__pycache__/__init__.cpython-313.pyc and b/containers/migrations/__pycache__/__init__.cpython-313.pyc differ
diff --git a/containers/models.py b/containers/models.py
index d9ec771..756750c 100644
--- a/containers/models.py
+++ b/containers/models.py
@@ -1,11 +1,13 @@
-
+from django.core.exceptions import ValidationError
from django.db import models
+
+from common.fields import ContainerNumberField
from common.models import LinesModel, ContainerTypeModel
# from payments.models import ContainerTariffPeriod, AdditionalFees
# Create your models here.
class Container(models.Model):
- number = models.CharField(max_length=11)
+ number = ContainerNumberField(max_length=11)
line = models.ForeignKey(
LinesModel,
on_delete=models.CASCADE,
@@ -25,7 +27,7 @@ class Container(models.Model):
receive_vehicle = models.CharField(max_length=100, blank=True, null=True)
damages = models.TextField(blank=True, null=True)
heavy_damaged = models.BooleanField(default=False)
- position = models.CharField(max_length=100, blank=True, null=True)
+ position = models.CharField(max_length=7, blank=True, null=True)
swept = models.BooleanField(default=False)
swept_on = models.DateTimeField(blank=True, null=True)
swept_by = models.ForeignKey(
@@ -67,6 +69,11 @@ class Container(models.Model):
)
expedition_vehicle = models.CharField(max_length=100, blank=True, null=True)
+ def clean(self):
+ if Container.objects.filter(number=self.number, expedited=False).exclude(id=self.id).exists():
+ raise ValidationError(f'Container with number {self.number} already exists in the depot.!')
+ if self.heavy_damaged and not self.damages.strip():
+ raise ValidationError('Heavy damaged containers must have damages specified.')
class ContainerHistory(Container):
diff --git a/containers/views/__pycache__/__init__.cpython-313.pyc b/containers/views/__pycache__/__init__.cpython-313.pyc
index 81c3ad7..b0d9888 100644
Binary files a/containers/views/__pycache__/__init__.cpython-313.pyc and b/containers/views/__pycache__/__init__.cpython-313.pyc differ
diff --git a/containers/views/__pycache__/barrier_views.cpython-313.pyc b/containers/views/__pycache__/barrier_views.cpython-313.pyc
index a147db5..da17cd6 100644
Binary files a/containers/views/__pycache__/barrier_views.cpython-313.pyc and b/containers/views/__pycache__/barrier_views.cpython-313.pyc differ
diff --git a/containers/views/__pycache__/client_views.cpython-313.pyc b/containers/views/__pycache__/client_views.cpython-313.pyc
index 52931ae..8cea080 100644
Binary files a/containers/views/__pycache__/client_views.cpython-313.pyc and b/containers/views/__pycache__/client_views.cpython-313.pyc differ
diff --git a/containers/views/__pycache__/common.cpython-313.pyc b/containers/views/__pycache__/common.cpython-313.pyc
index 3ffc94c..d8aa6e2 100644
Binary files a/containers/views/__pycache__/common.cpython-313.pyc and b/containers/views/__pycache__/common.cpython-313.pyc differ
diff --git a/containers/views/__pycache__/employee_views.cpython-313.pyc b/containers/views/__pycache__/employee_views.cpython-313.pyc
index f378628..367eb49 100644
Binary files a/containers/views/__pycache__/employee_views.cpython-313.pyc and b/containers/views/__pycache__/employee_views.cpython-313.pyc differ
diff --git a/damages_api/__pycache__/__init__.cpython-313.pyc b/damages_api/__pycache__/__init__.cpython-313.pyc
index cf94aa9..5dc9c64 100644
Binary files a/damages_api/__pycache__/__init__.cpython-313.pyc and b/damages_api/__pycache__/__init__.cpython-313.pyc differ
diff --git a/damages_api/__pycache__/admin.cpython-313.pyc b/damages_api/__pycache__/admin.cpython-313.pyc
index f95bfdd..b086864 100644
Binary files a/damages_api/__pycache__/admin.cpython-313.pyc and b/damages_api/__pycache__/admin.cpython-313.pyc differ
diff --git a/damages_api/__pycache__/apps.cpython-313.pyc b/damages_api/__pycache__/apps.cpython-313.pyc
index 59f2edd..bd32c0b 100644
Binary files a/damages_api/__pycache__/apps.cpython-313.pyc and b/damages_api/__pycache__/apps.cpython-313.pyc differ
diff --git a/damages_api/__pycache__/models.cpython-313.pyc b/damages_api/__pycache__/models.cpython-313.pyc
index 7a3cda6..144d84a 100644
Binary files a/damages_api/__pycache__/models.cpython-313.pyc and b/damages_api/__pycache__/models.cpython-313.pyc differ
diff --git a/damages_api/__pycache__/urls.cpython-313.pyc b/damages_api/__pycache__/urls.cpython-313.pyc
index fee1a28..4b949c8 100644
Binary files a/damages_api/__pycache__/urls.cpython-313.pyc and b/damages_api/__pycache__/urls.cpython-313.pyc differ
diff --git a/damages_api/__pycache__/views.cpython-313.pyc b/damages_api/__pycache__/views.cpython-313.pyc
index 0e58dca..4b95b87 100644
Binary files a/damages_api/__pycache__/views.cpython-313.pyc and b/damages_api/__pycache__/views.cpython-313.pyc differ
diff --git a/damages_api/migrations/__pycache__/__init__.cpython-313.pyc b/damages_api/migrations/__pycache__/__init__.cpython-313.pyc
index 3e2edab..a6a6135 100644
Binary files a/damages_api/migrations/__pycache__/__init__.cpython-313.pyc and b/damages_api/migrations/__pycache__/__init__.cpython-313.pyc differ
diff --git a/payments/__pycache__/__init__.cpython-313.pyc b/payments/__pycache__/__init__.cpython-313.pyc
index 4af532d..4cb73b7 100644
Binary files a/payments/__pycache__/__init__.cpython-313.pyc and b/payments/__pycache__/__init__.cpython-313.pyc differ
diff --git a/payments/__pycache__/admin.cpython-313.pyc b/payments/__pycache__/admin.cpython-313.pyc
index d13991b..28cff1a 100644
Binary files a/payments/__pycache__/admin.cpython-313.pyc and b/payments/__pycache__/admin.cpython-313.pyc differ
diff --git a/payments/__pycache__/apps.cpython-313.pyc b/payments/__pycache__/apps.cpython-313.pyc
index 63cf9ff..90546cf 100644
Binary files a/payments/__pycache__/apps.cpython-313.pyc and b/payments/__pycache__/apps.cpython-313.pyc differ
diff --git a/payments/__pycache__/forms.cpython-313.pyc b/payments/__pycache__/forms.cpython-313.pyc
index f774587..b78f0eb 100644
Binary files a/payments/__pycache__/forms.cpython-313.pyc and b/payments/__pycache__/forms.cpython-313.pyc differ
diff --git a/payments/__pycache__/models.cpython-313.pyc b/payments/__pycache__/models.cpython-313.pyc
index eaecd95..7d3f5e6 100644
Binary files a/payments/__pycache__/models.cpython-313.pyc and b/payments/__pycache__/models.cpython-313.pyc differ
diff --git a/payments/__pycache__/services.cpython-313.pyc b/payments/__pycache__/services.cpython-313.pyc
index 6dcf0d6..fa3deb8 100644
Binary files a/payments/__pycache__/services.cpython-313.pyc and b/payments/__pycache__/services.cpython-313.pyc differ
diff --git a/payments/__pycache__/urls.cpython-313.pyc b/payments/__pycache__/urls.cpython-313.pyc
index 1490b36..ed5c123 100644
Binary files a/payments/__pycache__/urls.cpython-313.pyc and b/payments/__pycache__/urls.cpython-313.pyc differ
diff --git a/payments/__pycache__/utils.cpython-313.pyc b/payments/__pycache__/utils.cpython-313.pyc
index d6362e8..c6842ff 100644
Binary files a/payments/__pycache__/utils.cpython-313.pyc and b/payments/__pycache__/utils.cpython-313.pyc differ
diff --git a/payments/__pycache__/views.cpython-313.pyc b/payments/__pycache__/views.cpython-313.pyc
index 807352b..516959d 100644
Binary files a/payments/__pycache__/views.cpython-313.pyc and b/payments/__pycache__/views.cpython-313.pyc differ
diff --git a/payments/migrations/__pycache__/0001_initial.cpython-313.pyc b/payments/migrations/__pycache__/0001_initial.cpython-313.pyc
index 4abae97..f5282af 100644
Binary files a/payments/migrations/__pycache__/0001_initial.cpython-313.pyc and b/payments/migrations/__pycache__/0001_initial.cpython-313.pyc differ
diff --git a/payments/migrations/__pycache__/0002_additionalfees_containertariffperiod.cpython-313.pyc b/payments/migrations/__pycache__/0002_additionalfees_containertariffperiod.cpython-313.pyc
index e67c39d..56a2e83 100644
Binary files a/payments/migrations/__pycache__/0002_additionalfees_containertariffperiod.cpython-313.pyc and b/payments/migrations/__pycache__/0002_additionalfees_containertariffperiod.cpython-313.pyc differ
diff --git a/payments/migrations/__pycache__/0003_auto_20250725_1920.cpython-313.pyc b/payments/migrations/__pycache__/0003_auto_20250725_1920.cpython-313.pyc
index 81f83b5..40d8e76 100644
Binary files a/payments/migrations/__pycache__/0003_auto_20250725_1920.cpython-313.pyc and b/payments/migrations/__pycache__/0003_auto_20250725_1920.cpython-313.pyc differ
diff --git a/payments/migrations/__pycache__/0004_populate_tariffs.cpython-313.pyc b/payments/migrations/__pycache__/0004_populate_tariffs.cpython-313.pyc
index 5af0e9a..870f228 100644
Binary files a/payments/migrations/__pycache__/0004_populate_tariffs.cpython-313.pyc and b/payments/migrations/__pycache__/0004_populate_tariffs.cpython-313.pyc differ
diff --git a/payments/migrations/__pycache__/__init__.cpython-313.pyc b/payments/migrations/__pycache__/__init__.cpython-313.pyc
index e77341d..7d953b9 100644
Binary files a/payments/migrations/__pycache__/__init__.cpython-313.pyc and b/payments/migrations/__pycache__/__init__.cpython-313.pyc differ
diff --git a/payments/models.py b/payments/models.py
index 31ddcdf..8cd9bb9 100644
--- a/payments/models.py
+++ b/payments/models.py
@@ -18,6 +18,11 @@ class Payment(models.Model):
paid_info = models.TextField(blank=True, null=True)
description = models.CharField(max_length=255, blank=True, null=True)
+ def clean(self):
+ if Payment.objects.filter(invoice_number=self.invoice_number).exclude(id=self.id).exists():
+ raise ValueError(f'Payment with invoice number {self.invoice_number} already exists.')
+
+
class PaymentItem(models.Model):
payment = models.ForeignKey(Payment, related_name='payment_items', on_delete=models.CASCADE)
container = models.ForeignKey(Container, related_name='payment_containers', on_delete=models.CASCADE)
@@ -47,4 +52,4 @@ class AdditionalFees(models.Model):
class Meta:
verbose_name = 'Additional Fees'
- verbose_name_plural = 'Additional Fees'
\ No newline at end of file
+ verbose_name_plural = 'Additional Fees'
diff --git a/preinfo/__pycache__/__init__.cpython-313.pyc b/preinfo/__pycache__/__init__.cpython-313.pyc
index 407951c..3ec207a 100644
Binary files a/preinfo/__pycache__/__init__.cpython-313.pyc and b/preinfo/__pycache__/__init__.cpython-313.pyc differ
diff --git a/preinfo/__pycache__/admin.cpython-313.pyc b/preinfo/__pycache__/admin.cpython-313.pyc
index f381387..d04e88e 100644
Binary files a/preinfo/__pycache__/admin.cpython-313.pyc and b/preinfo/__pycache__/admin.cpython-313.pyc differ
diff --git a/preinfo/__pycache__/apps.cpython-313.pyc b/preinfo/__pycache__/apps.cpython-313.pyc
index 760bc7b..2ff418c 100644
Binary files a/preinfo/__pycache__/apps.cpython-313.pyc and b/preinfo/__pycache__/apps.cpython-313.pyc differ
diff --git a/preinfo/__pycache__/forms.cpython-313.pyc b/preinfo/__pycache__/forms.cpython-313.pyc
index 287f07d..856031e 100644
Binary files a/preinfo/__pycache__/forms.cpython-313.pyc and b/preinfo/__pycache__/forms.cpython-313.pyc differ
diff --git a/preinfo/__pycache__/models.cpython-313.pyc b/preinfo/__pycache__/models.cpython-313.pyc
index dfd56a0..09e5cfb 100644
Binary files a/preinfo/__pycache__/models.cpython-313.pyc and b/preinfo/__pycache__/models.cpython-313.pyc differ
diff --git a/preinfo/__pycache__/urls.cpython-313.pyc b/preinfo/__pycache__/urls.cpython-313.pyc
index bdc2c02..3a947ce 100644
Binary files a/preinfo/__pycache__/urls.cpython-313.pyc and b/preinfo/__pycache__/urls.cpython-313.pyc differ
diff --git a/preinfo/migrations/__pycache__/0001_initial.cpython-313.pyc b/preinfo/migrations/__pycache__/0001_initial.cpython-313.pyc
index 5d3c1e1..7f4bd7e 100644
Binary files a/preinfo/migrations/__pycache__/0001_initial.cpython-313.pyc and b/preinfo/migrations/__pycache__/0001_initial.cpython-313.pyc differ
diff --git a/preinfo/migrations/__pycache__/0002_alter_preinfomodel_deleted_by_and_more.cpython-313.pyc b/preinfo/migrations/__pycache__/0002_alter_preinfomodel_deleted_by_and_more.cpython-313.pyc
index 2d2d951..b248d72 100644
Binary files a/preinfo/migrations/__pycache__/0002_alter_preinfomodel_deleted_by_and_more.cpython-313.pyc and b/preinfo/migrations/__pycache__/0002_alter_preinfomodel_deleted_by_and_more.cpython-313.pyc differ
diff --git a/preinfo/migrations/__pycache__/0003_rename_preinfomodel_preinfo.cpython-313.pyc b/preinfo/migrations/__pycache__/0003_rename_preinfomodel_preinfo.cpython-313.pyc
index c3d4e6b..623ca81 100644
Binary files a/preinfo/migrations/__pycache__/0003_rename_preinfomodel_preinfo.cpython-313.pyc and b/preinfo/migrations/__pycache__/0003_rename_preinfomodel_preinfo.cpython-313.pyc differ
diff --git a/preinfo/migrations/__pycache__/__init__.cpython-313.pyc b/preinfo/migrations/__pycache__/__init__.cpython-313.pyc
index 591586e..ad15dde 100644
Binary files a/preinfo/migrations/__pycache__/__init__.cpython-313.pyc and b/preinfo/migrations/__pycache__/__init__.cpython-313.pyc differ
diff --git a/preinfo/models.py b/preinfo/models.py
index 03ffb98..383d625 100644
--- a/preinfo/models.py
+++ b/preinfo/models.py
@@ -1,8 +1,12 @@
from django.db import models
+from common.fields import ContainerNumberField
+from containers.models import Container
+
+
# Create your models here.
class Preinfo(models.Model):
- container_number = models.CharField(
+ container_number = ContainerNumberField(
max_length=11,
)
container_type = models.ForeignKey(
@@ -33,3 +37,7 @@ class Preinfo(models.Model):
)
deleted_on = models.DateTimeField(null=True, blank=True)
received = models.BooleanField(default=False, null=False)
+
+ def clean(self):
+ if Container.objects.filter(number=self.container_number, expedited=False).exists():
+ raise ValueError(f'Container with number {self.container_number} is at the depot.')
diff --git a/preinfo/views/__pycache__/__init__.cpython-313.pyc b/preinfo/views/__pycache__/__init__.cpython-313.pyc
index c256524..d98757a 100644
Binary files a/preinfo/views/__pycache__/__init__.cpython-313.pyc and b/preinfo/views/__pycache__/__init__.cpython-313.pyc differ
diff --git a/preinfo/views/__pycache__/client_views.cpython-313.pyc b/preinfo/views/__pycache__/client_views.cpython-313.pyc
index bcf3a86..b3ce880 100644
Binary files a/preinfo/views/__pycache__/client_views.cpython-313.pyc and b/preinfo/views/__pycache__/client_views.cpython-313.pyc differ
diff --git a/preinfo/views/__pycache__/employee_views.cpython-313.pyc b/preinfo/views/__pycache__/employee_views.cpython-313.pyc
index b0fde8d..69609cf 100644
Binary files a/preinfo/views/__pycache__/employee_views.cpython-313.pyc and b/preinfo/views/__pycache__/employee_views.cpython-313.pyc differ