felicity-lims/felicity/apps/client/entities.py

74 lines
2.4 KiB
Python
Raw Normal View History

2024-07-24 17:04:53 +08:00
from uuid import uuid4
2024-07-28 03:52:31 +08:00
2024-07-21 15:06:51 +08:00
from sqlalchemy import Boolean, Column, ForeignKey, String
from sqlalchemy.orm import backref, relationship
2024-07-21 21:44:22 +08:00
from felicity.apps.abstract import AuditHistory
from felicity.apps.setup.entities import District, Province
from felicity.apps.user.abstract import AbstractBaseUser
2024-07-24 04:30:01 +08:00
from felicity.apps.user.enum import UserType
2024-07-21 15:06:51 +08:00
2024-07-21 21:44:22 +08:00
class Client(AuditHistory):
2024-07-21 15:06:51 +08:00
"""Client/Facility"""
__tablename__ = "client"
name = Column(String, nullable=False)
code = Column(String, index=True, unique=True, nullable=False)
district_uid = Column(String, ForeignKey("district.uid"), nullable=True)
district = relationship(District, backref="clients", lazy="selectin")
province_uid = Column(String, ForeignKey("province.uid"), nullable=True)
province = relationship(Province, backref="clients", lazy="selectin")
email = Column(String, nullable=True)
email_cc = Column(String, nullable=True)
consent_email = Column(Boolean(), default=False)
phone_mobile = Column(String, nullable=True)
phone_business = Column(String, nullable=True)
consent_sms = Column(Boolean(), default=False)
internal_use = Column(Boolean(), default=False) # e.g Test Client
active = Column(Boolean(), default=False)
@property
def get_province(self):
if self.district:
return self.district.province.name
elif self.province:
return self.province.name
else:
return ""
@property
def get_country(self):
if self.district:
return self.district.province.country.name
elif self.province:
return self.province.country.name
else:
return ""
class ClientContact(AbstractBaseUser):
__tablename__ = "client_contact"
email_cc = Column(String, nullable=True)
consent_sms = Column(Boolean(), default=False)
client_uid = Column(String, ForeignKey("client.uid"), nullable=False)
client = relationship(
Client,
backref=backref(
"contacts",
uselist=False,
),
lazy="selectin",
)
2024-07-24 17:04:53 +08:00
# to be deleted later
2024-07-28 03:52:31 +08:00
user_name = Column(
String, unique=True, index=True, nullable=False, default=uuid4().hex
)
2024-07-24 17:04:53 +08:00
hashed_password = Column(String, nullable=False, default=uuid4().hex)
2024-07-21 15:06:51 +08:00
@property
def user_type(self):
2024-07-24 04:30:01 +08:00
return UserType.CLIENT_CONTACT