mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-06-20 17:41:55 +02:00
🐛 Fix treasury
This commit is contained in:
@ -1,11 +1,10 @@
|
||||
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import datetime
|
||||
|
||||
from crispy_forms.helper import FormHelper
|
||||
from crispy_forms.layout import Submit
|
||||
from django import forms
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from note_kfet.inputs import DatePickerInput, AmountInput
|
||||
|
||||
@ -19,12 +18,13 @@ class InvoiceForm(forms.ModelForm):
|
||||
|
||||
# Django forms don't support date fields. We have to add it manually
|
||||
date = forms.DateField(
|
||||
initial=datetime.date.today,
|
||||
widget=DatePickerInput()
|
||||
initial=timezone.now,
|
||||
widget=DatePickerInput(),
|
||||
)
|
||||
|
||||
def clean_date(self):
|
||||
self.instance.date = self.data.get("date")
|
||||
return self.instance.date
|
||||
|
||||
class Meta:
|
||||
model = Invoice
|
||||
@ -36,7 +36,11 @@ class ProductForm(forms.ModelForm):
|
||||
model = Product
|
||||
fields = '__all__'
|
||||
widgets = {
|
||||
"amount": AmountInput()
|
||||
"amount": AmountInput(
|
||||
attrs={
|
||||
"negative": True,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@ -115,6 +119,12 @@ class LinkTransactionToRemittanceForm(forms.ModelForm):
|
||||
"""
|
||||
Attach a special transaction to a remittance.
|
||||
"""
|
||||
remittance = forms.ModelChoiceField(
|
||||
queryset=Remittance.objects.none(),
|
||||
label=_("Remittance"),
|
||||
empty_label=_("No attached remittance"),
|
||||
required=False,
|
||||
)
|
||||
|
||||
# Since we use a proxy model for special transactions, we add manually the fields related to the transaction
|
||||
last_name = forms.CharField(label=_("Last name"))
|
||||
@ -123,7 +133,7 @@ class LinkTransactionToRemittanceForm(forms.ModelForm):
|
||||
|
||||
bank = forms.Field(label=_("Bank"))
|
||||
|
||||
amount = forms.IntegerField(label=_("Amount"), min_value=0)
|
||||
amount = forms.IntegerField(label=_("Amount"), min_value=0, widget=AmountInput(), disabled=True, required=False)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
@ -133,33 +143,19 @@ class LinkTransactionToRemittanceForm(forms.ModelForm):
|
||||
|
||||
self.fields["remittance"].queryset = Remittance.objects.filter(closed=False)
|
||||
|
||||
def clean_last_name(self):
|
||||
"""
|
||||
Replace the first name in the information of the transaction.
|
||||
"""
|
||||
self.instance.transaction.last_name = self.data.get("last_name")
|
||||
self.instance.transaction.clean()
|
||||
def clean(self):
|
||||
cleaned_data = super().clean()
|
||||
self.instance.transaction.last_name = cleaned_data["last_name"]
|
||||
self.instance.transaction.first_name = cleaned_data["first_name"]
|
||||
self.instance.transaction.bank = cleaned_data["bank"]
|
||||
return cleaned_data
|
||||
|
||||
def clean_first_name(self):
|
||||
def save(self, commit=True):
|
||||
"""
|
||||
Replace the last name in the information of the transaction.
|
||||
Save the transaction and the remittance.
|
||||
"""
|
||||
self.instance.transaction.first_name = self.data.get("first_name")
|
||||
self.instance.transaction.clean()
|
||||
|
||||
def clean_bank(self):
|
||||
"""
|
||||
Replace the bank in the information of the transaction.
|
||||
"""
|
||||
self.instance.transaction.bank = self.data.get("bank")
|
||||
self.instance.transaction.clean()
|
||||
|
||||
def clean_amount(self):
|
||||
"""
|
||||
Replace the amount of the transaction.
|
||||
"""
|
||||
self.instance.transaction.amount = self.data.get("amount")
|
||||
self.instance.transaction.clean()
|
||||
self.instance.transaction.save()
|
||||
return super().save(commit)
|
||||
|
||||
class Meta:
|
||||
model = SpecialTransactionProxy
|
||||
|
@ -82,7 +82,7 @@ class Product(models.Model):
|
||||
verbose_name=_("Designation"),
|
||||
)
|
||||
|
||||
quantity = models.PositiveIntegerField(
|
||||
quantity = models.IntegerField(
|
||||
verbose_name=_("Quantity")
|
||||
)
|
||||
|
||||
|
@ -64,6 +64,7 @@ class RemittanceTable(tables.Table):
|
||||
model = Remittance
|
||||
template_name = 'django_tables2/bootstrap4.html'
|
||||
fields = ('id', 'date', 'remittance_type', 'comment', 'count', 'amount', 'view',)
|
||||
order_by = ('-date',)
|
||||
|
||||
|
||||
class SpecialTransactionTable(tables.Table):
|
||||
@ -100,7 +101,8 @@ class SpecialTransactionTable(tables.Table):
|
||||
}
|
||||
model = SpecialTransaction
|
||||
template_name = 'django_tables2/bootstrap4.html'
|
||||
fields = ('id', 'source', 'destination', 'last_name', 'first_name', 'bank', 'amount', 'reason',)
|
||||
fields = ('created_at', 'source', 'destination', 'last_name', 'first_name', 'bank', 'amount', 'reason',)
|
||||
order_by = ('-created_at',)
|
||||
|
||||
|
||||
class SogeCreditTable(tables.Table):
|
||||
|
@ -238,7 +238,7 @@ class RemittanceListView(LoginRequiredMixin, TemplateView):
|
||||
|
||||
closed_remittances = RemittanceTable(
|
||||
data=Remittance.objects.filter(closed=True).filter(
|
||||
PermissionBackend.filter_queryset(self.request.user, Remittance, "view")).reverse().all(),
|
||||
PermissionBackend.filter_queryset(self.request.user, Remittance, "view")).all(),
|
||||
prefix="closed-remittances-",
|
||||
)
|
||||
closed_remittances.paginate(page=self.request.GET.get("closed-remittances-page", 1), per_page=10)
|
||||
@ -281,8 +281,6 @@ class RemittanceUpdateView(ProtectQuerysetMixin, LoginRequiredMixin, UpdateView)
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
context["table"] = RemittanceTable(data=Remittance.objects.filter(
|
||||
PermissionBackend.filter_queryset(self.request.user, Remittance, "view")).all())
|
||||
data = SpecialTransaction.objects.filter(specialtransactionproxy__remittance=self.object).filter(
|
||||
PermissionBackend.filter_queryset(self.request.user, Remittance, "view")).all()
|
||||
context["special_transactions"] = SpecialTransactionTable(
|
||||
|
Reference in New Issue
Block a user