This commit is contained in:
2025-07-15 20:57:15 +03:00
parent f6c78a20a3
commit 0ffd79cee9
51 changed files with 1227 additions and 653 deletions
+19
View File
@@ -0,0 +1,19 @@
from django.forms import ModelForm, CheckboxSelectMultiple
from containers.models import Container
from payments.models import Payment
class PaymentCreateForm(ModelForm):
class Meta:
model = Payment
fields = ['total_amount', 'company', 'description']
widgets = {
'containers': CheckboxSelectMultiple(),
}
# def __init__(self, *args, **kwargs):
# super().__init__(*args, **kwargs)
# self.fields['containers'].queryset = Container.objects.all()
# self.fields['containers'].label_from_instance = lambda obj: f"{obj.name} ({obj.company.name})"
+25
View File
@@ -23,3 +23,28 @@ class PaymentItem(models.Model):
container = models.ForeignKey(Container, related_name='payment_containers', on_delete=models.CASCADE)
amount = models.DecimalField(max_digits=10, decimal_places=2)
class ContainerTariffPeriod(models.Model):
CONTAINER_SIZE_CHOICES = [
('20', '20 feet'),
('40', '40/45 feet'),
]
container_size = models.CharField(max_length=2, choices=CONTAINER_SIZE_CHOICES)
from_days = models.PositiveIntegerField()
to_days = models.PositiveIntegerField(null=True, blank=True) # null for last period (16+ days)
daily_rate = models.DecimalField(max_digits=6, decimal_places=2)
class Meta:
unique_together = ['container_size', 'from_days']
ordering = ['container_size', 'from_days']
class AdditionalFees(models.Model):
reefer_daily_supplement = models.DecimalField(max_digits=6, decimal_places=2, default=3.00)
sweeping_fee = models.DecimalField(max_digits=6, decimal_places=2, default=35.00)
fumigation_fee = models.DecimalField(max_digits=6, decimal_places=2, default=75.00)
class Meta:
verbose_name = 'Additional Fees'
verbose_name_plural = 'Additional Fees'
+7
View File
@@ -0,0 +1,7 @@
from django.urls import path
from payments.views import PaymentCreateView
urlpatterns = [
path("create/", PaymentCreateView.as_view(), name="payments_create"),
]
+44
View File
@@ -1,3 +1,47 @@
from django.shortcuts import render
from django.urls import reverse_lazy
from django.views.generic import ListView, CreateView
from common.models import CompanyModel
from containers.models import Container
from payments.forms import PaymentCreateForm
from payments.models import Payment
# Create your views here.
class PaymentCreateView(CreateView):
model = Payment
form_class = PaymentCreateForm
template_name = 'employee/payment-create.html'
success_url = reverse_lazy('payment-list')
def form_valid(self, form):
container_ids = self.request.POST.getlist('containers')
payment = form.save(commit=False)
payment.save()
payment.containers.set(container_ids)
return super().form_valid(form)
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
container_ids = self.request.GET.get('containers', '').split(',')
# Filter only valid IDs (non-empty strings that can be converted to int)
container_ids = [int(id) for id in container_ids if id.strip().isdigit()]
if container_ids:
# Get selected containers
context['containers'] = Container.objects.filter(
id__in=container_ids,
expedited=True,
payment_containers__isnull=True
).order_by('-expedited_on')
return context
def get_form(self, form_class=None):
form = super().get_form(form_class)
company_pk = self.request.GET.get('company', '')
form.fields['company'].initial = company_pk
# container_ids = [int(id) for id in container_ids if id.strip().isdigit()]
# form.fields['containers'].initial = container_ids
return form