mirror of
https://github.com/ae-utbm/sith.git
synced 2025-06-26 21:25:21 +00:00
invoice call form
This commit is contained in:
parent
6608dac4d3
commit
481c46e367
@ -19,6 +19,7 @@ from counter.models import (
|
|||||||
Counter,
|
Counter,
|
||||||
Customer,
|
Customer,
|
||||||
Eticket,
|
Eticket,
|
||||||
|
InvoiceCall,
|
||||||
Product,
|
Product,
|
||||||
Refilling,
|
Refilling,
|
||||||
ReturnableProduct,
|
ReturnableProduct,
|
||||||
@ -373,3 +374,35 @@ class BaseBasketForm(forms.BaseFormSet):
|
|||||||
BasketForm = forms.formset_factory(
|
BasketForm = forms.formset_factory(
|
||||||
ProductForm, formset=BaseBasketForm, absolute_max=None, min_num=1
|
ProductForm, formset=BaseBasketForm, absolute_max=None, min_num=1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class InvoiceCallForm(forms.Form):
|
||||||
|
def __init__(self, *args, month=None, clubs=None, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self.month = month
|
||||||
|
self.clubs = clubs
|
||||||
|
|
||||||
|
for club in self.clubs:
|
||||||
|
field_name = f"club_{club.id}"
|
||||||
|
initial = (
|
||||||
|
InvoiceCall.objects.filter(club=club, month=month)
|
||||||
|
.values_list("is_validated", flat=True)
|
||||||
|
.first()
|
||||||
|
)
|
||||||
|
|
||||||
|
self.fields[field_name] = forms.BooleanField(
|
||||||
|
required=False,
|
||||||
|
initial=initial,
|
||||||
|
)
|
||||||
|
|
||||||
|
def save(self):
|
||||||
|
for club in self.clubs:
|
||||||
|
field_name = f"club_{club.id}"
|
||||||
|
is_validated = self.cleaned_data.get(field_name, False)
|
||||||
|
|
||||||
|
InvoiceCall.objects.update_or_create(
|
||||||
|
month=self.month, club=club, defaults={"is_validated": is_validated}
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_club_name(self, club_id):
|
||||||
|
return f"club_{club_id}"
|
||||||
|
@ -1407,7 +1407,7 @@ class MonthField(models.CharField):
|
|||||||
|
|
||||||
|
|
||||||
class InvoiceCall(models.Model):
|
class InvoiceCall(models.Model):
|
||||||
is_validated = models.BooleanField(verbose_name=_("is validated"))
|
is_validated = models.BooleanField(verbose_name=_("is validated"), default=False)
|
||||||
club = models.ForeignKey(Club, on_delete=models.CASCADE)
|
club = models.ForeignKey(Club, on_delete=models.CASCADE)
|
||||||
month = MonthField(verbose_name=_("invoice date"))
|
month = MonthField(verbose_name=_("invoice date"))
|
||||||
|
|
||||||
|
@ -29,12 +29,12 @@
|
|||||||
<td>{% trans %}Validated{% endtrans %}</td>
|
<td>{% trans %}Validated{% endtrans %}</td>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for i in sums %}
|
{% for data in club_data %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ i['club__name'] }}</td>
|
<td>{{ data.club.name }}</td>
|
||||||
<td>{{"%.2f"|format(i['selling_sum'])}} €</td>
|
<td>{{"%.2f"|format(data.sum)}} €</td>
|
||||||
<td>
|
<td>
|
||||||
<input type="checkbox" name="validate_{{ i['club__name'] }}" {% if validated[i['club__name']] %}checked{% endif %}>
|
{{ form[form.get_club_name(data.club.id)] }}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -21,6 +21,7 @@ from django.utils import timezone
|
|||||||
from django.views.generic import TemplateView
|
from django.views.generic import TemplateView
|
||||||
|
|
||||||
from counter.fields import CurrencyField
|
from counter.fields import CurrencyField
|
||||||
|
from counter.forms import InvoiceCallForm
|
||||||
from counter.models import Club, InvoiceCall, Refilling, Selling
|
from counter.models import Club, InvoiceCall, Refilling, Selling
|
||||||
from counter.views.mixins import CounterAdminMixin, CounterAdminTabsMixin
|
from counter.views.mixins import CounterAdminMixin, CounterAdminTabsMixin
|
||||||
|
|
||||||
@ -87,10 +88,28 @@ class InvoiceCallView(CounterAdminTabsMixin, CounterAdminMixin, TemplateView):
|
|||||||
clubs = Club.objects.filter(name__in=club_names)
|
clubs = Club.objects.filter(name__in=club_names)
|
||||||
|
|
||||||
invoice_calls = InvoiceCall.objects.filter(month=month_str, club__in=clubs)
|
invoice_calls = InvoiceCall.objects.filter(month=month_str, club__in=clubs)
|
||||||
|
|
||||||
invoice_statuses = {ic.club.name: ic.is_validated for ic in invoice_calls}
|
invoice_statuses = {ic.club.name: ic.is_validated for ic in invoice_calls}
|
||||||
|
|
||||||
kwargs["validated"] = invoice_statuses
|
kwargs["form"] = InvoiceCallForm(clubs=clubs, month=month_str)
|
||||||
|
|
||||||
|
kwargs["club_data"] = []
|
||||||
|
for club in clubs:
|
||||||
|
selling_sum = next(
|
||||||
|
(
|
||||||
|
item["selling_sum"]
|
||||||
|
for item in kwargs["sums"]
|
||||||
|
if item["club__name"] == club.name
|
||||||
|
),
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
kwargs["club_data"].append(
|
||||||
|
{
|
||||||
|
"club": club,
|
||||||
|
"sum": selling_sum,
|
||||||
|
"validated": invoice_statuses.get(club.name, False),
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
@ -113,10 +132,9 @@ class InvoiceCallView(CounterAdminTabsMixin, CounterAdminMixin, TemplateView):
|
|||||||
has_selling=True
|
has_selling=True
|
||||||
)
|
)
|
||||||
|
|
||||||
for club in clubs:
|
form = InvoiceCallForm(request.POST, clubs=clubs, month=month_str)
|
||||||
is_checked = f"validate_{club.name}" in request.POST
|
|
||||||
|
if form.is_valid():
|
||||||
|
form.save()
|
||||||
|
|
||||||
InvoiceCall.objects.update_or_create(
|
|
||||||
month=month_str, club=club, defaults={"is_validated": is_checked}
|
|
||||||
)
|
|
||||||
return redirect(f"{request.path}?month={request.POST.get('month', '')}")
|
return redirect(f"{request.path}?month={request.POST.get('month', '')}")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user