Coverage for organizations/models.py: 90%
66 statements
« prev ^ index » next coverage.py v6.4.4, created at 2023-06-29 13:45 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2023-06-29 13:45 -0600
1from django.db import models
2from app.choices import ModelChoices, ChoiceItem
3from app.models import RandomSlugModel, TimeStampedModel
6class Organization(RandomSlugModel):
7 """
8 Model for organization.
9 All other models may depend on this
10 """
12 name = models.CharField(max_length=128)
14 stripe_secret_key = models.CharField(max_length=128, null=True)
15 facturapi_secret_key = models.CharField(max_length=128, blank=True, null=True)
16 facturapi_id = models.CharField(max_length=128, blank=True, null=True)
19class MembershipType(RandomSlugModel):
20 """
21 Organization's membership types
22 """
24 organization = models.ForeignKey("organizations.Organization", on_delete=models.CASCADE)
25 name = models.CharField(max_length=128)
27 class Meta:
28 ordering = ["name"]
31class MembershipFileTypes(RandomSlugModel):
32 """
33 Organization's required files for membership creation
34 """
36 organization = models.ForeignKey("organizations.Organization", on_delete=models.CASCADE)
37 name = models.CharField(max_length=32)
38 membership_type = models.ManyToManyField(
39 "organizations.MembershipType", blank=True, help_text="Leave blank for require to all types"
40 )
41 validity_days = models.IntegerField(null=True, blank=True)
43 class Meta:
44 ordering = ["name"]
47class PanelLanguage(TimeStampedModel):
48 """
49 Organization language elections
50 """
52 organization = models.ForeignKey("organizations.Organization", on_delete=models.CASCADE)
54 class SystemWordChoices(ModelChoices):
55 segment = ChoiceItem("segment", default_single="Segmento", default_plural="Segmentos")
56 membership = ChoiceItem("membership", default_single="Membresía", default_plural="Membresías")
57 subsidiary = ChoiceItem("subsidiary", default_single="Subsidiario", default_plural="Subsidiarios")
59 system_word = models.CharField(max_length=32, choices=SystemWordChoices.choices)
60 verbose_name = models.CharField(max_length=32)
61 plural_verbose_name = models.CharField(max_length=32)
63 class Meta:
64 unique_together = ("organization", "system_word")
66 @classmethod
67 def verbose(cls, organization):
68 organization_objects = cls.objects.filter(organization=organization)
70 def get_verbose(word, plural=True):
71 instance = organization_objects.get(system_word=word)
72 if plural:
73 return instance.plural_verbose_name
74 return instance.verbose_name
76 return get_verbose
79class OrganizationModule(TimeStampedModel):
80 """
81 Organization Module Settings
82 """
84 organization = models.ForeignKey("organizations.Organization", on_delete=models.CASCADE)
86 class ModuleChoices(ModelChoices):
87 events = ChoiceItem("events")
89 module = models.CharField(max_length=32, choices=ModuleChoices.choices)
90 is_active = models.BooleanField(default=True)
92 class Meta:
93 unique_together = ("organization", "module")
96class PaymentMethodType(RandomSlugModel):
97 """Model for Payment Method Types"""
99 organization = models.ForeignKey("organizations.Organization", on_delete=models.CASCADE)
101 type_key = models.CharField(max_length=2)
102 description = models.CharField(max_length=256)
105class OrganizationTaxInformation(RandomSlugModel):
106 """
107 Tax information for Organization
108 """
110 organization = models.OneToOneField("organizations.Organization", on_delete=models.CASCADE, related_name="tax_info")
112 legal_name = models.CharField(max_length=128)
113 tax_system = models.CharField(max_length=3)
115 cer_file = models.FileField(upload_to="organizations/certificates/", blank=True, null=True)
116 key_file = models.FileField(upload_to="organizations/certificates/", blank=True, null=True)
118 zip = models.CharField(max_length=5)
119 street = models.CharField(max_length=128)
120 exterior = models.CharField(max_length=8)
121 interior = models.CharField(max_length=8, blank=True, null=True)
122 neighborhood = models.CharField(max_length=128, blank=True, null=True)
123 city = models.CharField(max_length=128, blank=True, null=True)
124 municipality = models.CharField(max_length=128, blank=True, null=True)
125 state = models.CharField(max_length=128, blank=True, null=True)