add product
This commit is contained in:
1 parent
423d4cf40e
commit
c8d45dd07c
58 files changed
+8309
-674
No files matched your search
@@ -3,6 +3,7 @@ from utils.base_model import BaseModel
|
||||
from apps.workspace.models import City as CityModel, Workspace as WorkspaceModel
|
||||
from apps.cuser.models import CuserRole as CuserRoleModel
|
||||
from django.core.exceptions import ValidationError
|
||||
from utils.validations.mobile import normalize_mobile
|
||||
# Create your models here.
|
||||
|
||||
|
||||
@@ -61,13 +62,24 @@ class Customer(BaseModel):
|
||||
|
||||
class Meta:
|
||||
ordering = ['-created_at']
|
||||
constraints = [
|
||||
models.UniqueConstraint(fields=['sys_ws', 'mobile'], name='customer_workspace_mobile_unique'),
|
||||
]
|
||||
|
||||
def __str__(self):
|
||||
return str(self.name_family)
|
||||
|
||||
def clean(self):
|
||||
super().clean()
|
||||
if self.mobile is not None:
|
||||
self.mobile = normalize_mobile(self.mobile)
|
||||
if type(self).objects.filter(sys_ws_id=self.sys_ws_id, mobile=self.mobile).exclude(pk=self.pk).exists():
|
||||
raise ValidationError({"mobile": "مشتری با این شماره موبایل در این فضای کاری قبلاً ثبت شده است."})
|
||||
if self.cuser_role and not self.cuser_role.role_type.role_name_en == 'workspace_customer':
|
||||
raise ValidationError("cuser_role type must be customer")
|
||||
if self.cuser_role and (self.cuser_role.sys_ws_id != self.sys_ws_id or not self.cuser_role.cuser_id
|
||||
or self.cuser_role.cuser.mobile != self.mobile):
|
||||
raise ValidationError({'cuser_role': 'حساب پنل باید متعلق به همین شماره موبایل و فضای کاری باشد.'})
|
||||
|
||||
|
||||
class CustomerNote(BaseModel):
|
||||
|
||||
Reference in new issue
Block a user