mirror of
https://github.com/ae-utbm/sith.git
synced 2025-10-19 11:18:29 +00:00
Basic implementation of invoice call validation
This commit is contained in:
committed by
imperosol
parent
453e13d54b
commit
3bcd417ad0
@@ -10,6 +10,7 @@ from django.utils.translation import gettext_lazy as _
|
||||
from django_celery_beat.models import ClockedSchedule
|
||||
from phonenumber_field.widgets import RegionalPhoneNumberWidget
|
||||
|
||||
from club.models import Club
|
||||
from club.widgets.ajax_select import AutoCompleteSelectClub
|
||||
from core.models import User
|
||||
from core.views.forms import (
|
||||
@@ -29,6 +30,7 @@ from counter.models import (
|
||||
Counter,
|
||||
Customer,
|
||||
Eticket,
|
||||
InvoiceCall,
|
||||
Product,
|
||||
Refilling,
|
||||
ReturnableProduct,
|
||||
@@ -478,3 +480,39 @@ class BaseBasketForm(forms.BaseFormSet):
|
||||
BasketForm = forms.formset_factory(
|
||||
BasketProductForm, formset=BaseBasketForm, absolute_max=None, min_num=1
|
||||
)
|
||||
|
||||
|
||||
class InvoiceCallForm(forms.Form):
|
||||
def __init__(self, *args, month, clubs: list[Club] | None = None, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.month = month
|
||||
self.clubs = clubs
|
||||
|
||||
if self.clubs is None:
|
||||
self.clubs = []
|
||||
|
||||
invoices = {
|
||||
i["club_id"]: i["is_validated"]
|
||||
for i in InvoiceCall.objects.filter(
|
||||
club__in=self.clubs, month=self.month
|
||||
).values("club_id", "is_validated")
|
||||
}
|
||||
|
||||
for club in self.clubs:
|
||||
is_validated = invoices.get(club.id, False)
|
||||
|
||||
self.fields[f"club_{club.id}"] = forms.BooleanField(
|
||||
required=False, initial=is_validated
|
||||
)
|
||||
|
||||
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}"
|
||||
|
Reference in New Issue
Block a user