huge fix
This commit is contained in:
parent
810c87e2e0
commit
b5bf3a5dbe
51 changed files with 2397 additions and 326 deletions
|
|
@ -16,6 +16,8 @@ class ProfileAdmin(admin.ModelAdmin):
|
|||
list_display = [
|
||||
"user",
|
||||
"fullname",
|
||||
"user_type_display",
|
||||
"company_name",
|
||||
"pic_tag",
|
||||
"roles_str",
|
||||
"affairs",
|
||||
|
|
@ -25,8 +27,52 @@ class ProfileAdmin(admin.ModelAdmin):
|
|||
"is_active",
|
||||
"jcreated",
|
||||
]
|
||||
search_fields = ['user__username', 'user__first_name', 'user__last_name', 'user__phone_number']
|
||||
list_filter = ['user', 'roles', 'affairs', 'county', 'broker']
|
||||
search_fields = [
|
||||
'user__username',
|
||||
'user__first_name',
|
||||
'user__last_name',
|
||||
'user__phone_number',
|
||||
'company_name',
|
||||
'company_national_id',
|
||||
'national_code'
|
||||
]
|
||||
list_filter = [
|
||||
'user_type',
|
||||
'user',
|
||||
'roles',
|
||||
'affairs',
|
||||
'county',
|
||||
'broker',
|
||||
'is_completed',
|
||||
'is_active'
|
||||
]
|
||||
fieldsets = (
|
||||
('اطلاعات کاربری', {
|
||||
'fields': ('user', 'user_type', 'pic', 'roles')
|
||||
}),
|
||||
('اطلاعات شخصی - حقیقی', {
|
||||
'fields': ('national_code', 'address', 'phone_number_1', 'phone_number_2'),
|
||||
'classes': ('collapse',),
|
||||
}),
|
||||
('اطلاعات شرکت - حقوقی', {
|
||||
'fields': ('company_name', 'company_national_id'),
|
||||
'classes': ('collapse',),
|
||||
}),
|
||||
('اطلاعات بانکی', {
|
||||
'fields': ('card_number', 'account_number', 'bank_name'),
|
||||
'classes': ('collapse',),
|
||||
}),
|
||||
('اطلاعات سازمانی', {
|
||||
'fields': ('affairs', 'county', 'broker', 'owner'),
|
||||
}),
|
||||
('وضعیت', {
|
||||
'fields': ('is_completed', 'is_active'),
|
||||
}),
|
||||
('تاریخها', {
|
||||
'fields': ('created', 'updated'),
|
||||
'classes': ('collapse',),
|
||||
}),
|
||||
)
|
||||
date_hierarchy = 'created'
|
||||
ordering = ['-created']
|
||||
readonly_fields = ['created', 'updated']
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ from django import forms
|
|||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.forms import UserCreationForm
|
||||
from .models import Profile, Role
|
||||
from common.consts import UserRoles
|
||||
from common.consts import UserRoles, USER_TYPE_CHOICES
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
|
|
@ -28,10 +28,15 @@ class CustomerForm(forms.ModelForm):
|
|||
class Meta:
|
||||
model = Profile
|
||||
fields = [
|
||||
'phone_number_1', 'phone_number_2', 'national_code',
|
||||
'user_type', 'phone_number_1', 'phone_number_2', 'national_code',
|
||||
'company_name', 'company_national_id',
|
||||
'address', 'card_number', 'account_number', 'bank_name'
|
||||
]
|
||||
widgets = {
|
||||
'user_type': forms.Select(attrs={
|
||||
'class': 'form-control',
|
||||
'id': 'user-type-select'
|
||||
}),
|
||||
'phone_number_1': forms.TextInput(attrs={
|
||||
'class': 'form-control',
|
||||
'placeholder': '09123456789'
|
||||
|
|
@ -46,6 +51,15 @@ class CustomerForm(forms.ModelForm):
|
|||
'maxlength': '10',
|
||||
'required': 'required'
|
||||
}),
|
||||
'company_name': forms.TextInput(attrs={
|
||||
'class': 'form-control company-field',
|
||||
'placeholder': 'نام شرکت'
|
||||
}),
|
||||
'company_national_id': forms.TextInput(attrs={
|
||||
'class': 'form-control company-field',
|
||||
'placeholder': 'شناسه ملی شرکت',
|
||||
'maxlength': '11'
|
||||
}),
|
||||
'address': forms.Textarea(attrs={
|
||||
'class': 'form-control',
|
||||
'placeholder': 'آدرس کامل',
|
||||
|
|
@ -67,9 +81,12 @@ class CustomerForm(forms.ModelForm):
|
|||
}),
|
||||
}
|
||||
labels = {
|
||||
'user_type': 'نوع کاربر',
|
||||
'phone_number_1': 'تلفن ۱',
|
||||
'phone_number_2': 'تلفن ۲',
|
||||
'national_code': 'کد ملی',
|
||||
'company_name': 'نام شرکت',
|
||||
'company_national_id': 'شناسه ملی شرکت',
|
||||
'address': 'آدرس',
|
||||
'card_number': 'شماره کارت',
|
||||
'account_number': 'شماره حساب',
|
||||
|
|
@ -89,6 +106,21 @@ class CustomerForm(forms.ModelForm):
|
|||
raise forms.ValidationError('این کد ملی قبلاً استفاده شده است.')
|
||||
return national_code
|
||||
|
||||
def clean(self):
|
||||
cleaned_data = super().clean()
|
||||
user_type = cleaned_data.get('user_type')
|
||||
company_name = cleaned_data.get('company_name')
|
||||
company_national_id = cleaned_data.get('company_national_id')
|
||||
|
||||
# If user type is legal, company fields are required
|
||||
if user_type == 'legal':
|
||||
if not company_name:
|
||||
self.add_error('company_name', 'برای کاربران حقوقی نام شرکت الزامی است.')
|
||||
if not company_national_id:
|
||||
self.add_error('company_national_id', 'برای کاربران حقوقی شناسه ملی شرکت الزامی است.')
|
||||
|
||||
return cleaned_data
|
||||
|
||||
def save(self, commit=True):
|
||||
def _compute_completed(cleaned):
|
||||
try:
|
||||
|
|
@ -100,7 +132,15 @@ class CustomerForm(forms.ModelForm):
|
|||
bank_ok = bool(cleaned.get('bank_name'))
|
||||
card_ok = bool((cleaned.get('card_number') or '').strip())
|
||||
acc_ok = bool((cleaned.get('account_number') or '').strip())
|
||||
return all([first_ok, last_ok, nc_ok, phone_ok, addr_ok, bank_ok, card_ok, acc_ok])
|
||||
|
||||
# Check user type specific requirements
|
||||
user_type = cleaned.get('user_type', 'individual')
|
||||
if user_type == 'legal':
|
||||
company_name_ok = bool((cleaned.get('company_name') or '').strip())
|
||||
company_id_ok = bool((cleaned.get('company_national_id') or '').strip())
|
||||
return all([first_ok, last_ok, nc_ok, phone_ok, addr_ok, bank_ok, card_ok, acc_ok, company_name_ok, company_id_ok])
|
||||
else:
|
||||
return all([first_ok, last_ok, nc_ok, phone_ok, addr_ok, bank_ok, card_ok, acc_ok])
|
||||
except Exception:
|
||||
return False
|
||||
# Check if this is an update (instance exists)
|
||||
|
|
@ -125,9 +165,12 @@ class CustomerForm(forms.ModelForm):
|
|||
profile.is_completed = _compute_completed({
|
||||
'first_name': user.first_name,
|
||||
'last_name': user.last_name,
|
||||
'user_type': self.cleaned_data.get('user_type'),
|
||||
'national_code': self.cleaned_data.get('national_code'),
|
||||
'phone_number_1': self.cleaned_data.get('phone_number_1'),
|
||||
'phone_number_2': self.cleaned_data.get('phone_number_2'),
|
||||
'company_name': self.cleaned_data.get('company_name'),
|
||||
'company_national_id': self.cleaned_data.get('company_national_id'),
|
||||
'address': self.cleaned_data.get('address'),
|
||||
'bank_name': self.cleaned_data.get('bank_name'),
|
||||
'card_number': self.cleaned_data.get('card_number'),
|
||||
|
|
@ -171,9 +214,12 @@ class CustomerForm(forms.ModelForm):
|
|||
profile.is_completed = _compute_completed({
|
||||
'first_name': user.first_name,
|
||||
'last_name': user.last_name,
|
||||
'user_type': self.cleaned_data.get('user_type'),
|
||||
'national_code': self.cleaned_data.get('national_code'),
|
||||
'phone_number_1': self.cleaned_data.get('phone_number_1'),
|
||||
'phone_number_2': self.cleaned_data.get('phone_number_2'),
|
||||
'company_name': self.cleaned_data.get('company_name'),
|
||||
'company_national_id': self.cleaned_data.get('company_national_id'),
|
||||
'address': self.cleaned_data.get('address'),
|
||||
'bank_name': self.cleaned_data.get('bank_name'),
|
||||
'card_number': self.cleaned_data.get('card_number'),
|
||||
|
|
|
|||
|
|
@ -0,0 +1,44 @@
|
|||
# Generated by Django 5.2.4 on 2025-09-21 07:37
|
||||
|
||||
import django.core.validators
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('accounts', '0006_company_card_holder_name'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='historicalprofile',
|
||||
name='company_name',
|
||||
field=models.CharField(blank=True, help_text='فقط برای کاربران حقوقی الزامی است', max_length=255, null=True, verbose_name='نام شرکت'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='historicalprofile',
|
||||
name='company_national_id',
|
||||
field=models.CharField(blank=True, help_text='فقط برای کاربران حقوقی الزامی است', max_length=11, null=True, validators=[django.core.validators.RegexValidator(code='invalid_company_national_id', message='شناسه ملی باید فقط شامل اعداد باشد.', regex='^\\d+$')], verbose_name='شناسه ملی شرکت'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='historicalprofile',
|
||||
name='user_type',
|
||||
field=models.CharField(choices=[('individual', 'حقیقی'), ('legal', 'حقوقی')], default='individual', max_length=20, verbose_name='نوع کاربر'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='profile',
|
||||
name='company_name',
|
||||
field=models.CharField(blank=True, help_text='فقط برای کاربران حقوقی الزامی است', max_length=255, null=True, verbose_name='نام شرکت'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='profile',
|
||||
name='company_national_id',
|
||||
field=models.CharField(blank=True, help_text='فقط برای کاربران حقوقی الزامی است', max_length=11, null=True, validators=[django.core.validators.RegexValidator(code='invalid_company_national_id', message='شناسه ملی باید فقط شامل اعداد باشد.', regex='^\\d+$')], verbose_name='شناسه ملی شرکت'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='profile',
|
||||
name='user_type',
|
||||
field=models.CharField(choices=[('individual', 'حقیقی'), ('legal', 'حقوقی')], default='individual', max_length=20, verbose_name='نوع کاربر'),
|
||||
),
|
||||
]
|
||||
|
|
@ -4,7 +4,7 @@ from django.utils.html import format_html
|
|||
from django.core.validators import RegexValidator
|
||||
from simple_history.models import HistoricalRecords
|
||||
from common.models import TagModel, BaseModel, NameSlugModel
|
||||
from common.consts import UserRoles, BANK_CHOICES
|
||||
from common.consts import UserRoles, BANK_CHOICES, USER_TYPE_CHOICES
|
||||
from locations.models import Affairs, Broker, County
|
||||
|
||||
|
||||
|
|
@ -88,6 +88,33 @@ class Profile(BaseModel):
|
|||
verbose_name="شماره تماس ۲",
|
||||
blank=True
|
||||
)
|
||||
user_type = models.CharField(
|
||||
max_length=20,
|
||||
choices=USER_TYPE_CHOICES,
|
||||
default='individual',
|
||||
verbose_name="نوع کاربر"
|
||||
)
|
||||
company_national_id = models.CharField(
|
||||
max_length=11,
|
||||
null=True,
|
||||
verbose_name="شناسه ملی شرکت",
|
||||
blank=True,
|
||||
validators=[
|
||||
RegexValidator(
|
||||
regex=r'^\d+$',
|
||||
message='شناسه ملی باید فقط شامل اعداد باشد.',
|
||||
code='invalid_company_national_id'
|
||||
)
|
||||
],
|
||||
help_text="فقط برای کاربران حقوقی الزامی است"
|
||||
)
|
||||
company_name = models.CharField(
|
||||
max_length=255,
|
||||
null=True,
|
||||
verbose_name="نام شرکت",
|
||||
blank=True,
|
||||
help_text="فقط برای کاربران حقوقی الزامی است"
|
||||
)
|
||||
|
||||
pic = models.ImageField(
|
||||
upload_to="profile_images",
|
||||
|
|
@ -179,6 +206,23 @@ class Profile(BaseModel):
|
|||
|
||||
pic_tag.short_description = "تصویر"
|
||||
|
||||
def is_legal_entity(self):
|
||||
return self.user_type == 'legal'
|
||||
|
||||
def is_individual(self):
|
||||
return self.user_type == 'individual'
|
||||
|
||||
def get_display_name(self):
|
||||
"""Returns appropriate display name based on user type"""
|
||||
if self.is_legal_entity() and self.company_name:
|
||||
return self.company_name
|
||||
return self.user.get_full_name() or str(self.user)
|
||||
|
||||
def user_type_display(self):
|
||||
return dict(USER_TYPE_CHOICES).get(self.user_type, self.user_type)
|
||||
|
||||
user_type_display.short_description = "نوع کاربر"
|
||||
|
||||
|
||||
class Company(NameSlugModel):
|
||||
logo = models.ImageField(
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@
|
|||
<tr>
|
||||
<th>ردیف</th>
|
||||
<th>کاربر</th>
|
||||
<th>نوع کاربر</th>
|
||||
<th>کد ملی</th>
|
||||
<th>تلفن</th>
|
||||
<th>آدرس</th>
|
||||
|
|
@ -100,6 +101,27 @@
|
|||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
{% if customer.user_type == 'legal' %}
|
||||
<span class="badge bg-label-info">
|
||||
<i class="bx bx-buildings me-1"></i>حقوقی
|
||||
</span>
|
||||
<div class="mt-1">
|
||||
{% if customer.company_name %}
|
||||
<small class="text-muted d-block">{{ customer.company_name|truncatechars:25 }}</small>
|
||||
{% endif %}
|
||||
{% if customer.company_national_id %}
|
||||
<small class="text-muted d-block">
|
||||
<i class="bx bx-id-card me-1"></i>{{ customer.company_national_id }}
|
||||
</small>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% else %}
|
||||
<span class="badge bg-label-primary">
|
||||
<i class="bx bx-user me-1"></i>حقیقی
|
||||
</span>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>{{ customer.national_code|default:"کد ملی ثبت نشده" }}</td>
|
||||
<td>
|
||||
<div class="d-flex flex-column">
|
||||
|
|
@ -205,6 +227,16 @@
|
|||
<input type="hidden" id="customer-id" name="customer_id" value="">
|
||||
|
||||
<!-- User Information -->
|
||||
<div class="col-sm-12">
|
||||
<label class="form-label fw-bold" for="{{ form.user_type.id_for_label }}">{{ form.user_type.label }}</label>
|
||||
<div class="input-group input-group-merge">
|
||||
<span class="input-group-text"><i class="bx bx-user-circle"></i></span>
|
||||
{{ form.user_type }}
|
||||
</div>
|
||||
{% if form.user_type.errors %}
|
||||
<div class="invalid-feedback d-block">{{ form.user_type.errors.0 }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="col-sm-6">
|
||||
<label class="form-label fw-bold" for="{{ form.first_name.id_for_label }}">{{ form.first_name.label }}</label>
|
||||
|
|
@ -261,6 +293,29 @@
|
|||
{% endif %}
|
||||
</div>
|
||||
|
||||
<!-- Company Information (for legal entities) -->
|
||||
<div class="col-sm-12 company-fields" style="display: none;">
|
||||
<label class="form-label fw-bold" for="{{ form.company_name.id_for_label }}">{{ form.company_name.label }}</label>
|
||||
<div class="input-group input-group-merge">
|
||||
<span class="input-group-text"><i class="bx bx-buildings"></i></span>
|
||||
{{ form.company_name }}
|
||||
</div>
|
||||
{% if form.company_name.errors %}
|
||||
<div class="invalid-feedback d-block">{{ form.company_name.errors.0 }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="col-sm-12 company-fields" style="display: none;">
|
||||
<label class="form-label fw-bold" for="{{ form.company_national_id.id_for_label }}">{{ form.company_national_id.label }}</label>
|
||||
<div class="input-group input-group-merge">
|
||||
<span class="input-group-text"><i class="bx bx-id-card"></i></span>
|
||||
{{ form.company_national_id }}
|
||||
</div>
|
||||
{% if form.company_national_id.errors %}
|
||||
<div class="invalid-feedback d-block">{{ form.company_national_id.errors.0 }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="col-sm-12">
|
||||
<label class="form-label fw-bold" for="{{ form.bank_name.id_for_label }}">{{ form.bank_name.label }}</label>
|
||||
<div class="input-group input-group-merge">
|
||||
|
|
@ -347,6 +402,18 @@
|
|||
<td class="text-muted"><i class="bx bx-fingerprint me-1"></i>کد ملی</td>
|
||||
<td><strong id="cd-national-code">-</strong></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="text-muted"><i class="bx bx-user-circle me-1"></i>نوع کاربر</td>
|
||||
<td><strong id="cd-user-type">-</strong></td>
|
||||
</tr>
|
||||
<tr id="cd-company-name-row" style="display: none;">
|
||||
<td class="text-muted"><i class="bx bx-buildings me-1"></i>نام شرکت</td>
|
||||
<td><strong id="cd-company-name">-</strong></td>
|
||||
</tr>
|
||||
<tr id="cd-company-id-row" style="display: none;">
|
||||
<td class="text-muted"><i class="bx bx-id-card me-1"></i>شناسه ملی شرکت</td>
|
||||
<td><strong id="cd-company-id">-</strong></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="text-muted"><i class="bx bx-phone me-1"></i>شماره تلفن اول</td>
|
||||
<td><strong id="cd-phone1">-</strong></td>
|
||||
|
|
@ -495,6 +562,9 @@
|
|||
lengthMenu: [[10, 25, 50, -1], [10, 25, 50, "همه"]],
|
||||
order: [[0, 'asc']],
|
||||
responsive: true,
|
||||
columnDefs: [
|
||||
{ targets: [8], orderable: false } // عملیات column غیرقابل مرتبسازی
|
||||
]
|
||||
});
|
||||
|
||||
// Handle form submission
|
||||
|
|
@ -603,6 +673,21 @@
|
|||
$('#cd-username').text(c.user.username || '-');
|
||||
$('#cd-fullname').text(c.user.full_name || '-');
|
||||
$('#cd-national-code').text(c.national_code || '-');
|
||||
|
||||
// User type and company information
|
||||
const userTypeDisplay = c.user_type === 'legal' ? 'حقوقی' : 'حقیقی';
|
||||
$('#cd-user-type').text(userTypeDisplay);
|
||||
|
||||
if (c.user_type === 'legal') {
|
||||
$('#cd-company-name').text(c.company_name || '-');
|
||||
$('#cd-company-id').text(c.company_national_id || '-');
|
||||
$('#cd-company-name-row').show();
|
||||
$('#cd-company-id-row').show();
|
||||
} else {
|
||||
$('#cd-company-name-row').hide();
|
||||
$('#cd-company-id-row').hide();
|
||||
}
|
||||
|
||||
$('#cd-phone1').text(c.phone_number_1 || '-');
|
||||
$('#cd-phone2').text(c.phone_number_2 || '-');
|
||||
$('#cd-email').text(c.user.email || '-');
|
||||
|
|
@ -689,9 +774,12 @@
|
|||
'customer-id': customer.id,
|
||||
'id_first_name': customer.first_name,
|
||||
'id_last_name': customer.last_name,
|
||||
'user-type-select': customer.user_type,
|
||||
'id_phone_number_1': customer.phone_number_1,
|
||||
'id_phone_number_2': customer.phone_number_2,
|
||||
'id_national_code': customer.national_code,
|
||||
'id_company_name': customer.company_name,
|
||||
'id_company_national_id': customer.company_national_id,
|
||||
'id_card_number': customer.card_number,
|
||||
'id_account_number': customer.account_number,
|
||||
'id_address': customer.address,
|
||||
|
|
@ -711,6 +799,14 @@
|
|||
if (customer.bank_name !== undefined && customer.bank_name !== null) {
|
||||
$('#id_bank_name').val(customer.bank_name);
|
||||
}
|
||||
|
||||
// Ensure user type is applied and toggle company fields
|
||||
if (customer.user_type !== undefined && customer.user_type !== null) {
|
||||
$('#user-type-select').val(customer.user_type);
|
||||
}
|
||||
|
||||
// Toggle company fields based on user type
|
||||
toggleCompanyFields();
|
||||
|
||||
// Open modal
|
||||
$('#add-new-record').offcanvas('show');
|
||||
|
|
@ -753,8 +849,39 @@
|
|||
$('.is-invalid').removeClass('is-invalid');
|
||||
$('.invalid-feedback').remove();
|
||||
|
||||
// Reset user type to individual and hide company fields
|
||||
$('#user-type-select').val('individual');
|
||||
toggleCompanyFields();
|
||||
|
||||
// Open modal
|
||||
$('#add-new-record').offcanvas('show');
|
||||
}
|
||||
|
||||
function toggleCompanyFields() {
|
||||
const userType = $('#user-type-select').val();
|
||||
const companyFields = $('.company-fields');
|
||||
|
||||
if (userType === 'legal') {
|
||||
companyFields.show();
|
||||
// Make company fields required
|
||||
$('input[name="company_name"]').attr('required', true);
|
||||
$('input[name="company_national_id"]').attr('required', true);
|
||||
} else {
|
||||
companyFields.hide();
|
||||
// Remove required attribute from company fields
|
||||
$('input[name="company_name"]').removeAttr('required').val('');
|
||||
$('input[name="company_national_id"]').removeAttr('required').val('');
|
||||
// Clear any validation errors for company fields
|
||||
$('.company-fields .is-invalid').removeClass('is-invalid');
|
||||
$('.company-fields .invalid-feedback').remove();
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize user type toggle functionality
|
||||
$(document).ready(function() {
|
||||
$('#user-type-select').on('change', toggleCompanyFields);
|
||||
// Initialize on page load
|
||||
toggleCompanyFields();
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
@ -41,7 +41,7 @@ def dashboard(request):
|
|||
|
||||
|
||||
@login_required
|
||||
@allowed_roles([UserRoles.ADMIN, UserRoles.BROKER, UserRoles.MANAGER, UserRoles.ACCOUNTANT])
|
||||
@allowed_roles([UserRoles.ADMIN, UserRoles.BROKER, UserRoles.MANAGER, UserRoles.ACCOUNTANT, UserRoles.WATER_RESOURCE_MANAGER])
|
||||
def customer_list(request):
|
||||
# Get all profiles that have customer role
|
||||
base = Profile.objects.filter(roles__slug=UserRoles.CUSTOMER.value, is_deleted=False).select_related('user')
|
||||
|
|
@ -56,7 +56,7 @@ def customer_list(request):
|
|||
|
||||
@require_POST
|
||||
@login_required
|
||||
@allowed_roles([UserRoles.ADMIN, UserRoles.BROKER, UserRoles.MANAGER, UserRoles.ACCOUNTANT])
|
||||
@allowed_roles([UserRoles.ADMIN, UserRoles.BROKER, UserRoles.MANAGER, UserRoles.ACCOUNTANT, UserRoles.WATER_RESOURCE_MANAGER])
|
||||
def add_customer_ajax(request):
|
||||
"""AJAX endpoint for adding customers"""
|
||||
form = CustomerForm(request.POST, request.FILES)
|
||||
|
|
@ -96,7 +96,7 @@ def add_customer_ajax(request):
|
|||
|
||||
@require_POST
|
||||
@login_required
|
||||
@allowed_roles([UserRoles.ADMIN, UserRoles.BROKER, UserRoles.MANAGER, UserRoles.ACCOUNTANT])
|
||||
@allowed_roles([UserRoles.ADMIN, UserRoles.BROKER, UserRoles.MANAGER, UserRoles.ACCOUNTANT, UserRoles.WATER_RESOURCE_MANAGER])
|
||||
def edit_customer_ajax(request, customer_id):
|
||||
customer = get_object_or_404(Profile, id=customer_id)
|
||||
form = CustomerForm(request.POST, request.FILES, instance=customer)
|
||||
|
|
@ -148,9 +148,12 @@ def get_customer_data(request, customer_id):
|
|||
form_html = {
|
||||
'first_name': str(form['first_name']),
|
||||
'last_name': str(form['last_name']),
|
||||
'user_type': str(form['user_type']),
|
||||
'phone_number_1': str(form['phone_number_1']),
|
||||
'phone_number_2': str(form['phone_number_2']),
|
||||
'national_code': str(form['national_code']),
|
||||
'company_name': str(form['company_name']),
|
||||
'company_national_id': str(form['company_national_id']),
|
||||
'card_number': str(form['card_number']),
|
||||
'account_number': str(form['account_number']),
|
||||
'address': str(form['address']),
|
||||
|
|
@ -163,9 +166,12 @@ def get_customer_data(request, customer_id):
|
|||
'id': customer.id,
|
||||
'first_name': customer.user.first_name,
|
||||
'last_name': customer.user.last_name,
|
||||
'user_type': customer.user_type or 'individual',
|
||||
'phone_number_1': customer.phone_number_1 or '',
|
||||
'phone_number_2': customer.phone_number_2 or '',
|
||||
'national_code': customer.national_code or '',
|
||||
'company_name': customer.company_name or '',
|
||||
'company_national_id': customer.company_national_id or '',
|
||||
'card_number': customer.card_number or '',
|
||||
'account_number': customer.account_number or '',
|
||||
'address': customer.address or '',
|
||||
|
|
@ -177,7 +183,7 @@ def get_customer_data(request, customer_id):
|
|||
|
||||
@require_GET
|
||||
@login_required
|
||||
@allowed_roles([UserRoles.ADMIN, UserRoles.BROKER, UserRoles.MANAGER, UserRoles.ACCOUNTANT])
|
||||
@allowed_roles([UserRoles.ADMIN, UserRoles.BROKER, UserRoles.MANAGER, UserRoles.ACCOUNTANT, UserRoles.WATER_RESOURCE_MANAGER])
|
||||
def get_customer_details(request, customer_id):
|
||||
"""جزئیات کامل مشترک برای نمایش در مدال"""
|
||||
customer = get_object_or_404(
|
||||
|
|
@ -196,6 +202,9 @@ def get_customer_details(request, customer_id):
|
|||
'date_joined': customer.jcreated_date() if customer.user.date_joined else '',
|
||||
},
|
||||
'national_code': customer.national_code or '',
|
||||
'user_type': customer.user_type or 'individual',
|
||||
'company_name': customer.company_name or '',
|
||||
'company_national_id': customer.company_national_id or '',
|
||||
'phone_number_1': customer.phone_number_1 or '',
|
||||
'phone_number_2': customer.phone_number_2 or '',
|
||||
'card_number': customer.card_number or '',
|
||||
|
|
@ -229,7 +238,7 @@ def get_customer_details(request, customer_id):
|
|||
|
||||
@require_GET
|
||||
@login_required
|
||||
@allowed_roles([UserRoles.ADMIN, UserRoles.BROKER, UserRoles.MANAGER, UserRoles.ACCOUNTANT])
|
||||
@allowed_roles([UserRoles.ADMIN, UserRoles.BROKER, UserRoles.MANAGER, UserRoles.ACCOUNTANT, UserRoles.WATER_RESOURCE_MANAGER])
|
||||
def get_customer_wells(request, customer_id):
|
||||
"""چاههای مرتبط با یک مشترک"""
|
||||
customer = get_object_or_404(Profile, id=customer_id)
|
||||
|
|
@ -262,7 +271,7 @@ def get_customer_wells(request, customer_id):
|
|||
|
||||
@require_GET
|
||||
@login_required
|
||||
@allowed_roles([UserRoles.ADMIN, UserRoles.BROKER, UserRoles.MANAGER, UserRoles.ACCOUNTANT])
|
||||
@allowed_roles([UserRoles.ADMIN, UserRoles.BROKER, UserRoles.MANAGER, UserRoles.ACCOUNTANT, UserRoles.WATER_RESOURCE_MANAGER])
|
||||
def get_customer_requests(request, customer_id):
|
||||
"""درخواستهای مرتبط با یک مشترک"""
|
||||
customer = get_object_or_404(Profile, id=customer_id)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue