initial commit

This commit is contained in:
2025-08-05 10:26:39 +05:00
commit b7412bbef6
298 changed files with 10533 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
from .accounts import * # noqa
from .companies import * # noqa
from .folders import * # noqa

View File

@@ -0,0 +1,77 @@
from django.db import models
from django.utils.translation import gettext_lazy as _
from django.contrib.auth import get_user_model
from core.utils.base_model import UUIDPrimaryKeyBaseModel
from core.apps.companies.models.companies import CompanyModel
from core.apps.companies.validators.accounts import (
CompanyAccountValidator
)
UserModel = get_user_model()
class CompanyAccountModel(UUIDPrimaryKeyBaseModel):
role = models.CharField(
_("Role"),
max_length=255,
null=True,
blank=True,
)
user = models.ForeignKey( # type: ignore
UserModel,
on_delete=models.CASCADE,
verbose_name=_("User"),
null=False,
blank=False,
related_name="companies"
)
company = models.ForeignKey( # type: ignore
CompanyModel,
on_delete=models.CASCADE,
verbose_name=_("Company"),
null=False,
blank=False,
related_name="accounts",
)
def __str__(self):
return (
f"{self.user!s} "
f"{self.company!s} "
f"{self.role}"
)
def clean(self) -> None:
super().clean()
validator = CompanyAccountValidator(self)
validator()
@property
def user_name(self) -> str: # type: ignore
return self.user.full_name # type: ignore
@classmethod
def _create_fake(cls):
return cls.objects.create(
name="Mock CompanyAccount",
user=UserModel._create_fake(), # type: ignore
company=CompanyModel._create_fake() # type: ignore
)
class Meta: # type: ignore
db_table = "company_accounts"
verbose_name = _("Company Account")
verbose_name_plural = _("Company Accounts")
indexes = [
models.Index(fields=["user"], name="company_accounts_user_inx"),
models.Index(fields=["company"], name="company_accounts_company_inx")
]
unique_together = ["user", "company"]

View File

@@ -0,0 +1,184 @@
from typing import Self
from django.db import models
from django.core.validators import (
EmailValidator,
MinLengthValidator,
)
from django.utils.translation import gettext_lazy as _
from django.contrib.auth import get_user_model
from core.utils.base_model import UUIDPrimaryKeyBaseModel
from core.apps.banks.models import BankModel
from core.apps.companies.validators.companies import (
iik_validator,
iin_validator,
name_validator,
phone_validator,
pinfl_validator,
CompanyValidator,
)
UserModel = get_user_model()
class CompanyModel(UUIDPrimaryKeyBaseModel):
name = models.CharField(
_("name"),
max_length=512,
validators=[
name_validator,
MinLengthValidator(3)
],
null=False,
blank=False
)
pinfl_code = models.CharField(
_("PINFL code"),
validators=[
pinfl_validator,
],
null=True,
blank=True,
)
iin_code = models.CharField(
_("IIN code"),
validators=[iin_validator],
null=True,
blank=True
)
phone = models.CharField(
_("Phone Number"),
max_length=25,
unique=True,
validators=[
phone_validator,
],
null=False,
blank=False,
)
email = models.CharField(
_("Email Address"),
max_length=255,
validators=[
EmailValidator()
],
unique=True,
null=False,
blank=False,
)
iik_code = models.CharField(
_("IIK code"),
max_length=30,
validators=[
iik_validator
],
null=True, blank=True
)
bank = models.ForeignKey(
BankModel,
on_delete=models.SET_NULL,
null=True,
blank=True
)
legal_address = models.CharField(
_("Legal Address"),
max_length=512,
validators=[
MinLengthValidator(10)
],
null=True,
blank=True
)
real_address = models.CharField(
_("Real Address"),
max_length=512,
validators=[
MinLengthValidator(10)
],
null=True,
blank=True
)
logo = models.ImageField(
_("Logo"),
max_length=1024,
null=True,
blank=True
)
signature_authority_document = models.FileField(
_("Signature Authority Document"),
max_length=1024,
null=True,
blank=True
)
def __str__(self):
return self.name
@property
def company_code(self) -> str:
if self.pinfl_code is not None:
return f"PINFL code: {self.pinfl_code}"
else:
return f"IIN code: {self.iin_code}"
def clean(self):
super().clean()
validator = CompanyValidator(self)
validator()
@classmethod
def _create_fake(cls) -> Self:
return cls.objects.create(
name="mock LLC",
pinfl_code="12345678901234",
iin_code="12345678901234",
phone="+998901234567",
email="mock@example.com",
iik_code="UZS1234567890",
legal_address="Some legal address, City, Country",
real_address="Same as above",
bank=BankModel._create_fake() # type: ignore
)
class Meta: # type: ignore
db_table = "companies"
verbose_name = _("Company")
verbose_name_plural = _("Companies")
indexes = [
models.Index(
fields=["phone"],
name="companies_phone_inx"
),
models.Index(
fields=["email"],
name="companies_email_inx"
),
models.Index(
fields=["iin_code"],
name="companies_iin_code_inx"
),
models.Index(
fields=["pinfl_code"],
name="companies_pinfl_code_inx"
),
models.Index(
fields=["name"],
name="companies_name_inx"
),
]

View File

@@ -0,0 +1,68 @@
from django.db import models
from django.utils.translation import gettext_lazy as _
from django.core.validators import (
MaxLengthValidator,
MinLengthValidator,
)
from core.utils.base_model import UUIDPrimaryKeyBaseModel
from core.apps.companies.models.companies import CompanyModel
from core.apps.companies.validators.folders import (
CompanyFolderValidator
)
from core.apps.contracts.models import ContractModel
class CompanyFolderModel(UUIDPrimaryKeyBaseModel):
name = models.CharField(
_("name"),
max_length=150,
validators=[
MaxLengthValidator(150),
MinLengthValidator(3),
]
)
company = models.ForeignKey(
CompanyModel,
on_delete=models.PROTECT,
related_name="folders",
null=False,
blank=False
)
contracts = models.ManyToManyField( # type: ignore
ContractModel,
verbose_name=_("Contracts"),
related_name="folders",
)
def __str__(self):
return f"{self.name} {self.company!s}"
@classmethod
def _create_fake(cls):
return cls.objects.create(
name="mock",
company=CompanyModel._create_fake() # type: ignore
)
def clean(self) -> None:
super().clean()
validator = CompanyFolderValidator(self)
validator()
class Meta: # type: ignore
db_table = "company_folders"
verbose_name = _("Company Folder")
verbose_name_plural = _("Company Folders")
constraints = [
models.UniqueConstraint(
fields=["name", "company"],
name="company_folders_name_company_unique_constraint"
)
]