update
@ -4,6 +4,8 @@ from django.core.validators import MinLengthValidator
|
||||
from django.core.validators import RegexValidator
|
||||
from django import forms
|
||||
from django.contrib.auth import get_user_model
|
||||
from phonenumber_field.phonenumber import PhoneNumber
|
||||
|
||||
from .mixins import AddClassMixin
|
||||
from django.forms.models import inlineformset_factory
|
||||
from .models import (
|
||||
@ -29,7 +31,7 @@ from .models import (
|
||||
Opportunity, Priority, Sources,
|
||||
)
|
||||
from django_ledger.models import ItemModel, InvoiceModel
|
||||
from django.forms import ModelMultipleChoiceField, ValidationError
|
||||
from django.forms import ModelMultipleChoiceField, ValidationError, DateInput
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
import django_tables2 as tables
|
||||
from django.forms import formset_factory
|
||||
@ -62,21 +64,21 @@ class StaffForm(forms.ModelForm):
|
||||
model = Staff
|
||||
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):
|
||||
# user_instance = super().save(commit=False)
|
||||
# user = user_instance.user
|
||||
# user.email = self.cleaned_data["email"]
|
||||
# if commit:
|
||||
# user.save()
|
||||
# user_instance.save()
|
||||
# return user_instance
|
||||
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):
|
||||
user_instance = super().save(commit=False)
|
||||
user = user_instance.user
|
||||
user.email = self.cleaned_data["email"]
|
||||
if commit:
|
||||
user.save()
|
||||
user_instance.save()
|
||||
return user_instance
|
||||
|
||||
|
||||
# Dealer Form
|
||||
@ -99,16 +101,23 @@ class CustomerForm(forms.ModelForm, AddClassMixin):
|
||||
class Meta:
|
||||
model = Customer
|
||||
fields = [
|
||||
"title",
|
||||
"first_name",
|
||||
"middle_name",
|
||||
"last_name",
|
||||
"gender",
|
||||
"dob",
|
||||
"email",
|
||||
"national_id",
|
||||
"city",
|
||||
"phone_number",
|
||||
"address",
|
||||
"country"
|
||||
]
|
||||
widgets = {"country": CountrySelectWidget()}
|
||||
widgets = {
|
||||
"phone_number": forms.TextInput(attrs={"class": "phone"}),
|
||||
"dob": forms.DateInput(attrs={"type": "date"}),
|
||||
}
|
||||
|
||||
|
||||
|
||||
class CarForm(
|
||||
|
||||
19
inventory/migrations/0010_customer_staff.py
Normal file
@ -0,0 +1,19 @@
|
||||
# Generated by Django 5.1.4 on 2025-01-09 11:36
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('inventory', '0009_alter_staff_managers'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='customer',
|
||||
name='staff',
|
||||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='customer_staff', to='inventory.staff', verbose_name='Staff'),
|
||||
),
|
||||
]
|
||||
@ -0,0 +1,22 @@
|
||||
# Generated by Django 5.1.4 on 2025-01-09 20:54
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('inventory', '0010_customer_staff'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='customer',
|
||||
name='country',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='customer',
|
||||
name='city',
|
||||
field=models.CharField(blank=True, max_length=255, verbose_name='City'),
|
||||
),
|
||||
]
|
||||
@ -824,6 +824,8 @@ class Customer(models.Model):
|
||||
lead = models.OneToOneField(Lead, on_delete=models.SET_NULL, null=True, blank=True,
|
||||
related_name="converted", verbose_name=_("Lead"))
|
||||
dealer = models.ForeignKey(Dealer, on_delete=models.CASCADE,related_name="customers")
|
||||
staff = models.ForeignKey(Staff, on_delete=models.SET_NULL, null=True, related_name="customer_staff",
|
||||
verbose_name=_("Staff"))
|
||||
title = models.CharField(choices=Title.choices, default=Title.NA, max_length=10, verbose_name=_("Title"))
|
||||
first_name = models.CharField(max_length=50, verbose_name=_("First Name"))
|
||||
middle_name = models.CharField(max_length=50, blank=True, null=True, verbose_name=_("Middle Name"))
|
||||
@ -832,8 +834,8 @@ class Customer(models.Model):
|
||||
dob = models.DateField(verbose_name=_("Date of Birth"))
|
||||
email = models.EmailField(unique=True, verbose_name=_("Email"))
|
||||
national_id = models.CharField(max_length=10, unique=True, verbose_name=_("National ID"))
|
||||
country = CountryField(blank=True, verbose_name=_("Country"))
|
||||
phone_number = PhoneNumberField(region="SA", unique=True, verbose_name=_("Phone Number"))
|
||||
city = models.CharField(max_length=255, blank=True, verbose_name=_("City"))
|
||||
address = models.CharField(max_length=200, blank=True, null=True, verbose_name=_("Address"))
|
||||
created = models.DateTimeField(auto_now_add=True, verbose_name=_("Created"))
|
||||
updated = models.DateTimeField(auto_now=True, verbose_name=_("Updated"))
|
||||
|
||||
BIN
static/.DS_Store
vendored
|
Before Width: | Height: | Size: 4.2 KiB |
|
Before Width: | Height: | Size: 4.7 KiB |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 353 B |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 361 B |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 353 B |
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 362 B |
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 355 B |
|
Before Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 236 B |
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 331 B |
|
Before Width: | Height: | Size: 6.3 KiB After Width: | Height: | Size: 358 B |
|
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 357 B |
|
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 353 B |
|
Before Width: | Height: | Size: 5.0 KiB After Width: | Height: | Size: 370 B |
|
Before Width: | Height: | Size: 9.1 KiB |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 368 B |
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 355 B |
|
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 360 B |
|
Before Width: | Height: | Size: 4.2 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 353 B |
|
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 351 B |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 350 B |
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 352 B |
|
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 359 B |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 358 B |
|
Before Width: | Height: | Size: 9.5 KiB After Width: | Height: | Size: 359 B |
|
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 365 B |
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 351 B |
|
Before Width: | Height: | Size: 28 KiB |
|
Before Width: | Height: | Size: 6.3 KiB After Width: | Height: | Size: 546 B |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 359 B |
|
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 369 B |
|
Before Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 368 B |
|
Before Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 353 B |
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 368 B |
|
Before Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 5.9 KiB After Width: | Height: | Size: 235 B |
|
Before Width: | Height: | Size: 36 KiB |
|
Before Width: | Height: | Size: 7.0 KiB After Width: | Height: | Size: 356 B |
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 351 B |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 324 B |
|
Before Width: | Height: | Size: 8.1 KiB After Width: | Height: | Size: 360 B |
|
Before Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 354 B |
|
Before Width: | Height: | Size: 8.2 KiB After Width: | Height: | Size: 361 B |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 358 B |
|
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 345 B |
|
Before Width: | Height: | Size: 33 KiB |
|
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 351 B |
|
Before Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 9.7 KiB |
|
Before Width: | Height: | Size: 9.2 KiB After Width: | Height: | Size: 359 B |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 359 B |
|
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 308 B |
|
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 357 B |
|
Before Width: | Height: | Size: 7.0 KiB |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 361 B |
|
Before Width: | Height: | Size: 23 KiB After Width: | Height: | Size: 354 B |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 36 KiB |
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 354 B |
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 356 B |
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 355 B |
|
Before Width: | Height: | Size: 4.3 KiB |
|
Before Width: | Height: | Size: 14 KiB |
|
Before Width: | Height: | Size: 4.2 KiB |
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 353 B |
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 352 B |
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 356 B |
|
Before Width: | Height: | Size: 9.5 KiB |
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 363 B |
|
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 362 B |
|
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 364 B |
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 369 B |
|
Before Width: | Height: | Size: 7.0 KiB After Width: | Height: | Size: 362 B |
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 5.0 KiB After Width: | Height: | Size: 358 B |
|
Before Width: | Height: | Size: 5.0 KiB |
|
Before Width: | Height: | Size: 4.9 KiB After Width: | Height: | Size: 351 B |
|
Before Width: | Height: | Size: 4.6 KiB After Width: | Height: | Size: 252 B |
|
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 546 B |
|
Before Width: | Height: | Size: 8.1 KiB After Width: | Height: | Size: 350 B |
|
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 362 B |
|
Before Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 360 B |
|
Before Width: | Height: | Size: 5.3 KiB After Width: | Height: | Size: 354 B |
|
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 353 B |