48 lines
1.5 KiB
Python
48 lines
1.5 KiB
Python
import uuid
|
|
|
|
from typing import TYPE_CHECKING, List, Optional
|
|
|
|
from sqlalchemy import Boolean, Unicode, text
|
|
from sqlalchemy.dialects.postgresql import UUID
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
from sqlalchemy.sql import expression
|
|
|
|
from ..db.base_class import reg
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
from .customer_discount import CustomerDiscount
|
|
|
|
|
|
@reg.mapped_as_dataclass(unsafe_hash=True)
|
|
class Customer:
|
|
__tablename__ = "customers"
|
|
|
|
id: Mapped[uuid.UUID] = mapped_column(
|
|
"id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), insert_default=uuid.uuid4
|
|
)
|
|
name: Mapped[str] = mapped_column("name", Unicode(255), nullable=False)
|
|
phone: Mapped[str] = mapped_column("phone", Unicode(255), nullable=False, unique=True)
|
|
address: Mapped[Optional[str]] = mapped_column("address", Unicode(255), nullable=True)
|
|
|
|
print_in_bill: Mapped[bool] = mapped_column(
|
|
"print_in_bill", Boolean, server_default=expression.false(), insert_default=False, nullable=False
|
|
)
|
|
|
|
discounts: Mapped[List["CustomerDiscount"]] = relationship(back_populates="customer")
|
|
|
|
@property
|
|
def __name__(self):
|
|
return self.name
|
|
|
|
def __init__(self, name=None, phone=None, address=None, print_in_bill=None, id_=None):
|
|
self.name = name
|
|
self.phone = phone
|
|
self.address = address
|
|
self.print_in_bill = print_in_bill
|
|
self.id = id_
|
|
|
|
@classmethod
|
|
def cash(cls):
|
|
return uuid.UUID("2c716f4b-0736-429a-ad51-610d7c47cb5e")
|