alcehmy and event functions updated
This commit is contained in:
@@ -20,7 +20,6 @@ from sqlalchemy import (
|
||||
Integer,
|
||||
Text,
|
||||
or_,
|
||||
Identity,
|
||||
)
|
||||
from sqlalchemy.orm import mapped_column, relationship, Mapped
|
||||
|
||||
@@ -425,9 +424,7 @@ class RelationshipEmployee2PostCode(CrudCollection):
|
||||
company_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("companies.id"), nullable=True
|
||||
) # 1, 2, 3
|
||||
employee_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("employees.id"), nullable=False
|
||||
)
|
||||
employee_id: Mapped[int] = mapped_column(ForeignKey("employees.id"), nullable=False)
|
||||
member_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("address_postcode.id"), nullable=False
|
||||
)
|
||||
@@ -465,13 +462,25 @@ class Addresses(CrudCollection):
|
||||
__tablename__ = "addresses"
|
||||
__exclude__fields__ = []
|
||||
|
||||
build_number: Mapped[str] = mapped_column(String(24), nullable=False, comment="Build Number")
|
||||
door_number: Mapped[str] = mapped_column(String(24), nullable=True, comment="Door Number")
|
||||
floor_number: Mapped[str] = mapped_column(String(24), nullable=True, comment="Floor Number")
|
||||
build_number: Mapped[str] = mapped_column(
|
||||
String(24), nullable=False, comment="Build Number"
|
||||
)
|
||||
door_number: Mapped[str] = mapped_column(
|
||||
String(24), nullable=True, comment="Door Number"
|
||||
)
|
||||
floor_number: Mapped[str] = mapped_column(
|
||||
String(24), nullable=True, comment="Floor Number"
|
||||
)
|
||||
|
||||
comment_address: Mapped[str] = mapped_column(String, nullable=False, comment="Address")
|
||||
letter_address: Mapped[str] = mapped_column(String, nullable=False, comment="Address")
|
||||
short_letter_address: Mapped[str] = mapped_column(String, nullable=False, comment="Address")
|
||||
comment_address: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Address"
|
||||
)
|
||||
letter_address: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Address"
|
||||
)
|
||||
short_letter_address: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Address"
|
||||
)
|
||||
|
||||
latitude: Mapped[float] = mapped_column(Numeric(20, 12), server_default="0")
|
||||
longitude: Mapped[float] = mapped_column(Numeric(20, 12), server_default="0")
|
||||
@@ -483,9 +492,10 @@ class Addresses(CrudCollection):
|
||||
|
||||
@classmethod
|
||||
def list_via_employee(cls, token_dict, filter_expr):
|
||||
post_code_list = RelationshipEmployee2PostCode.filter_active(
|
||||
post_code_list = RelationshipEmployee2PostCode.filter_all(
|
||||
RelationshipEmployee2PostCode.employee_id
|
||||
== token_dict.selected_company.employee_id,
|
||||
RelationshipEmployee2PostCode.active==True,
|
||||
).data
|
||||
post_code_id_list = [post_code.member_id for post_code in post_code_list]
|
||||
if not post_code_id_list:
|
||||
@@ -493,10 +503,10 @@ class Addresses(CrudCollection):
|
||||
status_code=404,
|
||||
detail="User has no post code registered. User can not list addresses.",
|
||||
)
|
||||
cls.pre_query = Addresses.filter_active(
|
||||
cls.post_code_id.in_(post_code_id_list)
|
||||
).query
|
||||
return cls.filter_active(*filter_expr)
|
||||
cls.pre_query = cls.filter_active(cls.post_code_id.in_(post_code_id_list)).query
|
||||
filter_cls = cls.filter_all(*filter_expr)
|
||||
cls.pre_query = None
|
||||
return filter_cls
|
||||
|
||||
# buildings: Mapped["Build"] = relationship(
|
||||
# "Build", back_populates="addresses", foreign_keys="Build.address_id"
|
||||
|
||||
Reference in New Issue
Block a user