This commit is contained in:
aminhashemi92 2025-09-29 17:38:11 +03:30
parent 810c87e2e0
commit b5bf3a5dbe
51 changed files with 2397 additions and 326 deletions

View file

@ -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(