Нет описания

models.py 3.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. from __future__ import annotations
  2. from django.contrib.auth import get_user_model
  3. from django.contrib.sites.models import Site
  4. from django.db import models
  5. User = get_user_model()
  6. class TimestampedModel(models.Model):
  7. created_at = models.DateTimeField(auto_now_add=True)
  8. updated_at = models.DateTimeField(auto_now=True)
  9. class Meta:
  10. abstract = True
  11. class Organization(TimestampedModel):
  12. name = models.CharField(max_length=255)
  13. code = models.CharField(max_length=32, unique=True)
  14. # Minimal curated choices for simplicity; expand as needed
  15. TZ_CHOICES = (
  16. ("UTC", "UTC"),
  17. ("Asia/Bangkok", "Asia/Bangkok"),
  18. ("Asia/Singapore", "Asia/Singapore"),
  19. ("Asia/Jakarta", "Asia/Jakarta"),
  20. ("Europe/Berlin", "Europe/Berlin"),
  21. ("America/New_York", "America/New_York"),
  22. )
  23. timezone = models.CharField(max_length=64, choices=TZ_CHOICES, default="UTC")
  24. CURRENCY_CHOICES = (
  25. ("USD", "USD — US Dollar"),
  26. ("THB", "THB — Thai Baht"),
  27. ("EUR", "EUR — Euro"),
  28. ("SGD", "SGD — Singapore Dollar"),
  29. ("IDR", "IDR — Indonesian Rupiah"),
  30. )
  31. currency_code = models.CharField(max_length=8, choices=CURRENCY_CHOICES, default="USD")
  32. # Weigh ticket reconciliation settings
  33. ticket_tolerance_abs_kg = models.DecimalField(max_digits=10, decimal_places=3, default=0.500)
  34. ticket_tolerance_pct = models.DecimalField(max_digits=5, decimal_places=2, default=1.00)
  35. allow_adjust_net_to_lines = models.BooleanField(default=True)
  36. allow_add_residual_line = models.BooleanField(default=True)
  37. def __str__(self) -> str:
  38. return self.name
  39. class OrganizationSite(models.Model):
  40. organization = models.ForeignKey(Organization, on_delete=models.CASCADE, related_name="sites")
  41. site = models.OneToOneField(Site, on_delete=models.CASCADE, related_name="organization_site")
  42. def __str__(self) -> str:
  43. return f"{self.site.domain} -> {self.organization.code}"
  44. class UserProfile(TimestampedModel):
  45. ROLE_OWNER = "owner"
  46. ROLE_MANAGER = "manager"
  47. ROLE_DRIVER = "driver"
  48. ROLE_CUSTOMER = "customer"
  49. ROLE_AUDITOR = "auditor"
  50. ROLE_CHOICES = (
  51. (ROLE_OWNER, "Owner"),
  52. (ROLE_MANAGER, "Manager"),
  53. (ROLE_DRIVER, "Driver"),
  54. (ROLE_CUSTOMER, "Customer"),
  55. (ROLE_AUDITOR, "Auditor"),
  56. )
  57. user = models.OneToOneField(User, on_delete=models.CASCADE, related_name="recycle_profile")
  58. organization = models.ForeignKey(Organization, on_delete=models.CASCADE, related_name="users")
  59. role = models.CharField(max_length=16, choices=ROLE_CHOICES, default=ROLE_MANAGER)
  60. my_photo = models.ImageField(upload_to="user_photos/", blank=True, null=True)
  61. # Contact and profile details
  62. phone = models.CharField(max_length=32, blank=True)
  63. job_title = models.CharField(max_length=128, blank=True)
  64. department = models.CharField(max_length=128, blank=True)
  65. preferred_language = models.CharField(max_length=10, blank=True)
  66. # Address fields
  67. address_line1 = models.CharField(max_length=255, blank=True)
  68. address_line2 = models.CharField(max_length=255, blank=True)
  69. city = models.CharField(max_length=128, blank=True)
  70. state = models.CharField(max_length=128, blank=True)
  71. postal_code = models.CharField(max_length=32, blank=True)
  72. country = models.CharField(max_length=64, blank=True)
  73. def __str__(self) -> str:
  74. return f"{self.user.username} ({self.role})"