diff --git a/db.sqlite b/db.sqlite index 812c4e9d..c4f3d855 100644 Binary files a/db.sqlite and b/db.sqlite differ diff --git a/inventory/__pycache__/forms.cpython-311.pyc b/inventory/__pycache__/forms.cpython-311.pyc index b133fbc4..d9531abc 100644 Binary files a/inventory/__pycache__/forms.cpython-311.pyc and b/inventory/__pycache__/forms.cpython-311.pyc differ diff --git a/inventory/__pycache__/views.cpython-311.pyc b/inventory/__pycache__/views.cpython-311.pyc index 7f75b0d1..78691ac4 100644 Binary files a/inventory/__pycache__/views.cpython-311.pyc and b/inventory/__pycache__/views.cpython-311.pyc differ diff --git a/inventory/forms.py b/inventory/forms.py index f495b017..8598fd2c 100644 --- a/inventory/forms.py +++ b/inventory/forms.py @@ -40,16 +40,39 @@ class AdditionalServiceForm(forms.ModelForm): model = AdditionalServices fields = ['name', 'price','description','taxable', 'uom'] + class PaymentForm(forms.ModelForm): class Meta: model = Payment fields = ['amount','payment_method', 'reference_number'] + class StaffForm(forms.ModelForm): - email = forms.EmailField(required=True, label="Email") + email = forms.EmailField( + required=True, + label="Email", + widget=forms.EmailInput(attrs={"class": "form-control"}) + ) + class Meta: model = Staff - fields = ['name', 'arabic_name', 'phone_number','staff_type'] + fields = ['name', 'arabic_name', 'phone_number', 'staff_type'] + + def __init__(self, *args, **kwargs): + user_instance = kwargs.get('instance') + if user_instance and user_instance.user: + initial = kwargs.setdefault('initial', {}) + initial['email'] = user_instance.user.email + super().__init__(*args, **kwargs) + + def save(self, commit=True): + staff_instance = super().save(commit=False) + user = staff_instance.user + user.email = self.cleaned_data['email'] + if commit: + user.save() + staff_instance.save() + return staff_instance # Dealer Form @@ -58,6 +81,7 @@ class DealerForm(forms.ModelForm): model = Dealer fields = ['name', 'arabic_name', 'crn', 'vrn', 'phone_number', 'address', 'logo'] + # Customer Form class CustomerForm(forms.ModelForm, AddClassMixin): class Meta: @@ -269,10 +293,6 @@ class CarSelectionTable(tables.Table): template_name = "django_tables2/bootstrap4.html" - - - - class WizardForm1(forms.Form): email = forms.EmailField( @@ -354,6 +374,7 @@ class WizardForm2(forms.Form): } ) + class WizardForm3(forms.Form): # CRN field with max length of 10 crn = forms.CharField( diff --git a/inventory/views.py b/inventory/views.py index 95b4cb24..f9dd7b77 100644 --- a/inventory/views.py +++ b/inventory/views.py @@ -1188,16 +1188,10 @@ class UserUpdateView( permission_required = ("inventory.change_dealer",) success_message = _("User updated successfully.") - - def form_valid(self, form): - user = form.instance.user - for group in user.groups.all(): - group.user_set.remove(user) - Group.objects.get(name=form.cleaned_data["staff_type"].lower()).user_set.add( - user - ) - form.save() - return super().form_valid(form) + def get_form_kwargs(self): + kwargs = super().get_form_kwargs() + kwargs['instance'] = self.get_object() # Pass the Staff instance to the form + return kwargs def UserDeleteview(request, pk): diff --git a/templates/users/user_form.html b/templates/users/user_form.html index 255c4f02..28b4df52 100644 --- a/templates/users/user_form.html +++ b/templates/users/user_form.html @@ -1,39 +1,26 @@ {% extends "base.html" %} -{% load i18n %} -{% load crispy_forms_filters %} +{% load i18n static crispy_forms_filters %} + {% block title %}{% trans "users" %}{% endblock title %} {% block content %} -
- {% if staff.created %} - - {{ _("Edit User") }} - {% else %} - - {{ _("Add User") }} - {% endif %} -
-