save and confirmed added

This commit is contained in:
2024-11-17 16:30:50 +03:00
parent 7e1b26f3c4
commit 295dbe2cd8
48 changed files with 922 additions and 697 deletions

View File

@@ -209,6 +209,7 @@ class UserLoginModule(AuthModule):
People,
MongoQueryIdentity,
)
found_user = Users.check_user_exits(
access_key=data.access_key, domain=data.domain
)
@@ -260,9 +261,7 @@ class UserLoginModule(AuthModule):
no_address_validates = mongo_db.mongo_engine.get_all()[0] == 0
record_id = uuid.uuid4().__str__()
notice_link = ApiStatic.blacklist_login(record_id=record_id)
found_people = People.filter_one(
People.id == found_user.person_id
).data
found_people = People.filter_one(People.id == found_user.person_id).data
access_via_user = query_engine.update_access_history_via_user(
AccessHistoryViaUser(
**{

View File

@@ -437,10 +437,16 @@ class AccountRecords(CrudCollection):
status_id: Mapped[int] = mapped_column(SmallInteger, server_default="0")
approved_record: Mapped[bool] = mapped_column(Boolean, server_default="0")
import_file_name: Mapped[str] = mapped_column(String, nullable=True, comment="XLS Key")
import_file_name: Mapped[str] = mapped_column(
String, nullable=True, comment="XLS Key"
)
receive_debit: Mapped[int] = mapped_column(ForeignKey("api_enum_dropdown.id"), nullable=True)
receive_debit_uu_id: Mapped[str] = mapped_column(String, nullable=True, comment="Debit UU ID")
receive_debit: Mapped[int] = mapped_column(
ForeignKey("api_enum_dropdown.id"), nullable=True
)
receive_debit_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Debit UU ID"
)
budget_type: Mapped[int] = mapped_column(
ForeignKey("api_enum_dropdown.id"), nullable=True
)
@@ -449,20 +455,32 @@ class AccountRecords(CrudCollection):
)
company_id: Mapped[int] = mapped_column(ForeignKey("companies.id"), nullable=True)
company_uu_id: Mapped[str] = mapped_column(String, nullable=True, comment="Company UU ID")
send_company_id: Mapped[int] = mapped_column(ForeignKey("companies.id"), nullable=True)
send_company_uu_id = mapped_column(String, nullable=True, comment="Send Company UU ID" )
company_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Company UU ID"
)
send_company_id: Mapped[int] = mapped_column(
ForeignKey("companies.id"), nullable=True
)
send_company_uu_id = mapped_column(
String, nullable=True, comment="Send Company UU ID"
)
customer_id: Mapped[int] = mapped_column(ForeignKey("people.id"), nullable=True)
customer_uu_id = mapped_column(String, nullable=True, comment="Customer UU ID")
send_person_id: Mapped[int] = mapped_column(ForeignKey("people.id"), nullable=True)
send_person_uu_id: Mapped[str] = mapped_column(String, nullable=True, comment="Send Person UU ID")
approving_accounting_person: Mapped[int] = mapped_column(ForeignKey("people.id"), nullable=True)
send_person_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Send Person UU ID"
)
approving_accounting_person: Mapped[int] = mapped_column(
ForeignKey("people.id"), nullable=True
)
approving_accounting_person_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Approving Accounting Person UU ID"
)
# build_id: Mapped[int] = mapped_column(ForeignKey("build.id"), nullable=True)
build_parts_id: Mapped[int] = mapped_column(ForeignKey("build_parts.id"), nullable=True)
build_parts_id: Mapped[int] = mapped_column(
ForeignKey("build_parts.id"), nullable=True
)
build_parts_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Build Parts UU ID"
)

View File

@@ -24,9 +24,9 @@ class CrypterEngine(CrudCollection):
@classmethod
def get_valid_keys(cls, row=None):
cls.encrypt_list, cls.decrypt_list = [], []
if not cls.filter_all(
cls.created_at > datetime.now() - timedelta(days=29)
).get(1):
if not cls.filter_all(cls.created_at > datetime.now() - timedelta(days=29)).get(
1
):
cls.create_encrypt_keys(count=100)
if decrypt_identifier := getattr(row, "cryp_uu_id", None):
if decrypt_row := cls.find_one(uu_id=str(decrypt_identifier)):

View File

@@ -179,7 +179,9 @@ class Build(CrudCollection, SelectActionWithEmployee):
site_id: Mapped[int] = mapped_column(ForeignKey("build_sites.id"), nullable=True)
site_uu_id: Mapped[str] = mapped_column(String, comment="Site UUID", nullable=True)
address_id: Mapped[int] = mapped_column(ForeignKey("addresses.id"), nullable=False)
address_uu_id: Mapped[str] = mapped_column(String, comment="Address UUID", nullable=False)
address_uu_id: Mapped[str] = mapped_column(
String, comment="Address UUID", nullable=False
)
build_types_id: Mapped[int] = mapped_column(
ForeignKey("build_types.id"), nullable=False, comment="Building Type"
)
@@ -226,8 +228,8 @@ class Build(CrudCollection, SelectActionWithEmployee):
@property
def management_room(self):
if management_room := BuildParts.find_one(
id=self.management_room_id, build_id=self.id, active=True, is_confirmed=True
if management_room := BuildParts.filter_by_one(
system=True, id=self.management_room_id, build_id=self.id
):
return management_room
return None
@@ -240,7 +242,7 @@ class Build(CrudCollection, SelectActionWithEmployee):
data_dict["address_id"] = None
if data.address_uu_id:
official_address = Addresses.filter_one(
Addresses.uu_id==data.address_uu_id,
Addresses.uu_id == data.address_uu_id,
).data
data_dict["address_id"] = official_address.id
data_dict["build_no"] = str(official_address.build_number)
@@ -249,7 +251,9 @@ class Build(CrudCollection, SelectActionWithEmployee):
status_code=status.HTTP_404_NOT_FOUND,
detail="Address is not found in database. Re-enter address record then try again.",
)
build_type = BuildTypes.filter_by_one(system=True, uu_id=str(data.build_types_uu_id)).data
build_type = BuildTypes.filter_by_one(
system=True, uu_id=str(data.build_types_uu_id)
).data
data_dict["build_types_id"] = build_type.id
build_created = cls.find_or_create(**data_dict)
created_build_relation = cls.__many__table__.find_or_create(
@@ -304,7 +308,8 @@ class Build(CrudCollection, SelectActionWithEmployee):
@property
def livable_part_count(self):
livable_parts = BuildParts.filter_all(
BuildParts.build_id == self.id, BuildParts.human_livable == True,
BuildParts.build_id == self.id,
BuildParts.human_livable == True,
)
if not livable_parts.data:
raise HTTPException(
@@ -318,7 +323,9 @@ class Build(CrudCollection, SelectActionWithEmployee):
building_types = None
for part in self.parts:
building_types = {}
build_type = BuildTypes.filter_by_one(system=True, id=part.build_part_type_id).data
build_type = BuildTypes.filter_by_one(
system=True, id=part.build_part_type_id
).data
if build_type.type_code in building_types:
building_types[build_type.type_code]["list"].append(part.part_no)
else:
@@ -363,7 +370,9 @@ class BuildParts(CrudCollection):
part_gross_size: Mapped[int] = mapped_column(
Integer, server_default="0", comment="Part Gross Size"
)
part_net_size: Mapped[int] = mapped_column(Integer, server_default="0", comment="Part Net Size")
part_net_size: Mapped[int] = mapped_column(
Integer, server_default="0", comment="Part Net Size"
)
default_accessory: Mapped[str] = mapped_column(
Text, server_default="0", comment="Default Accessory"
)
@@ -469,7 +478,9 @@ class BuildParts(CrudCollection):
@property
def part_name(self):
if build_type := BuildTypes.filter_by_one(system=True, id=self.build_part_type_id).data:
if build_type := BuildTypes.filter_by_one(
system=True, id=self.build_part_type_id
).data:
return f"{str(build_type.type_name).upper()} : {str(self.part_no).upper()}"
return f"Undefined:{str(build_type.type_name).upper()}"
@@ -552,23 +563,21 @@ class BuildLivingSpace(CrudCollection):
from api_events.events.events.events_bind_services import (
ServiceBindOccupantEventMethods,
)
if data.get('expiry_starts'):
data['expiry_starts'] = str(system_arrow.get(data['expiry_starts']))
if data.get('expiry_ends'):
data['expiry_ends'] = str(system_arrow.get(data['expiry_ends']))
if data.get("expiry_starts"):
data["expiry_starts"] = str(system_arrow.get(data["expiry_starts"]))
if data.get("expiry_ends"):
data["expiry_ends"] = str(system_arrow.get(data["expiry_ends"]))
created_living_space = BuildLivingSpace.find_or_create(**data)
occupant_type = OccupantTypes.filter_by_one(
system=True,
uu_id=created_living_space.occupant_type_uu_id
system=True, uu_id=created_living_space.occupant_type_uu_id
).data
related_service = Services.filter_by_one(
related_responsibility=occupant_type.occupant_code,
**Services.valid_record_dict
**Services.valid_record_dict,
).data
created_living_space.save()
created_living_space.is_confirmed = True
created_living_space.save()
created_living_space.save_and_confirm()
if not related_service:
raise HTTPException(
@@ -586,6 +595,7 @@ class BuildLivingSpace(CrudCollection):
cls, customer_id, process_date, add_days: int = 32
):
from api_library.date_time_actions.date_functions import system_arrow
formatted_date = system_arrow.get(str(process_date))
living_spaces = cls.filter_all(
or_(
@@ -642,7 +652,7 @@ class BuildSites(CrudCollection):
__exclude__fields__ = []
__include__fields__ = []
site_name : Mapped[str]= mapped_column(String(24), nullable=False)
site_name: Mapped[str] = mapped_column(String(24), nullable=False)
site_no: Mapped[str] = mapped_column(String(8), nullable=False)
address_id: Mapped[int] = mapped_column(ForeignKey("addresses.id"))
@@ -671,14 +681,22 @@ class BuildCompaniesProviding(CrudCollection):
build_id = mapped_column(
ForeignKey("build.id"), nullable=False, comment="Building ID"
)
build_uu_id: Mapped[str] = mapped_column(String, nullable=True, comment="Providing UUID")
build_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Providing UUID"
)
company_id: Mapped[int] = mapped_column(ForeignKey("companies.id"))
company_uu_id: Mapped[str] = mapped_column(String, nullable=True, comment="Providing UUID")
company_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Providing UUID"
)
provide_id: Mapped[int] = mapped_column(
ForeignKey("api_enum_dropdown.id"), nullable=True
)
provide_uu_id: Mapped[str] = mapped_column(String, nullable=True, comment="Providing UUID")
contract_id: Mapped[int] = mapped_column(Integer, ForeignKey("companies.id"), nullable=True)
provide_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Providing UUID"
)
contract_id: Mapped[int] = mapped_column(
Integer, ForeignKey("companies.id"), nullable=True
)
__table_args__ = (
Index(
@@ -702,14 +720,22 @@ class BuildPersonProviding(CrudCollection):
build_id = mapped_column(
ForeignKey("build.id"), nullable=False, comment="Building ID"
)
build_uu_id: Mapped[str] = mapped_column(String, nullable=True, comment="Providing UUID")
build_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Providing UUID"
)
people_id: Mapped[int] = mapped_column(ForeignKey("people.id"))
people_uu_id: Mapped[str] = mapped_column(String, nullable=True, comment="People UUID")
people_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="People UUID"
)
provide_id: Mapped[int] = mapped_column(
ForeignKey("api_enum_dropdown.id"), nullable=True
)
provide_uu_id: Mapped[str] = mapped_column(String, nullable=True, comment="Providing UUID")
contract_id: Mapped[int] = mapped_column(Integer, ForeignKey("companies.id"), nullable=True)
provide_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Providing UUID"
)
contract_id: Mapped[int] = mapped_column(
Integer, ForeignKey("companies.id"), nullable=True
)
__table_args__ = (
Index(

View File

@@ -45,7 +45,9 @@ class BuildDecisionBook(CrudCollection):
__tablename__ = "build_decision_book"
__exclude__fields__ = []
decision_book_pdf_path: Mapped[str] = mapped_column(String)
decision_book_pdf_path: Mapped[str] = mapped_column(
String, server_default="", nullable=True
)
resp_company_fix_wage: Mapped[float] = mapped_column(
Numeric(10, 2), server_default="0"
) #
@@ -135,9 +137,7 @@ class BuildDecisionBook(CrudCollection):
related_companies_ids = list(
related_.id for related_ in related_companies.all()
)
related_building = Build.filter_all(
Build.company_id.in_(related_companies_ids)
)
related_building = Build.filter_all(Build.company_id.in_(related_companies_ids))
related_building_ids = list(related_.id for related_ in related_building.data)
return cls.filter_all(cls.build_id.in_(related_building_ids)).query
@@ -223,13 +223,13 @@ class BuildDecisionBook(CrudCollection):
):
bank_date = datetime.strptime(str(bank_date), "%Y-%m-%d %H:%M:%S")
build_iban = BuildIbans.find_one(iban=iban)
decision_book: cls = cls.filter(
decision_book: cls = cls.filter_one(
cls.build_id == build_iban.build_id,
cls.expiry_starts < bank_date,
cls.expiry_ends > bank_date,
cls.active == True,
cls.deleted == False,
)
).data
decision_book.check_book_is_valid(bank_date.__str__())
return decision_book
return
@@ -263,11 +263,13 @@ class BuildDecisionBookInvitations(CrudCollection):
Numeric(10, 2), server_default="0.51"
)
message = mapped_column(Text, nullable=True, comment="Invitation Message")
planned_date = mapped_column(
message: Mapped[str] = mapped_column(
Text, nullable=True, comment="Invitation Message"
)
planned_date: Mapped[TIMESTAMP] = mapped_column(
TIMESTAMP, nullable=False, comment="Planned Meeting Date"
)
planned_date_expires = mapped_column(
planned_date_expires: Mapped[TIMESTAMP] = mapped_column(
TIMESTAMP, nullable=False, comment="Planned Meeting Date Expires"
)
@@ -284,13 +286,12 @@ class BuildDecisionBookInvitations(CrudCollection):
@classmethod
def check_invites_are_ready_for_meeting(cls, selected_decision_book, token_dict):
first_book_invitation = BuildDecisionBookInvitations.find_one(
build_id=token_dict.selected_occupant.build_id,
decision_book_id=selected_decision_book.id,
invitation_attempt=1,
active=True,
is_confirmed=True,
)
first_book_invitation = BuildDecisionBookInvitations.filter_one(
BuildDecisionBookInvitations.build_id
== token_dict.selected_occupant.build_id,
BuildDecisionBookInvitations.decision_book_id == selected_decision_book.id,
BuildDecisionBookInvitations.invitation_attempt == 1,
).data
if not first_book_invitation:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
@@ -305,19 +306,19 @@ class BuildDecisionBookInvitations(CrudCollection):
BuildDecisionBookPerson.build_decision_book_id
== selected_decision_book.id,
BuildDecisionBookPerson.is_attending == True,
filter_records=False,
system=True,
)
.query.distinct(BuildDecisionBookPerson.person_id)
.count()
)
second_book_invitation = BuildDecisionBookInvitations.find_one(
build_id=token_dict.selected_occupant.build_id,
decision_book_id=selected_decision_book.id,
invitation_attempt=2,
active=True,
is_confirmed=True,
)
second_book_invitation = BuildDecisionBookInvitations.filter_one(
BuildDecisionBookInvitations.build_id
== token_dict.selected_occupant.build_id,
BuildDecisionBookInvitations.decision_book_id == selected_decision_book.id,
BuildDecisionBookInvitations.invitation_attempt == 2,
system=True,
).data
if not valid_invite_count >= need_attend_count and not second_book_invitation:
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
@@ -341,46 +342,48 @@ class BuildDecisionBookPerson(CrudCollection):
__exclude__fields__ = []
__enum_list__ = [("management_typecode", "BuildManagementType", "bm")]
dues_percent_discount = mapped_column(SmallInteger, server_default="0")
dues_percent_discount: Mapped[int] = mapped_column(SmallInteger, server_default="0")
dues_fix_discount: Mapped[float] = mapped_column(Numeric(10, 2), server_default="0")
dues_discount_approval_date = mapped_column(
dues_discount_approval_date: Mapped[TIMESTAMP] = mapped_column(
TIMESTAMP, server_default="1900-01-01 00:00:00"
)
send_date = mapped_column(TIMESTAMP, nullable=False, comment="Confirmation Date")
is_attending = mapped_column(
send_date: Mapped[TIMESTAMP] = mapped_column(
TIMESTAMP, nullable=False, comment="Confirmation Date"
)
is_attending: Mapped[bool] = mapped_column(
Boolean, server_default="0", comment="Occupant is Attending to invitation"
)
confirmed_date = mapped_column(
confirmed_date: Mapped[TIMESTAMP] = mapped_column(
TIMESTAMP, nullable=True, comment="Confirmation Date"
)
token: Mapped[str] = mapped_column(
String, server_default="", comment="Invitation Token"
)
vicarious_person_id = mapped_column(
vicarious_person_id: Mapped[int] = mapped_column(
ForeignKey("people.id"), nullable=True, comment="Vicarious Person ID"
)
vicarious_person_uu_id = mapped_column(
vicarious_person_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Vicarious Person UUID"
)
invite_id = mapped_column(
invite_id: Mapped[int] = mapped_column(
ForeignKey("build_decision_book_invitations.id"), nullable=False
)
invite_uu_id: Mapped[str] = mapped_column(
String, nullable=False, comment="Invite UUID"
)
build_decision_book_id = mapped_column(
build_decision_book_id: Mapped[int] = mapped_column(
ForeignKey("build_decision_book.id"), nullable=False
)
build_decision_book_uu_id = mapped_column(
build_decision_book_uu_id: Mapped[str] = mapped_column(
String, nullable=False, comment="Decision Book UUID"
)
build_living_space_id = mapped_column(
build_living_space_id: Mapped[int] = mapped_column(
ForeignKey("build_living_space.id"), nullable=False
)
build_living_space_uu_id = mapped_column(
build_living_space_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Living Space UUID"
)
person_id: Mapped[int] = mapped_column(ForeignKey("people.id"), nullable=False)
@@ -403,7 +406,7 @@ class BuildDecisionBookPerson(CrudCollection):
system=True,
)
BuildDecisionBookPersonOccupants.pre_query = all_decision_book_people.query
return BuildDecisionBookPersonOccupants.filter_all(system=True)
return BuildDecisionBookPersonOccupants.filter_all(system=True).data
def add_occupant_type(self, occupant_type, build_living_space_id: int = None):
from databases import (
@@ -422,15 +425,14 @@ class BuildDecisionBookPerson(CrudCollection):
invite_uu_id=str(self.invite_uu_id),
occupant_type_id=occupant_type.id,
occupant_type_uu_id=str(occupant_type.uu_id),
is_confirmed=True,
)
if person_occupants := BuildDecisionBookPersonOccupants.find_or_create(
**book_dict
):
person_occupants.save_and_confirm()
decision_book = BuildDecisionBook.filter_one(
BuildDecisionBook.id == self.build_decision_book_id,
BuildDecisionBook.active == True,
BuildDecisionBook.is_confirmed == True,
).data
person_occupants.update(
expiry_starts=decision_book.expiry_starts,
@@ -449,8 +451,6 @@ class BuildDecisionBookPerson(CrudCollection):
decision_build = Build.filter_one(
Build.id == decision_book.build_id,
Build.active == True,
Build.is_confirmed == True,
).data
management_room = decision_build.management_room
if not management_room:
@@ -461,8 +461,6 @@ class BuildDecisionBookPerson(CrudCollection):
living_space = BuildLivingSpace.filter_one(
BuildLivingSpace.id == build_living_space_id,
BuildLivingSpace.active == True,
BuildLivingSpace.is_confirmed == True,
).data
expiry_ends = str(
system_arrow.get(decision_book.meeting_date).shift(hours=23)
@@ -477,15 +475,11 @@ class BuildDecisionBookPerson(CrudCollection):
person_uu_id=str(living_space.person_uu_id),
expiry_starts=expiry_starts,
expiry_ends=expiry_ends,
is_confirmed=True,
active=True,
)
expires_at = str(
system_arrow.get(decision_book.meeting_date).shift(days=15)
)
related_living_space.save()
related_living_space.is_confirmed = True
related_living_space.save()
related_living_space.save_and_confirm()
ServiceBindOccupantEventMethods.bind_services_occupant_system(
build_living_space_id=related_living_space.id,
service_id=related_service.id,
@@ -524,13 +518,13 @@ class BuildDecisionBookPersonOccupants(CrudCollection):
__tablename__ = "build_decision_book_person_occupants"
__exclude__fields__ = []
build_decision_book_person_id = mapped_column(
build_decision_book_person_id: Mapped[int] = mapped_column(
ForeignKey("build_decision_book_person.id"), nullable=False
)
build_decision_book_person_uu_id = mapped_column(
build_decision_book_person_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Decision Book Person UUID"
)
invite_id = mapped_column(
invite_id: Mapped[int] = mapped_column(
ForeignKey("build_decision_book_invitations.id"), nullable=True
)
invite_uu_id: Mapped[str] = mapped_column(
@@ -566,15 +560,17 @@ class BuildDecisionBookItems(CrudCollection):
__tablename__ = "build_decision_book_items"
__exclude__fields__ = []
item_order = mapped_column(
item_order: Mapped[int] = mapped_column(
SmallInteger, nullable=False, comment="Order Number of Item"
)
item_comment = mapped_column(Text, nullable=False, comment="Comment Content")
item_objection = mapped_column(Text)
info_is_completed = mapped_column(
item_comment: Mapped[str] = mapped_column(
Text, nullable=False, comment="Comment Content"
)
item_objection: Mapped[str] = mapped_column(Text)
info_is_completed: Mapped[bool] = mapped_column(
Boolean, server_default="0", comment="Info process is Completed"
)
is_payment_created = mapped_column(
is_payment_created: Mapped[bool] = mapped_column(
Boolean, server_default="0", comment="Are payment Records Created"
)
@@ -585,10 +581,10 @@ class BuildDecisionBookItems(CrudCollection):
String, nullable=True, comment="Info Type UUID"
)
build_decision_book_id = mapped_column(
build_decision_book_id: Mapped[int] = mapped_column(
ForeignKey("build_decision_book.id"), nullable=False
)
build_decision_book_uu_id = mapped_column(
build_decision_book_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Decision Book UUID"
)
@@ -610,7 +606,7 @@ class BuildDecisionBookItems(CrudCollection):
Companies,
)
related_companies = Companies.select_action(duty_id=duty_id)
related_companies = Companies.select_action(duty_id_list=[duty_id])
related_companies_ids = list(
related_.id for related_ in related_companies.all()
)
@@ -635,9 +631,9 @@ class BuildDecisionBookItems(CrudCollection):
duty_id=token.duty_list["duty_id"]
)
cls.pre_query = cls.select_action(duty_id=token.duty_list["duty_id"])
if decision_book := BuildDecisionBook.find_one(
uu_id=data.build_decision_book_uu_id
):
if decision_book := BuildDecisionBook.filter_one(
BuildDecisionBook.uu_id == data.build_decision_book_uu_id
).data:
found_dict = dict(
item_order=data.item_order, build_decision_book_id=decision_book.id
)
@@ -666,9 +662,11 @@ class BuildDecisionBookItems(CrudCollection):
occupant_type_list = OccupantTypes.filter_all(
OccupantTypes.occupant_code.in_(occupant_type_required_list),
system=True,
)
).data
# active_invite = invitations[1] if invitations[1] else invitations[0]
invitation = BuildDecisionBookInvitations.find_one(id=active_invite.id)
invitation = BuildDecisionBookInvitations.filter_one(
BuildDecisionBookInvitations.id == active_invite.id
).data
people_book_attend_count = None
if invitation.invitation_attempt == 1:
people_book_attend_is_attending = BuildDecisionBookPerson.filter_all(
@@ -702,26 +700,25 @@ class BuildDecisionBookItems(CrudCollection):
active=True,
is_payment_created=True,
)
occupant_type_pre = OccupantTypes.find_one(
occupant_code="MT-PRS", occupant_category_type="MT"
)
occupant_type_wrt = OccupantTypes.find_one(
occupant_code="MT-WRT", occupant_category_type="MT"
)
occupant_type_mng = OccupantTypes.find_one(
occupant_code="BU-MNG", occupant_category_type="BU"
)
occupant_type_pre = OccupantTypes.filter_by_one(
system=True, occupant_code="MT-PRS", occupant_category_type="MT"
).data
occupant_type_wrt = OccupantTypes.filter_by_one(
system=True, occupant_code="MT-WRT", occupant_category_type="MT"
).data
occupant_type_mng = OccupantTypes.filter_by_one(
system=True, occupant_code="BU-MNG", occupant_category_type="BU"
).data
person_occupants_pre = BuildDecisionBookPersonOccupants.find_one(
invite_id=invitation.id,
occupant_type_id=occupant_type_pre.id,
)
person_invite_pret = BuildDecisionBookPerson.find_one(
id=person_occupants_pre.build_decision_book_person_id
)
person = People.find_one(
id=person_invite_pret.person_id, active=True, is_confirmed=True
)
person_occupants_pre = BuildDecisionBookPersonOccupants.filter_one(
BuildDecisionBookPersonOccupants.invite_id == invitation.id,
BuildDecisionBookPersonOccupants.occupant_type_id == occupant_type_pre.id,
).data
person_invite_pret = BuildDecisionBookPerson.filter_one(
BuildDecisionBookPerson.id
== person_occupants_pre.build_decision_book_person_id
).data
person = People.filter_one(People.id == person_invite_pret.person_id).data
BuildDecisionBookItems.find_or_create(
**book_items_dict,
item_order=1,
@@ -732,16 +729,15 @@ class BuildDecisionBookItems(CrudCollection):
),
)
person_occupants_wrt = BuildDecisionBookPersonOccupants.find_one(
invite_id=invitation.id,
occupant_type_id=occupant_type_wrt.id,
)
person_invite_wrt = BuildDecisionBookPerson.find_one(
id=person_occupants_wrt.build_decision_book_person_id
)
person = People.find_one(
id=person_invite_pret.person_id, active=True, is_confirmed=True
)
person_occupants_wrt = BuildDecisionBookPersonOccupants.filter_one(
BuildDecisionBookPersonOccupants.invite_id == invitation.id,
BuildDecisionBookPersonOccupants.occupant_type_id == occupant_type_wrt.id,
).data
person_invite_wrt = BuildDecisionBookPerson.filter_one(
BuildDecisionBookPerson.id
== person_occupants_wrt.build_decision_book_person_id
).data
person = People.filter_one(People.id == person_invite_pret.person_id).data
BuildDecisionBookItems.find_or_create(
**book_items_dict,
item_order=2,
@@ -752,16 +748,15 @@ class BuildDecisionBookItems(CrudCollection):
),
)
person_occupants_mng = BuildDecisionBookPersonOccupants.find_one(
invite_id=invitation.id,
occupant_type_id=occupant_type_mng.id,
)
person_invite_mng = BuildDecisionBookPerson.find_one(
id=person_occupants_mng.build_decision_book_person_id
)
person = People.find_one(
id=person_invite_pret.person_id, active=True, is_confirmed=True
)
person_occupants_mng = BuildDecisionBookPersonOccupants.filter_one(
BuildDecisionBookPersonOccupants.invite_id == invitation.id,
BuildDecisionBookPersonOccupants.occupant_type_id == occupant_type_mng.id,
).data
person_invite_mng = BuildDecisionBookPerson.filter_one(
BuildDecisionBookPerson.id
== person_occupants_mng.build_decision_book_person_id
).data
person = People.filter_one(People.id == person_invite_pret.person_id).data
BuildDecisionBookItems.find_or_create(
**book_items_dict,
item_order=3,
@@ -795,23 +790,27 @@ class BuildDecisionBookItemsUnapproved(CrudCollection):
__tablename__ = "build_decision_book_items_unapproved"
__exclude__fields__ = []
item_objection = mapped_column(Text, nullable=False, comment="Objection Content")
item_order = mapped_column(SmallInteger, nullable=False, comment="Order Number")
item_objection: Mapped[str] = mapped_column(
Text, nullable=False, comment="Objection Content"
)
item_order: Mapped[int] = mapped_column(
SmallInteger, nullable=False, comment="Order Number"
)
decision_book_item_id = mapped_column(
decision_book_item_id: Mapped[int] = mapped_column(
ForeignKey("build_decision_book_items.id"), nullable=False
)
decision_book_item_uu_id = mapped_column(
decision_book_item_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Decision Book Item"
)
person_id: Mapped[int] = mapped_column(ForeignKey("people.id"), nullable=False)
person_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Person UUID"
)
build_decision_book_item = mapped_column(
build_decision_book_item: Mapped[int] = mapped_column(
ForeignKey("build_decision_book_items.id"), nullable=False
)
build_decision_book_item_uu_id = mapped_column(
build_decision_book_item_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Decision Book Item UUID"
)
@@ -833,11 +832,13 @@ class BuildDecisionBookPayments(CrudCollection):
__exclude__fields__ = []
__enum_list__ = [("receive_debit", "DebitTypes", "D")]
payment_plan_time_periods = mapped_column(
payment_plan_time_periods: Mapped[str] = mapped_column(
String(10), nullable=False, comment="Payment Plan Time Periods"
)
process_date = mapped_column(TIMESTAMP, nullable=False, comment="Payment Due Date")
payment_amount = mapped_column(
process_date: Mapped[TIMESTAMP] = mapped_column(
TIMESTAMP, nullable=False, comment="Payment Due Date"
)
payment_amount: Mapped[float] = mapped_column(
Numeric(16, 2), nullable=False, comment="Payment Amount"
)
currency: Mapped[str] = mapped_column(String(8), server_default="TRY")
@@ -853,20 +854,20 @@ class BuildDecisionBookPayments(CrudCollection):
process_date_y: Mapped[int] = mapped_column(SmallInteger)
process_date_m: Mapped[int] = mapped_column(SmallInteger)
build_decision_book_item_id = mapped_column(
build_decision_book_item_id: Mapped[int] = mapped_column(
ForeignKey("build_decision_book_items.id"),
nullable=False,
comment="Build Decision Book Item ID",
)
build_decision_book_item_uu_id = mapped_column(
build_decision_book_item_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Decision Book Item UUID"
)
decision_book_project_id = mapped_column(
decision_book_project_id: Mapped[int] = mapped_column(
ForeignKey("build_decision_book_projects.id"),
nullable=True,
comment="Decision Book Project ID",
)
decision_book_project_uu_id = mapped_column(
decision_book_project_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Decision Book Project UUID"
)
@@ -932,29 +933,37 @@ class BuildDecisionBookLegal(CrudCollection):
__tablename__ = "build_decision_book_legal"
__exclude__fields__ = []
period_start_date = mapped_column(
period_start_date: Mapped[TIMESTAMP] = mapped_column(
TIMESTAMP, nullable=False, comment="Start Date of Legal Period"
)
lawsuits_decision_number = mapped_column(
lawsuits_decision_number: Mapped[str] = mapped_column(
String, nullable=False, comment="Lawsuits Decision Number"
)
lawsuits_decision_date = mapped_column(
lawsuits_decision_date: Mapped[TIMESTAMP] = mapped_column(
TIMESTAMP, nullable=False, comment="Lawsuits Decision Date"
)
period_stop_date = mapped_column(TIMESTAMP, server_default="2099-12-31 23:59:59")
decision_book_pdf_path: Mapped[str] = mapped_column(String(128))
resp_company_total_wage: Mapped[float] = mapped_column(
Numeric(10, 2), server_default="0"
period_stop_date: Mapped[TIMESTAMP] = mapped_column(
TIMESTAMP, server_default="2099-12-31 23:59:59"
)
contact_agreement_path = mapped_column(String(128))
contact_agreement_date = mapped_column(
decision_book_pdf_path: Mapped[str] = mapped_column(
String, server_default="", nullable=True
)
resp_company_total_wage: Mapped[float] = mapped_column(
Numeric(10, 2), server_default="0", nullable=True
)
contact_agreement_path: Mapped[str] = mapped_column(
String, server_default="", nullable=True
)
contact_agreement_date: Mapped[TIMESTAMP] = mapped_column(
TIMESTAMP, server_default="1900-01-01 00:00:00", nullable=True
)
meeting_date: Mapped[str] = mapped_column(
TIMESTAMP, server_default="1900-01-01 00:00:00"
)
meeting_date = mapped_column(TIMESTAMP, server_default="1900-01-01 00:00:00")
lawsuits_type = mapped_column(String(1), server_default="C")
lawsuits_name = mapped_column(String(128))
lawsuits_note = mapped_column(String(512))
lawsuits_type: Mapped[str] = mapped_column(String(1), server_default="C")
lawsuits_name: Mapped[str] = mapped_column(String(128))
lawsuits_note: Mapped[str] = mapped_column(String(512))
lawyer_cost: Mapped[float] = mapped_column(Numeric(20, 2))
mediator_lawyer_cost: Mapped[float] = mapped_column(Numeric(20, 2))
other_cost: Mapped[float] = mapped_column(Numeric(20, 2))
@@ -962,22 +971,24 @@ class BuildDecisionBookLegal(CrudCollection):
approved_cost: Mapped[float] = mapped_column(Numeric(20, 2))
total_price: Mapped[float] = mapped_column(Numeric(20, 2))
build_db_item_id = mapped_column(
build_db_item_id: Mapped[int] = mapped_column(
ForeignKey("build_decision_book_items.id"), nullable=False
)
build_db_item_uu_id = mapped_column(
build_db_item_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Decision Book Item UUID"
)
resp_attorney_id: Mapped[int] = mapped_column(
ForeignKey("people.id"), nullable=False
)
resp_attorney_uu_id = mapped_column(String, nullable=True, comment="Attorney UUID")
resp_attorney_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Attorney UUID"
)
resp_attorney_company_id: Mapped[int] = mapped_column(ForeignKey("companies.id"))
resp_attorney_company_uu_id = mapped_column(
resp_attorney_company_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Company UUID"
)
mediator_lawyer_person_id: Mapped[int] = mapped_column(ForeignKey("people.id"))
mediator_lawyer_person_uu_id = mapped_column(
mediator_lawyer_person_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Mediator Lawyer UUID"
)
@@ -998,60 +1009,70 @@ class BuildDecisionBookProjects(CrudCollection):
__tablename__ = "build_decision_book_projects"
__exclude__fields__ = []
project_no = mapped_column(
project_no: Mapped[str] = mapped_column(
String(12), nullable=True, comment="Project Number of Decision Book"
)
project_name = mapped_column(String, nullable=False, comment="Project Name")
project_start_date = mapped_column(
project_name: Mapped[str] = mapped_column(
String, nullable=False, comment="Project Name"
)
project_start_date: Mapped[TIMESTAMP] = mapped_column(
TIMESTAMP, nullable=False, comment="Project Start Date"
)
project_stop_date = mapped_column(TIMESTAMP, server_default="2099-12-31 23:59:59")
project_type = mapped_column(String, server_default="C")
project_note = mapped_column(Text)
project_stop_date: Mapped[TIMESTAMP] = mapped_column(
TIMESTAMP, server_default="2099-12-31 23:59:59"
)
project_type: Mapped[str] = mapped_column(String, server_default="C")
project_note: Mapped[str] = mapped_column(Text)
decision_book_pdf_path = mapped_column(String)
decision_book_pdf_path: Mapped[str] = mapped_column(
String, server_default="", nullable=True
)
resp_company_fix_wage: Mapped[float] = mapped_column(
Numeric(10, 2), server_default="0"
)
is_out_sourced: Mapped[bool] = mapped_column(Boolean, server_default="0")
contact_id = mapped_column(
contact_id: Mapped[int] = mapped_column(
ForeignKey("contracts.id"), nullable=True, comment="Contract id"
)
contact_uu_id = mapped_column(String, nullable=True, comment="Contract UUID")
meeting_date = mapped_column(
contact_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Contract UUID"
)
meeting_date: Mapped[TIMESTAMP] = mapped_column(
TIMESTAMP, server_default="1900-01-01 00:00:00", index=True
)
currency = mapped_column(String(8), server_default="TRY")
currency: Mapped[float] = mapped_column(String(8), server_default="TRY")
bid_price: Mapped[float] = mapped_column(Numeric(16, 4), server_default="0")
approved_price: Mapped[float] = mapped_column(Numeric(16, 4), server_default="0")
final_price: Mapped[float] = mapped_column(Numeric(16, 4), server_default="0")
build_decision_book_id = mapped_column(
build_decision_book_id: Mapped[int] = mapped_column(
ForeignKey("build_decision_book.id"), nullable=False
)
build_decision_book_uu_id = mapped_column(
build_decision_book_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Decision Book UUID"
)
build_decision_book_item_id = mapped_column(
ForeignKey("build_decision_book_items.id"), nullable=False
)
build_decision_book_item_uu_id = mapped_column(
build_decision_book_item_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Decision Book Item UUID"
)
project_response_living_space_id = mapped_column(
project_response_living_space_id: Mapped[int] = mapped_column(
ForeignKey("build_living_space.id"),
nullable=True,
comment="Project Response Person ID",
)
project_response_living_space_uu_id = mapped_column(
project_response_living_space_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Project Response Person UUID"
)
resp_company_id: Mapped[int] = mapped_column(
ForeignKey("companies.id"), nullable=True
)
resp_company_uu_id = mapped_column(String, nullable=True, comment="Company UUID")
resp_company_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Company UUID"
)
build_decision_book_item: Mapped["BuildDecisionBookItems"] = relationship(
"BuildDecisionBookItems",
@@ -1070,9 +1091,7 @@ class BuildDecisionBookProjects(CrudCollection):
related_companies_ids = list(
related_.id for related_ in related_companies.all()
)
related_building = Build.filter_all(
Build.company_id.in_(related_companies_ids)
)
related_building = Build.filter_all(Build.company_id.in_(related_companies_ids))
related_building_ids = list(related_.id for related_ in related_building.data)
related_decision_books = BuildDecisionBook.filter_all(
BuildDecisionBook.build_id.in_(related_building_ids),
@@ -1153,30 +1172,30 @@ class BuildDecisionBookProjectPerson(CrudCollection):
__tablename__ = "build_decision_book_project_person"
__exclude__fields__ = []
__enum_list__ = [("management_typecode", "ProjectTeamTypes", "PTT-EMP")]
# __enum_list__ = [("management_typecode", "ProjectTeamTypes", "PTT-EMP")]
dues_percent_discount = mapped_column(SmallInteger, server_default="0")
dues_percent_discount: Mapped[int] = mapped_column(SmallInteger, server_default="0")
job_fix_wage: Mapped[float] = mapped_column(Numeric(10, 2), server_default="0")
bid_price: Mapped[float] = mapped_column(Numeric(10, 2), server_default="0")
decision_price: Mapped[float] = mapped_column(Numeric(10, 2), server_default="0")
build_decision_book_project_id = mapped_column(
build_decision_book_project_id: Mapped[int] = mapped_column(
ForeignKey("build_decision_book_projects.id"), nullable=False
)
build_decision_book_project_uu_id = mapped_column(
build_decision_book_project_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Decision Book Project UUID"
)
living_space_id: Mapped[int] = mapped_column(
ForeignKey("build_living_space.id"), nullable=False
)
living_space_uu_id = mapped_column(
living_space_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Living Space UUID"
)
project_team_type_id = mapped_column(
project_team_type_id: Mapped[int] = mapped_column(
ForeignKey("api_enum_dropdown.id"), nullable=True
)
project_team_type_uu_id = mapped_column(
project_team_type_uu_id: Mapped[str] = mapped_column(
String, nullable=True, comment="Management Type UUID"
)

View File

@@ -120,7 +120,7 @@ class CrudMixin(Base, SmartQueryMixin, SessionMixin, FilterAttributes):
key_ = cls.__annotations__.get(key, None)
is_primary, value_type = key in cls.primary_keys, type(val)
row_attr = bool(getattr(getattr(cls, key), "foreign_keys", None))
if is_primary or row_attr and key_ == Mapped[int]:
if is_primary or row_attr:
return False, None
elif val is None:
return True, None
@@ -136,12 +136,16 @@ class CrudMixin(Base, SmartQueryMixin, SessionMixin, FilterAttributes):
elif key_ == Mapped[int]:
return True, int(val)
elif key_ == Mapped[TIMESTAMP]:
return True, str(client_arrow.get(str(val)).format("DD-MM-YYYY HH:mm:ss"))
return True, str(
client_arrow.get(str(val)).format("DD-MM-YYYY HH:mm:ss")
)
elif key_ == Mapped[str]:
return True, str(val)
else:
if isinstance(val, datetime.datetime):
return True, str(client_arrow.get(str(val)).format("DD-MM-YYYY HH:mm:ss"))
return True, str(
client_arrow.get(str(val)).format("DD-MM-YYYY HH:mm:ss")
)
elif isinstance(value_type, bool):
return True, bool(val)
elif isinstance(value_type, float) or isinstance(value_type, Decimal):
@@ -241,12 +245,12 @@ class CrudMixin(Base, SmartQueryMixin, SessionMixin, FilterAttributes):
exclude_list = [
element
for element in self.__system_default_model__
if str(element)[-2:] == "id" and str(element)[-5:].lower() == 'uu_id'
if str(element)[-2:] == "id" and str(element)[-5:].lower() == "uu_id"
]
columns_include_list = list(set(include).difference(set(exclude_list)))
# columns_include_list.extend([column for column in self.columns if str(column)[-5:].lower() == 'uu_id'])
columns_include_list.extend(['uu_id'])
columns_include_list.extend(["uu_id"])
for key in list(columns_include_list):
val = getattr(self, key)
correct, value_of_database = self.iterate_over_variables(val, key)
@@ -265,7 +269,7 @@ class CrudMixin(Base, SmartQueryMixin, SessionMixin, FilterAttributes):
)
columns_excluded_list = list(set(self.columns).difference(set(exclude)))
# columns_excluded_list.extend([column for column in self.columns if str(column)[-5:].lower() == 'uu_id'])
columns_excluded_list.extend(['uu_id', 'active'])
columns_excluded_list.extend(["uu_id", "active"])
for key in list(columns_excluded_list):
val = getattr(self, key)
@@ -280,7 +284,13 @@ class CrudMixin(Base, SmartQueryMixin, SessionMixin, FilterAttributes):
columns_list = [
columns for columns in columns_list if str(columns)[-2:] != "id"
]
columns_list.extend([column for column in self.columns if str(column)[-5:].lower() == 'uu_id'])
columns_list.extend(
[
column
for column in self.columns
if str(column)[-5:].lower() == "uu_id"
]
)
for remove_field in self.__system_default_model__:
if remove_field in columns_list:
columns_list.remove(remove_field)

View File

@@ -68,9 +68,7 @@ class Modules(CrudCollection):
is_default_module = mapped_column(Boolean, server_default="0")
def retrieve_services(self):
services = Services.filter_all(
Services.module_id == self.id
).data
services = Services.filter_all(Services.module_id == self.id).data
if not services:
self.raise_http_exception(
status_code="HTTP_404_NOT_FOUND",
@@ -145,13 +143,9 @@ class Event2Employee(CrudCollection):
@classmethod
def get_event_id_by_employee_id(cls, employee_id) -> (list, list):
active_events = cls.filter_all(
cls.employee_id == employee_id
)
active_events = cls.filter_all(cls.employee_id == employee_id)
active_events_id = [event.event_id for event in active_events.data]
active_events = Events.filter_all(
Events.id.in_(active_events_id)
)
active_events = Events.filter_all(Events.id.in_(active_events_id))
active_events_uu_id = [str(event.uu_id) for event in active_events.data]
return active_events_id, active_events_uu_id
@@ -191,9 +185,7 @@ class Event2Occupant(CrudCollection):
cls.build_living_space_id == build_living_space_id,
).data
active_events_id = [event.event_id for event in active_events]
active_events = Events.filter_all(
Events.id.in_(active_events_id)
).data
active_events = Events.filter_all(Events.id.in_(active_events_id)).data
active_events_uu_id = [str(event.uu_id) for event in active_events]
return active_events_id, active_events_uu_id

View File

@@ -136,10 +136,11 @@ class Users(CrudCollection, UserLoginModule, SelectAction):
return getattr(self.priority, "priority_code", 0) == 0
@classmethod
def create_action(cls, create_user: InsertUsers):
def create_action(cls, create_user: InsertUsers, token_dict):
found_person = People.filter_one(
People.uu_id == create_user.people_uu_id,
).data
if not found_person:
raise HTTPException(status_code=400, detail="Person not found.")
if (
@@ -156,8 +157,9 @@ class Users(CrudCollection, UserLoginModule, SelectAction):
del create_dict["people_uu_id"]
create_dict["person_id"] = found_person.id
create_dict["person_uu_id"] = str(found_person.uu_id)
create_dict["related_company"] = token_dict.selected_company.company_uu_id
created_user = cls.find_or_create(**create_dict)
created_user.reset_password_token()
created_user.reset_password_token(found_user=created_user)
return created_user
@classmethod
@@ -182,7 +184,7 @@ class Users(CrudCollection, UserLoginModule, SelectAction):
from databases import Employees, Duties
found_person = People.filter_one(
People.id==self.person_id,
People.id == self.person_id,
)
found_employees = Employees.filter_by_active(
people_id=found_person.id, is_confirmed=True
@@ -416,8 +418,12 @@ class AddressPostcode(CrudCollection, SelectActionWithEmployee):
__many__table__ = RelationshipEmployee2PostCode
street_id: Mapped[int] = mapped_column(ForeignKey("address_street.id"))
street_uu_id: Mapped[str] = mapped_column(String, server_default="", comment="Street UUID")
postcode: Mapped[str] = mapped_column(String(32), nullable=False, comment="Postcode")
street_uu_id: Mapped[str] = mapped_column(
String, server_default="", comment="Street UUID"
)
postcode: Mapped[str] = mapped_column(
String(32), nullable=False, comment="Postcode"
)
__table_args__ = ({"comment": "Postcode Information"},)
@@ -456,10 +462,12 @@ class Addresses(CrudCollection):
street_id: Mapped[int] = mapped_column(
ForeignKey("address_street.id"), nullable=False
)
street_uu_id: Mapped[str] = mapped_column(String, server_default="", comment="Street UUID")
street_uu_id: Mapped[str] = mapped_column(
String, server_default="", comment="Street UUID"
)
@classmethod
def list_via_employee(cls, token_dict, filter_expr = None):
def list_via_employee(cls, token_dict, filter_expr=None):
post_code_list = RelationshipEmployee2PostCode.filter_all(
RelationshipEmployee2PostCode.employee_id
== token_dict.selected_company.employee_id,
@@ -470,9 +478,7 @@ class Addresses(CrudCollection):
status_code=404,
detail="User has no post code registered. User can not list addresses.",
)
cls.pre_query = cls.filter_all(
cls.post_code_id.in_(post_code_id_list)
).query
cls.pre_query = cls.filter_all(cls.post_code_id.in_(post_code_id_list)).query
filter_cls = cls.filter_all(*filter_expr or [])
cls.pre_query = None
return filter_cls.data
@@ -527,9 +533,15 @@ class AddressGeographicLocations(CrudCollection):
__tablename__ = "address_geographic_locations"
__exclude__fields__ = []
geo_table: Mapped[str] = mapped_column(String, nullable=False, comment="Address Table Name")
geo_id: Mapped[int] = mapped_column(Integer, nullable=False, comment="Address Table ID")
geo_name: Mapped[str] = mapped_column(String, nullable=False, comment="Geographic Location Name")
geo_table: Mapped[str] = mapped_column(
String, nullable=False, comment="Address Table Name"
)
geo_id: Mapped[int] = mapped_column(
Integer, nullable=False, comment="Address Table ID"
)
geo_name: Mapped[str] = mapped_column(
String, nullable=False, comment="Geographic Location Name"
)
geo_latitude: Mapped[float] = mapped_column(
Numeric(20, 6), server_default="0", comment="Geographic Location Name"
)
@@ -572,10 +584,18 @@ class AddressCountry(CrudCollection):
__tablename__ = "address_country"
__exclude__fields__ = []
country_code: Mapped[str] = mapped_column(String(16), nullable=False, comment="Country Code")
country_name: Mapped[str] = mapped_column(String, nullable=False, comment="Country Name")
money_code: Mapped[str] = mapped_column(String(12), nullable=True, comment="Money Code")
language: Mapped[str] = mapped_column(String, nullable=True, comment="Language Code")
country_code: Mapped[str] = mapped_column(
String(16), nullable=False, comment="Country Code"
)
country_name: Mapped[str] = mapped_column(
String, nullable=False, comment="Country Name"
)
money_code: Mapped[str] = mapped_column(
String(12), nullable=True, comment="Money Code"
)
language: Mapped[str] = mapped_column(
String, nullable=True, comment="Language Code"
)
address_geographic_id: Mapped[int] = mapped_column(
BigInteger, nullable=True, comment="Address Geographic Id"
)
@@ -595,17 +615,29 @@ class AddressState(CrudCollection):
__tablename__ = "address_state"
__exclude__fields__ = []
state_code: Mapped[str] = mapped_column(String(16), nullable=False, comment="State Code")
state_name: Mapped[str] = mapped_column(String, nullable=False, comment="State Name")
licence_plate: Mapped[str] = mapped_column(String(24), nullable=True, comment="Sign Code")
phone_code: Mapped[str] = mapped_column(String(36), nullable=True, comment="Phone Code")
gov_code: Mapped[str] = mapped_column(String(128), nullable=True, comment="Government Code")
state_code: Mapped[str] = mapped_column(
String(16), nullable=False, comment="State Code"
)
state_name: Mapped[str] = mapped_column(
String, nullable=False, comment="State Name"
)
licence_plate: Mapped[str] = mapped_column(
String(24), nullable=True, comment="Sign Code"
)
phone_code: Mapped[str] = mapped_column(
String(36), nullable=True, comment="Phone Code"
)
gov_code: Mapped[str] = mapped_column(
String(128), nullable=True, comment="Government Code"
)
address_geographic_id: Mapped[int] = mapped_column(
BigInteger, nullable=True, comment="Address Geographic Id"
)
country_id: Mapped[int] = mapped_column(ForeignKey("address_country.id"))
country_uu_id: Mapped[str] = mapped_column(String, server_default="", comment="Country UUID")
country_uu_id: Mapped[str] = mapped_column(
String, server_default="", comment="Country UUID"
)
__table_args__ = (
Index(
@@ -626,17 +658,27 @@ class AddressCity(CrudCollection):
__tablename__ = "address_city"
__exclude__fields__ = []
city_code: Mapped[str] = mapped_column(String(24), nullable=False, comment="City Code")
city_code: Mapped[str] = mapped_column(
String(24), nullable=False, comment="City Code"
)
city_name: Mapped[str] = mapped_column(String, nullable=False, comment="City Name")
licence_plate: Mapped[str] = mapped_column(String(24), nullable=True, comment="Sign Code")
phone_code: Mapped[str] = mapped_column(String(36), nullable=True, comment="Phone Code")
gov_code: Mapped[str] = mapped_column(String(128), nullable=True, comment="Government Code")
licence_plate: Mapped[str] = mapped_column(
String(24), nullable=True, comment="Sign Code"
)
phone_code: Mapped[str] = mapped_column(
String(36), nullable=True, comment="Phone Code"
)
gov_code: Mapped[str] = mapped_column(
String(128), nullable=True, comment="Government Code"
)
address_geographic_id: Mapped[int] = mapped_column(
BigInteger, nullable=True, comment="Address Geographic Id"
)
state_id: Mapped[int] = mapped_column(ForeignKey("address_state.id"))
state_uu_id: Mapped[str] = mapped_column(String, server_default="", comment="State UUID")
state_uu_id: Mapped[str] = mapped_column(
String, server_default="", comment="State UUID"
)
__table_args__ = (
Index(
@@ -657,10 +699,18 @@ class AddressDistrict(CrudCollection):
__tablename__ = "address_district"
__exclude__fields__ = []
district_code: Mapped[str] = mapped_column(String(16), nullable=False, comment="District Code")
district_name: Mapped[str] = mapped_column(String, nullable=False, comment="District Name")
phone_code: Mapped[str] = mapped_column(String(36), nullable=True, comment="Phone Code")
gov_code: Mapped[str] = mapped_column(String(128), nullable=True, comment="Government Code")
district_code: Mapped[str] = mapped_column(
String(16), nullable=False, comment="District Code"
)
district_name: Mapped[str] = mapped_column(
String, nullable=False, comment="District Name"
)
phone_code: Mapped[str] = mapped_column(
String(36), nullable=True, comment="Phone Code"
)
gov_code: Mapped[str] = mapped_column(
String(128), nullable=True, comment="Government Code"
)
address_geographic_id: Mapped[int] = mapped_column(
BigInteger, nullable=True, comment="Address Geographic Id"
)
@@ -668,7 +718,9 @@ class AddressDistrict(CrudCollection):
city_id: Mapped[int] = mapped_column(
ForeignKey("address_city.id"), nullable=False, comment="City ID"
)
city_uu_id: Mapped[str] = mapped_column(String, server_default="", comment="City UUID")
city_uu_id: Mapped[str] = mapped_column(
String, server_default="", comment="City UUID"
)
__table_args__ = (
Index(
@@ -689,11 +741,19 @@ class AddressLocality(CrudCollection):
__tablename__ = "address_locality"
__exclude__fields__ = []
locality_code: Mapped[str] = mapped_column(String(16), nullable=False, comment="Locality Code")
locality_name: Mapped[str] = mapped_column(String, nullable=False, comment="Locality Name")
locality_code: Mapped[str] = mapped_column(
String(16), nullable=False, comment="Locality Code"
)
locality_name: Mapped[str] = mapped_column(
String, nullable=False, comment="Locality Name"
)
type_code: Mapped[str] = mapped_column(String, nullable=True, comment="Type Name")
type_description: Mapped[str] = mapped_column(String, nullable=True, comment="Type Name")
gov_code: Mapped[str] = mapped_column(String(128), nullable=True, comment="Government Code")
type_description: Mapped[str] = mapped_column(
String, nullable=True, comment="Type Name"
)
gov_code: Mapped[str] = mapped_column(
String(128), nullable=True, comment="Government Code"
)
address_show: Mapped[bool] = mapped_column(Boolean, server_default="1")
address_geographic_id: Mapped[int] = mapped_column(
BigInteger, nullable=True, comment="Address Geographic Id"
@@ -702,7 +762,9 @@ class AddressLocality(CrudCollection):
district_id: Mapped[int] = mapped_column(
ForeignKey("address_district.id"), nullable=False, comment="District ID"
)
district_uu_id: Mapped[str] = mapped_column(String, server_default="", comment="District UUID")
district_uu_id: Mapped[str] = mapped_column(
String, server_default="", comment="District UUID"
)
__table_args__ = (
Index(
@@ -730,8 +792,12 @@ class AddressNeighborhood(CrudCollection):
String, nullable=False, comment="Neighborhood Name"
)
type_code: Mapped[str] = mapped_column(String, nullable=True, comment="Type Name")
type_description: Mapped[str] = mapped_column(String, nullable=True, comment="Type Name")
gov_code: Mapped[str] = mapped_column(String(128), nullable=True, comment="Government Code")
type_description: Mapped[str] = mapped_column(
String, nullable=True, comment="Type Name"
)
gov_code: Mapped[str] = mapped_column(
String(128), nullable=True, comment="Government Code"
)
address_show: Mapped[bool] = mapped_column(Boolean, server_default="1")
address_geographic_id: Mapped[int] = mapped_column(
BigInteger, nullable=True, comment="Address Geographic Id"
@@ -740,11 +806,15 @@ class AddressNeighborhood(CrudCollection):
district_id: Mapped[int] = mapped_column(
ForeignKey("address_district.id"), nullable=True, comment="District ID"
)
district_uu_id: Mapped[str] = mapped_column(String, server_default="", comment="District UUID")
district_uu_id: Mapped[str] = mapped_column(
String, server_default="", comment="District UUID"
)
locality_id: Mapped[int] = mapped_column(
ForeignKey("address_locality.id"), nullable=True, comment="Locality ID"
)
locality_uu_id: Mapped[str] = mapped_column(String, server_default="", comment="Locality UUID")
locality_uu_id: Mapped[str] = mapped_column(
String, server_default="", comment="Locality UUID"
)
__table_args__ = (
Index(
@@ -765,11 +835,19 @@ class AddressStreet(CrudCollection):
__tablename__ = "address_street"
__exclude__fields__ = []
street_code: Mapped[str] = mapped_column(String(16), nullable=False, comment="Street Code")
street_name: Mapped[str] = mapped_column(String, nullable=False, comment="Street Name")
street_code: Mapped[str] = mapped_column(
String(16), nullable=False, comment="Street Code"
)
street_name: Mapped[str] = mapped_column(
String, nullable=False, comment="Street Name"
)
type_code: Mapped[str] = mapped_column(String, nullable=True, comment="Type Name")
type_description: Mapped[str] = mapped_column(String, nullable=True, comment="Type Name")
gov_code: Mapped[str] = mapped_column(String(128), nullable=True, comment="Government Code")
type_description: Mapped[str] = mapped_column(
String, nullable=True, comment="Type Name"
)
gov_code: Mapped[str] = mapped_column(
String(128), nullable=True, comment="Government Code"
)
address_geographic_id: Mapped[int] = mapped_column(
BigInteger, nullable=True, comment="Address Geographic Id"
@@ -858,7 +936,9 @@ class OccupantTypes(CrudCollection):
__tablename__ = "occupant_types"
__exclude__fields__ = []
occupant_type: Mapped[str] = mapped_column(String, nullable=False, comment="Occupant Type")
occupant_type: Mapped[str] = mapped_column(
String, nullable=False, comment="Occupant Type"
)
occupant_description: Mapped[str] = mapped_column(String, server_default="")
occupant_code: Mapped[str] = mapped_column(String, server_default="")
occupant_category: Mapped[str] = mapped_column(String, server_default="")
@@ -908,11 +988,19 @@ class Contracts(CrudCollection):
"expire start is the start date of the contract, expire en is the end date of the contract.",
)
company_id: Mapped[int] = mapped_column(Integer, ForeignKey("companies.id"), nullable=True)
company_uu_id: Mapped[str] = mapped_column(String, server_default="", comment="Company UUID")
company_id: Mapped[int] = mapped_column(
Integer, ForeignKey("companies.id"), nullable=True
)
company_uu_id: Mapped[str] = mapped_column(
String, server_default="", comment="Company UUID"
)
person_id: Mapped[int] = mapped_column(Integer, ForeignKey("people.id"), nullable=True)
person_uu_id: Mapped[str] = mapped_column(String, server_default="", comment="Person UUID")
person_id: Mapped[int] = mapped_column(
Integer, ForeignKey("people.id"), nullable=True
)
person_uu_id: Mapped[str] = mapped_column(
String, server_default="", comment="Person UUID"
)
@classmethod
def retrieve_contact_no(cls):

View File

@@ -37,7 +37,9 @@ class ApiEnumDropdown(CrudCollection):
def get_debit_search(cls, search_debit: str = None, search_uu_id: str = None):
if search_uu_id:
if search := cls.filter_one(
cls.enum_class.in_(["DebitTypes"]), cls.uu_id == search_uu_id, system=True
cls.enum_class.in_(["DebitTypes"]),
cls.uu_id == search_uu_id,
system=True,
).data:
return search
elif search_debit:
@@ -45,16 +47,14 @@ class ApiEnumDropdown(CrudCollection):
cls.enum_class.in_(["DebitTypes"]), cls.key == search_debit, system=True
).data:
return search
return cls.filter_all(
cls.enum_class.in_(["DebitTypes"]), system=True
).data
return cls.filter_all(cls.enum_class.in_(["DebitTypes"]), system=True).data
@classmethod
def get_due_types(cls):
if due_list := cls.filter_all(
cls.enum_class == "BuildDuesTypes",
cls.key.in_(["BDT-A", "BDT-D"]),
system=True
system=True,
).data:
return [due.uu_id.__str__() for due in due_list]
raise HTTPException(
@@ -66,20 +66,19 @@ class ApiEnumDropdown(CrudCollection):
def due_type_search(cls, search_management: str = None, search_uu_id: str = None):
if search_uu_id:
if search := cls.filter_one(
cls.enum_class.in_(["BuildDuesTypes"]), cls.uu_id == search_uu_id,
system=True
cls.enum_class.in_(["BuildDuesTypes"]),
cls.uu_id == search_uu_id,
system=True,
).data:
return search
elif search_management:
if search := cls.filter_one(
cls.enum_class.in_(["BuildDuesTypes"]), cls.key == search_management,
system=True
cls.enum_class.in_(["BuildDuesTypes"]),
cls.key == search_management,
system=True,
).data:
return search
return cls.filter_all(
cls.enum_class.in_(["BuildDuesTypes"]),
system=True
).data
return cls.filter_all(cls.enum_class.in_(["BuildDuesTypes"]), system=True).data
def get_enum_dict(self):
return {
@@ -94,7 +93,9 @@ class ApiEnumDropdown(CrudCollection):
def uuid_of_enum(cls, enum_class: str, key: str):
return str(
getattr(
cls.filter_one(cls.enum_class == enum_class, cls.key == key, system=True).data,
cls.filter_one(
cls.enum_class == enum_class, cls.key == key, system=True
).data,
"uu_id",
None,
)

View File

@@ -10,7 +10,7 @@ engine_config = {
"pool_size": 10,
"max_overflow": 0,
"echo": False,
"isolation_level": "READ COMMITTED"
"isolation_level": "READ COMMITTED",
}
engine = create_engine(**engine_config)

View File

@@ -20,7 +20,7 @@ class FilterAttributes:
__session__ = Base.session # The session to use in the model.
pre_query = None # The query to use before the filtering such as: query = cls.query.filter_by(active=True)
total_count = None # The query to use before the filtering such as: query = cls.query.filter_by(active=True)
total_count = None # The query to use before the filtering such as: query = cls.query.filter_by(active=True)
filter_attr = None # The filter attributes to use in the model.
FilterModel = ListOptions
@@ -56,6 +56,20 @@ class FilterAttributes:
message=str(e.__context__).split("\n")[0],
)
@classmethod
def save_and_confirm(cls):
"""Saves the updated model to the current entity db."""
try:
cls.is_confirmed = True
cls.__session__.commit()
except SQLAlchemyError as e:
cls.raise_http_exception(
status_code="HTTP_400_BAD_REQUEST",
error_case=e.__class__.__name__,
data={},
message=str(e.__context__).split("\n")[0],
)
@classmethod
def _query(cls):
"""Returns the query to use in the model."""
@@ -124,15 +138,9 @@ class FilterAttributes:
@classmethod
def get_active_and_confirmed_query_arg(cls, arg):
"""Add active and confirmed to the query."""
arg = cls.add_new_arg_to_args(
arg, "is_confirmed", cls.is_confirmed == True
)
arg = cls.add_new_arg_to_args(
arg, "active", cls.active == True
)
arg = cls.add_new_arg_to_args(
arg, "deleted", cls.deleted == False
)
arg = cls.add_new_arg_to_args(arg, "is_confirmed", cls.is_confirmed == True)
arg = cls.add_new_arg_to_args(arg, "active", cls.active == True)
arg = cls.add_new_arg_to_args(arg, "deleted", cls.deleted == False)
return arg
@classmethod
@@ -190,7 +198,7 @@ class FilterAttributes:
args = cls.get_not_expired_query_arg(args)
filter_list = cls.get_filter_attributes()
if filter_list.get("query", None):
for smart_iter in cls.filter_expr(**filter_list.get('query', {})):
for smart_iter in cls.filter_expr(**filter_list.get("query", {})):
if key := arg_left(smart_iter):
args = cls.add_new_arg_to_args(args, key, smart_iter)
query = cls._query().filter(*args)