diff --git a/ApiValidations/Request/__init__.py b/ApiValidations/Request/__init__.py index 0233ace..d312c43 100644 --- a/ApiValidations/Request/__init__.py +++ b/ApiValidations/Request/__init__.py @@ -4,10 +4,236 @@ from .base_validations import ( ListOptions, CrudRecords, ) +from .address import ( + InsertAddress, + UpdateAddress, + UpdatePostCode, + InsertPostCode, + SearchAddress, +) +from .application import ( + SingleEnumUUID, + SingleEnumClassKey, + SingleEnumOnlyClass, + SingleOccupantTypeUUID, + SingleOccupantTypeClassKey, +) +from .area import ( + InsertBuildArea, + InsertBuildSites, + UpdateBuildArea, + UpdateBuildSites, +) +from .authentication import ( + Login, + Logout, + ChangePassword, + Remember, + Forgot, + CreatePassword, + OccupantSelection, + EmployeeSelection, +) +from .account_records import ( + InsertAccountRecord, + UpdateAccountRecord, +) + +from .build_living_space import ( + InsertBuildLivingSpace, + UpdateBuildLivingSpace, +) +from .build_part import ( + InsertBuildParts, + InsertBuildTypes, + UpdateBuildParts, + UpdateBuildTypes, +) +from .building import ( + InsertBuild, + UpdateBuild, +) +from .company import ( + MatchCompany2Company, + InsertCompany, + UpdateCompany, +) +from .decision_book import ( + DecisionBookDecisionBookInvitations, + DecisionBookDecisionBookInvitationsUpdate, + DecisionBookDecisionBookInvitationsAttend, + DecisionBookDecisionBookInvitationsAssign, + UpdateDecisionBook, + UpdateBuildDecisionBookItems, + UpdateBuildDecisionBookItemDebits, + InsertBuildDecisionBookItems, + InsertBuildDecisionBookItemDebits, + InsertDecisionBookCompleted, + InsertDecisionBook, + InsertDecisionBookPerson, + ListDecisionBook, + RemoveDecisionBookPerson, +) +from .departments import ( + DepartmentsPydantic, +) +from .employee import ( + InsertDuties, + UpdateDuties, + InsertEmployees, + SelectDuties, + UnBindEmployees2People, + BindEmployees2People, + UpdateCompanyEmployees, + InsertCompanyEmployees, + InsertCompanyEmployeesSalaries, + InsertCompanyDuty, + UpdateCompanyEmployeesSalaries, + UpdateCompanyDuty, +) +from .events import ( + # CreateEvents, + RegisterEvents2Employee, + RegisterEvents2Occupant, +) +from .people import ( + UpdatePerson, + InsertPerson, +) +from .project_decision_book import ( + InsertBuildDecisionBookProjectItemDebits, + UpdateBuildDecisionBookProjectItemDebits, + InsertBuildDecisionBookProjects, + UpdateBuildDecisionBookProjects, + InsertBuildDecisionBookProjectPerson, + UpdateBuildDecisionBookProjectPerson, + InsertBuildDecisionBookProjectItems, + UpdateBuildDecisionBookProjectItems, + ApprovalsBuildDecisionBookProjects, +) +from .rules import ( + UpdateEndpointAccess, + UpdateEndpointAccessList, + InsertEndpointAccess, + CheckEndpointAccess, +) +from .services import ( + RegisterServices2Employee, + RegisterServices2Occupant, +) +from .staff import ( + InsertStaff, + SelectStaff, +) +from .user import ( + InsertUsers, + UpdateUsers, + QueryUsers, + # ActiveUsers, + # ListUsers, + # DeleteUsers, +) +from .modules import ( + RegisterModules2Occupant, + RegisterModules2Employee, +) + __all__ = [ "BaseModelRegular", "PydanticBaseModel", "ListOptions", "CrudRecords", + "ListOptions", + "CrudRecords", + "PydanticBaseModel", + "BaseModelRegular", + "InsertAddress", + "UpdateAddress", + "UpdatePostCode", + "InsertPostCode", + "SearchAddress", + "SingleEnumUUID", + "SingleEnumClassKey", + "SingleEnumOnlyClass", + "SingleOccupantTypeUUID", + "SingleOccupantTypeClassKey", + "InsertBuildArea", + "InsertBuildSites", + "UpdateBuildArea", + "UpdateBuildSites", + "Login", + "Logout", + "ChangePassword", + "Remember", + "Forgot", + "CreatePassword", + "OccupantSelection", + "EmployeeSelection", + "InsertAccountRecord", + "UpdateAccountRecord", + "InsertBuildLivingSpace", + "UpdateBuildLivingSpace", + "InsertBuildParts", + "InsertBuildTypes", + "UpdateBuildParts", + "UpdateBuildTypes", + "InsertBuild", + "UpdateBuild", + "MatchCompany2Company", + "InsertCompany", + "UpdateCompany", + "DecisionBookDecisionBookInvitations", + "DecisionBookDecisionBookInvitationsUpdate", + "DecisionBookDecisionBookInvitationsAttend", + "DecisionBookDecisionBookInvitationsAssign", + "UpdateDecisionBook", + "UpdateBuildDecisionBookItems", + "UpdateBuildDecisionBookItemDebits", + "InsertBuildDecisionBookItems", + "InsertBuildDecisionBookItemDebits", + "InsertDecisionBookCompleted", + "InsertDecisionBook", + "InsertDecisionBookPerson", + "ListDecisionBook", + "RemoveDecisionBookPerson", + "DepartmentsPydantic", + "InsertDuties", + "UpdateDuties", + "InsertEmployees", + "SelectDuties", + "UnBindEmployees2People", + "BindEmployees2People", + "UpdateCompanyEmployees", + "InsertCompanyEmployees", + "InsertCompanyEmployeesSalaries", + "InsertCompanyDuty", + "UpdateCompanyEmployeesSalaries", + "UpdateCompanyDuty", + "RegisterEvents2Employee", + "RegisterEvents2Occupant", + "UpdatePerson", + "InsertPerson", + "InsertBuildDecisionBookProjectItems", + "UpdateBuildDecisionBookProjectItems", + "ApprovalsBuildDecisionBookProjects", + "InsertBuildDecisionBookProjectItemDebits", + "UpdateBuildDecisionBookProjectItemDebits", + "InsertBuildDecisionBookProjects", + "UpdateBuildDecisionBookProjects", + "InsertBuildDecisionBookProjectPerson", + "UpdateBuildDecisionBookProjectPerson", + "UpdateEndpointAccess", + "UpdateEndpointAccessList", + "InsertEndpointAccess", + "CheckEndpointAccess", + "RegisterServices2Employee", + "RegisterServices2Occupant", + "InsertStaff", + "SelectStaff", + "InsertUsers", + "UpdateUsers", + "QueryUsers", + "RegisterModules2Occupant", + "RegisterModules2Employee", ] diff --git a/ApiValidations/Request/account_records.py b/ApiValidations/Request/account_records.py new file mode 100644 index 0000000..69a4754 --- /dev/null +++ b/ApiValidations/Request/account_records.py @@ -0,0 +1,162 @@ +from api_validations.core_validations import BaseModelRegular +from api_validations.validations_request import ( + PydanticBaseModel, +) +from typing import Optional + + +class AccountValidation: + tr = { + "iban": "IBAN Numarası", + "bank_date": "Bank Tarih", + "currency_value": "Para Değeri", + "bank_balance": "Banka Bakiye", + "currency": "Para Birimi", + "additional_balance": "Ek Bakiye", + "channel_branch": "Kanal Şubesi", + "process_name": "İşlem Adı", + "process_type": "İşlem Tipi", + "process_comment": "İşlem Yorum", + "bank_reference_code": "Banka Referans Kodu", + "add_comment_note": "Yorum Not", + "is_receipt_mail_send": "Fiş Mail Gönderildi", + "found_from": "Bulunduğu Yer", + "similarity": "Benzerlik", + "remainder_balance": "Kalan Bakiye", + "bank_date_y": "Bank Tarih Yıl", + "bank_date_m": "Bank Tarih Ay", + "bank_date_w": "Bank Tarih Hafta", + "bank_date_d": "Bank Tarih Gün", + "approving_accounting_record": "Onaylayan Muhasebe Kaydı", + "accounting_receipt_date": "Muhasebe Fiş Tarihi", + "accounting_receipt_number": "Muhasebe Fiş Numarası", + "approved_record": "Onaylanmış Kayıt", + "import_file_name": "İçe Aktarım Dosya Adı", + "receive_debit_uu_id": "Alacak UUID", + "budget_type_uu_id": "Bütçe Tipi UUID", + "company_uu_id": "Şirket UUID", + "send_company_uu_id": "Gönderen Şirket UUID", + "customer_id": "Müşteri ID", + "customer_uu_id": "Müşteri UUID", + "send_person_uu_id": "Gönderen Kişi UUID", + "approving_accounting_person_uu_id": "Onaylayan Muhasebe Kişi UUID", + "build_parts_uu_id": "Daire UUID", + "build_decision_book_uu_id": "Karar Defteri UUID", + } + en = { + "iban": "IBAN Number", + "bank_date": "Bank Date", + "currency_value": "Currency Value", + "bank_balance": "Bank Balance", + "currency": "Currency", + "additional_balance": "Additional Balance", + "channel_branch": "Channel Branch", + "process_name": "Process Name", + "process_type": "Process Type", + "process_comment": "Process Comment", + "bank_reference_code": "Bank Reference Code", + "add_comment_note": "Comment Note", + "is_receipt_mail_send": "Receipt Mail Send", + "found_from": "Found From", + "similarity": "Similarity", + "remainder_balance": "Remainder Balance", + "bank_date_y": "Bank Date Year", + "bank_date_m": "Bank Date Month", + "bank_date_w": "Bank Date Week", + "bank_date_d": "Bank Date Day", + "approving_accounting_record": "Approving Accounting Record", + "accounting_receipt_date": "Accounting Receipt Date", + "accounting_receipt_number": "Accounting Receipt Number", + "approved_record": "Approved Record", + "import_file_name": "Import File Name", + "receive_debit_uu_id": "Receive Debit UUID", + "budget_type_uu_id": "Budget Type UUID", + "company_uu_id": "Company UUID", + "send_company_uu_id": "Send Company UUID", + "customer_id": "Customer ID", + "customer_uu_id": "Customer UUID", + "send_person_uu_id": "Send Person UUID", + "approving_accounting_person_uu_id": "Approving Accounting Person UUID", + "build_parts_uu_id": "Build Parts UUID", + "build_decision_book_uu_id": "Build Decision Book UUID", + } + + +class InsertAccountRecord(BaseModelRegular, AccountValidation): + + iban: str + bank_date: str + currency_value: float + bank_balance: float + currency: str + additional_balance: float + channel_branch: str + process_name: str + process_type: str + process_comment: str + bank_reference_code: str + + add_comment_note: Optional[str] = None + is_receipt_mail_send: Optional[bool] = None + found_from: Optional[str] = None + similarity: Optional[float] = None + remainder_balance: Optional[float] = None + bank_date_y: Optional[int] = None + bank_date_m: Optional[int] = None + bank_date_w: Optional[int] = None + bank_date_d: Optional[int] = None + approving_accounting_record: Optional[bool] = None + accounting_receipt_date: Optional[str] = None + accounting_receipt_number: Optional[int] = None + approved_record: Optional[bool] = None + import_file_name: Optional[str] = None + # receive_debit_uu_id: Optional[str] = None + budget_type_uu_id: Optional[str] = None + company_uu_id: Optional[str] = None + send_company_uu_id: Optional[str] = None + customer_id: Optional[str] = None + customer_uu_id: Optional[str] = None + send_person_uu_id: Optional[str] = None + approving_accounting_person_uu_id: Optional[str] = None + build_parts_uu_id: Optional[str] = None + build_decision_book_uu_id: Optional[str] = None + + +class UpdateAccountRecord(PydanticBaseModel, AccountValidation): + + iban: Optional[str] = None + bank_date: Optional[str] = None + currency_value: Optional[float] = None + bank_balance: Optional[float] = None + currency: Optional[str] = None + additional_balance: Optional[float] = None + channel_branch: Optional[str] = None + process_name: Optional[str] = None + process_type: Optional[str] = None + process_comment: Optional[str] = None + bank_reference_code: Optional[str] = None + + add_comment_note: Optional[str] = None + is_receipt_mail_send: Optional[bool] = None + found_from: Optional[str] = None + similarity: Optional[float] = None + remainder_balance: Optional[float] = None + bank_date_y: Optional[int] = None + bank_date_m: Optional[int] = None + bank_date_w: Optional[int] = None + bank_date_d: Optional[int] = None + approving_accounting_record: Optional[bool] = None + accounting_receipt_date: Optional[str] = None + accounting_receipt_number: Optional[int] = None + approved_record: Optional[bool] = None + import_file_name: Optional[str] = None + receive_debit_uu_id: Optional[str] = None + budget_type_uu_id: Optional[str] = None + company_uu_id: Optional[str] = None + send_company_uu_id: Optional[str] = None + customer_id: Optional[str] = None + customer_uu_id: Optional[str] = None + send_person_uu_id: Optional[str] = None + approving_accounting_person_uu_id: Optional[str] = None + build_parts_uu_id: Optional[str] = None + build_decision_book_uu_id: Optional[str] = None diff --git a/ApiValidations/Request/address.py b/ApiValidations/Request/address.py new file mode 100644 index 0000000..c7b9249 --- /dev/null +++ b/ApiValidations/Request/address.py @@ -0,0 +1,130 @@ +from api_validations.core_validations import BaseModelRegular +from api_validations.validations_request import ( + PydanticBaseModel, + ListOptions, +) +from typing import Optional + + +class PostCodeValidation: + tr = { + "post_code": "Posta Kodu", + "street_uu_id": "Sokak UUID", + } + en = { + "post_code": "Post Code", + "street_uu_id": "Street UUID", + } + + +class InsertPostCode(BaseModelRegular, PostCodeValidation): + street_uu_id: str + post_code: str + + +class UpdatePostCode(PydanticBaseModel, PostCodeValidation): + street_uu_id: Optional[str] = None + post_code: Optional[str] = None + + +class SearchAddressValidation: + tr = { + "search": "Ara", + "list_options": "Liste Seçenekleri", + } + en = { + "search": "Search", + "list_options": "List Options", + } + + +class SearchAddress(PydanticBaseModel, SearchAddressValidation): + search: str + list_options: ListOptions + + +class StreetValidation: + tr = { + "street_code": "Sokak Kodu", + "street_name": "Sokak Adı", + "postcode": "Posta Kodu", + "type_code": "Tip Kodu", + "type_description": "Tip Açıklaması", + "gov_code": "Devlet Kodu", + "address_geographic_uu_id": "Coğrafi UUID", + } + en = { + "street_code": "Street Code", + "street_name": "Street Name", + "postcode": "Post Code", + "type_code": "Type Code", + "type_description": "Type Description", + "gov_code": "Government Code", + "address_geographic_uu_id": "Address Geographic UUID", + } + + +class InsertStreet(PydanticBaseModel, StreetValidation): + street_code: str + street_name: str + postcode: str + + type_code: Optional[str] = None + type_description: Optional[str] = None + gov_code: Optional[str] = None + address_geographic_uu_id: Optional[str] = None + + +class AddressValidation: + tr = { + "post_code_uu_id": "Posta Kodu UUID", + "comment_address": "Adres Yorumu", + "letter_address": "Mektup Adresi", + "build_number": "Bina Numarası", + "door_number": "Kapı Numarası", + "floor_number": "Kat Numarası", + "short_letter_address": "Kısa Mektup Adresi", + "latitude": "Enlem", + "longitude": "Boylam", + } + en = { + "post_code_uu_id": "Post Code UUID", + "comment_address": "Address Comment", + "letter_address": "Letter Address", + "build_number": "Build Number", + "door_number": "Door Number", + "floor_number": "Floor Number", + "short_letter_address": "Short Letter Address", + "latitude": "Latitude", + "longitude": "Longitude", + } + + +class InsertAddress(BaseModelRegular, AddressValidation): + post_code_uu_id: str + + comment_address: Optional[str] = None + letter_address: Optional[str] = None + + build_number: str + door_number: Optional[str] = None + floor_number: Optional[str] = None + + short_letter_address: Optional[str] = None + latitude: Optional[float] = None + longitude: Optional[float] = None + + +class UpdateAddress(PydanticBaseModel, AddressValidation): + post_code_uu_id: Optional[str] = None + + comment_address: Optional[str] = None + letter_address: Optional[str] = None + + build_number: Optional[str] = None + door_number: Optional[str] = None + floor_number: Optional[str] = None + + short_letter_address: Optional[str] = None + latitude: Optional[float] = None + longitude: Optional[float] = None diff --git a/ApiValidations/Request/application.py b/ApiValidations/Request/application.py new file mode 100644 index 0000000..f9fa22b --- /dev/null +++ b/ApiValidations/Request/application.py @@ -0,0 +1,69 @@ +from api_validations.core_validations import BaseModelRegular + + +class SingleEnumClassKeyValidation: + tr = { + "class_name": "Sınıf Adı", + "key_name": "Anahtar Adı", + } + en = { + "class_name": "Class Name", + "key_name": "Key Name", + } + + +class SingleEnumClassKey(BaseModelRegular): + class_name: str + key_name: str + + +class SingleEnumUUIDValidation: + tr = { + "uu_id": "UUID", + } + en = { + "uu_id": "UUID", + } + + +class SingleEnumUUID(BaseModelRegular): + uu_id: str + + +class SingleEnumOnlyClassValidation: + tr = { + "class_name": "Sınıf Adı", + } + en = { + "class_name": "Class Name", + } + + +class SingleEnumOnlyClass(BaseModelRegular): + class_name: str + + +class SingleOccupantTypeClassKeyValidation: + tr = { + "type_code": "Tip Kodu", + } + en = { + "type_code": "Type Code", + } + + +class SingleOccupantTypeClassKey(BaseModelRegular): + type_code: str + + +class SingleOccupantTypeUUIDValidation: + tr = { + "uu_id": "Görev UUID", + } + en = { + "uu_id": "Occupant UUID", + } + + +class SingleOccupantTypeUUID(BaseModelRegular): + uu_id: str diff --git a/ApiValidations/Request/area.py b/ApiValidations/Request/area.py new file mode 100644 index 0000000..cfdf675 --- /dev/null +++ b/ApiValidations/Request/area.py @@ -0,0 +1,76 @@ +from typing import Optional +from api_validations.core_validations import BaseModelRegular +from api_validations.validations_request import ( + PydanticBaseModel, +) + + +class BuildAreaValidation: + + tr = { + "area_name": "Alan Adı", + "area_code": "Alan Kodu", + "area_type": "Alan Tipi", + "area_direction": "Alan Yönü", + "area_gross_size": "Brüt Alan", + "area_net_size": "Net Alan", + "width": "Genişlik", + "size": "En", + } + en = { + "area_name": "Area Name", + "area_code": "Area Code", + "area_type": "Area Type", + "area_direction": "Area Direction", + "area_gross_size": "Gross Size", + "area_net_size": "Net Size", + "width": "Width", + "size": "Size", + } + + +class InsertBuildArea(BaseModelRegular, BuildAreaValidation): + + build_uu_id: str + area_name: str + area_code: str + area_type: str + area_direction: Optional[str] = None + area_gross_size: Optional[float] = None + area_net_size: Optional[float] = None + width: Optional[int] = None + size: Optional[int] = None + + +class UpdateBuildArea(PydanticBaseModel, BuildAreaValidation): + + area_name: Optional[str] = None + area_code: Optional[str] = None + area_type: Optional[str] = None + area_direction: Optional[str] = None + area_gross_size: Optional[float] = None + area_net_size: Optional[float] = None + width: Optional[int] = None + size: Optional[int] = None + + +class BuildSites: + tr = {"address_uu_id": "Adres UU ID", "site_name": "Site Adı", "site_no": "Site No"} + en = { + "address_uu_id": "Address UU ID", + "site_name": "Site Name", + "site_no": "Site No", + } + + +class InsertBuildSites(BaseModelRegular, BuildSites): + + address_uu_id: str + site_name: str + site_no: str + + +class UpdateBuildSites(PydanticBaseModel, BuildSites): + + site_name: Optional[str] = None + site_no: Optional[str] = None diff --git a/ApiValidations/Request/authentication.py b/ApiValidations/Request/authentication.py new file mode 100644 index 0000000..d1205ce --- /dev/null +++ b/ApiValidations/Request/authentication.py @@ -0,0 +1,104 @@ +from api_validations.core_validations import BaseModelRegular +from typing import Optional +from pydantic import BaseModel + + +class ChangePasswordValidation: + tr = {"old_password": "Eski Şifre", "new_password": "Yeni Şifre"} + en = {"old_password": "Old Password", "new_password": "New Password"} + + +class ChangePassword(BaseModelRegular, ChangePasswordValidation): + old_password: str + new_password: str + + +class CreatePasswordValidation: + tr = { + "password_token": "Şifre Token", + "password": "Şifre", + "re_password": "Şifre Tekrar", + } + en = { + "password_token": "Password Token", + "password": "Password", + "re_password": "Re-Password", + } + + +class CreatePassword(BaseModelRegular, CreatePasswordValidation): + password_token: str + password: str + re_password: str + + +class OccupantSelectionValidation: + + tr = {"occupant_uu_id": "Kiracı UU ID", "build_part_uu_id": "Bölüm UU ID"} + en = {"occupant_uu_id": "Occupant UU ID", "build_part_uu_id": "Build Part UU ID"} + + +class OccupantSelection(BaseModel, OccupantSelectionValidation): + occupant_uu_id: str + build_part_uu_id: str + + +class EmployeeSelectionValidation: + + tr = {"company_uu_id": "Şirket UU ID"} + en = {"company_uu_id": "Company UU ID"} + + +class EmployeeSelection(BaseModel, EmployeeSelectionValidation): + company_uu_id: str + + +class LoginValidation: + tr = { + "domain": "Domain", + "access_key": "Erişim Anahtarı", + "password": "Şifre", + "remember_me": "Beni Hatırla", + } + en = { + "domain": "Domain", + "access_key": "Access Key", + "password": "Password", + "remember_me": "Remember Me", + } + + +class Login(BaseModelRegular, LoginValidation): + domain: str + access_key: str + password: str + remember_me: Optional[bool] = False + + +class LogoutValidation: + tr = {"domain": "Domain"} + en = {"domain": "Domain"} + + +class Logout(BaseModelRegular, LogoutValidation): + domain: str + + +class RememberValidation: + tr = {"domain": "Domain", "refresh_token": "Yenileme Anahtarı"} + en = {"domain": "Domain", "refresh_token": "Refresh Token"} + + +class Remember(BaseModelRegular, RememberValidation): + domain: str + refresh_token: str + + +class ForgotValidation: + tr = {"domain": "Domain", "access_key": "Erişim Anahtarı"} + en = {"domain": "Domain", "access_key": "Access Key"} + + +class Forgot(BaseModelRegular, ForgotValidation): + domain: str + access_key: str diff --git a/ApiValidations/Request/build_living_space.py b/ApiValidations/Request/build_living_space.py new file mode 100644 index 0000000..abb1ae7 --- /dev/null +++ b/ApiValidations/Request/build_living_space.py @@ -0,0 +1,52 @@ +from typing import Optional +from api_validations.core_validations import BaseModelRegular +from api_validations.validations_request import ( + PydanticBaseModel, + PydanticBaseModelValidation, +) + + +class BuildLivingSpaceValidation: + tr = { + "person_uu_id": "Kişi UUID'si", + "build_parts_uu_id": "Bina UUID'si", + "occupant_type_uu_id": "Mülk Sahibi UUID'si", + "expiry_starts": "Geçerlilik Başlangıç Tarihi", + "expiry_ends": "Geçerlilik Bitiş Tarihi", + } + en = { + "person_uu_id": "Person UUID", + "build_parts_uu_id": "Build UUID", + "occupant_type_uu_id": "Occupant UUID", + "expiry_starts": "Expiry Starts", + "expiry_ends": "Expiry Ends", + } + + +class PydanticBaseModelValidationUpdate: + tr = { + **PydanticBaseModelValidation.tr, + "is_tenant_live": "Kiracı mı?", + "build_parts_uu_id": "Bina UUID'si", + "person_uu_id": "Kişi UUID'si", + } + en = { + **PydanticBaseModelValidation.en, + "is_tenant_live": "Is Tenant Live?", + "build_parts_uu_id": "Build UUID", + "person_uu_id": "Person UUID", + } + + +class InsertBuildLivingSpace(BaseModelRegular, BuildLivingSpaceValidation): + person_uu_id: str + build_parts_uu_id: str + occupant_type_uu_id: str + expiry_starts: str + expiry_ends: Optional[str] = None + + +class UpdateBuildLivingSpace(PydanticBaseModel, BuildLivingSpaceValidation): + is_tenant_live: Optional[bool] = None + build_parts_uu_id: Optional[str] = None + person_uu_id: Optional[str] = None diff --git a/ApiValidations/Request/build_part.py b/ApiValidations/Request/build_part.py new file mode 100644 index 0000000..0386a3b --- /dev/null +++ b/ApiValidations/Request/build_part.py @@ -0,0 +1,139 @@ +from typing import Optional +from api_validations.core_validations import BaseModelRegular +from api_validations.validations_request import ( + PydanticBaseModel, + PydanticBaseModelValidation, +) + + +class BuildTypesUpdateValidation: + tr = { + **PydanticBaseModelValidation.tr, + "function_code": "Fonksiyon Kodu", + "type_code": "Tip Kodu", + "lang": "Dil", + "type_name": "Tip Adı", + } + en = { + **PydanticBaseModelValidation.en, + "function_code": "Function Code", + "type_code": "Type Code", + "lang": "Language", + "type_name": "Type Name", + } + + +class BuildTypesValidation: + tr = { + "function_code": "Fonksiyon Kodu", + "type_code": "Tip Kodu", + "lang": "Dil", + "type_name": "Tip Adı", + } + en = { + "function_code": "Function Code", + "type_code": "Type Code", + "lang": "Language", + "type_name": "Type Name", + } + + +class InsertBuildTypes(BaseModelRegular, BuildTypesValidation): + function_code: str + type_code: str + lang: str + type_name: str + + +class UpdateBuildTypes(PydanticBaseModel, BuildTypesUpdateValidation): ... + + +class BuildPartsValidation: + tr = { + "address_gov_code": "Adres İl Kodu", + "part_no": "Daire No", + "part_level": "Daire Seviyesi", + "build_part_type_uu_id": "Bina Daire Tipi UUID'si", + "part_code": "Daire Kodu", + "part_gross_size": "Daire Brüt Alanı", + "part_net_size": "Daire Net Alanı", + "default_accessory": "Varsayılan Aksesuar", + "human_livable": "İnsan Yaşanabilir", + "part_direction": "Daire Yönü", + } + en = { + "address_gov_code": "Address Gov Code", + "part_no": "Flat No", + "part_level": "Flat Level", + "build_part_type_uu_id": "Build Flat Type UUID", + "part_code": "Flat Code", + "part_gross_size": "Flat Gross Size", + "part_net_size": "Flat Net Size", + "default_accessory": "Default Accessory", + "human_livable": "Human Livable", + "part_direction": "Flat Direction", + } + + +class InsertBuildParts(BaseModelRegular, BuildPartsValidation): + build_uu_id: str + address_gov_code: str + part_no: int + part_level: int + build_part_type_uu_id: str + + part_gross_size: Optional[int] = None + part_net_size: Optional[int] = None + default_accessory: Optional[str] = None + human_livable: Optional[bool] = False + part_direction_uu_id: Optional[str] = None + ref_id: Optional[str] = None + + +class UpdateBuildPartsValidation: + tr = { + **PydanticBaseModelValidation.tr, + "address_gov_code": "Adres İl Kodu", + "part_no": "Daire No", + "part_level": "Daire Seviyesi", + "build_part_type_uu_id": "Bina Daire Tipi UUID'si", + "part_code": "Daire Kodu", + "part_gross_size": "Daire Brüt Alanı", + "part_net_size": "Daire Net Alanı", + "default_accessory": "Varsayılan Aksesuar", + "human_livable": "İnsan Yaşanabilir", + "part_direction": "Daire Yönü", + "current_owner_person_uu_id": "Mevcut Sahip Kişi UUID'si", + "current_tenant_person_uu_id": "Mevcut Kiracı Kişi UUID'si", + } + en = { + **PydanticBaseModelValidation.en, + "address_gov_code": "Address Gov Code", + "part_no": "Flat No", + "part_level": "Flat Level", + "build_part_type_uu_id": "Build Flat Type UUID", + "part_code": "Flat Code", + "part_gross_size": "Flat Gross Size", + "part_net_size": "Flat Net Size", + "default_accessory": "Default Accessory", + "human_livable": "Human Livable", + "part_direction": "Flat Direction", + "current_owner_person_uu_id": "Current Owner Person UUID", + "current_tenant_person_uu_id": "Current Tenant Person UUID", + } + + +class UpdateBuildParts(PydanticBaseModel, UpdateBuildPartsValidation): + address_gov_code: Optional[str] = None + part_no: Optional[int] = None + part_level: Optional[int] = None + build_part_type_uu_id: Optional[str] = None + + part_code: Optional[int] = None + part_gross_size: Optional[int] = None + part_net_size: Optional[int] = None + default_accessory: Optional[str] = None + human_livable: Optional[bool] = False + part_direction: Optional[str] = None + current_owner_person_uu_id: Optional[str] = None + current_tenant_person_uu_id: Optional[str] = None diff --git a/ApiValidations/Request/building.py b/ApiValidations/Request/building.py new file mode 100644 index 0000000..1efa2ac --- /dev/null +++ b/ApiValidations/Request/building.py @@ -0,0 +1,102 @@ +from typing import Optional +from datetime import datetime +from api_validations.core_validations import BaseModelRegular +from api_validations.validations_request import ( + PydanticBaseModel, + PydanticBaseModelValidation, + CrudRecordValidation, +) + + +class BuildValidation: + tr = { + **CrudRecordValidation.tr, + "gov_address_code": "Devlet Adres Kodu", + "build_name": "Bina Adı", + "build_types_uu_id": "Bina Tipi", + "build_no": "Bina No", + "max_floor": "Kat Sayısı", + "underground_floor": "Bodrum Kat Sayısı", + "address_uu_id": "Adres", + "build_date": "Yapım Tarihi", + "decision_period_date": "Karar Tarihi", + "tax_no": "Vergi No", + "lift_count": "Asansör Sayısı", + "heating_system": "Isıtma Sistemi", + "cooling_system": "Soğutma Sistemi", + "hot_water_system": "Sıcak Su Sistemi", + "block_service_man_count": "Hizmet Görevlisi Sayısı", + "security_service_man_count": "Güvenlik Görevlisi Sayısı", + "garage_count": "Garaj Sayısı", + } + en = { + **CrudRecordValidation.en, + "gov_address_code": "Government Address Code", + "build_name": "Building Name", + "build_types_uu_id": "Building Type", + "build_no": "Building No", + "max_floor": "Number of Floors", + "underground_floor": "Number of Basement Floors", + "address_uu_id": "Address", + "build_date": "Construction Date", + "decision_period_date": "Decision Date", + "tax_no": "Tax No", + "lift_count": "Number of Elevators", + "heating_system": "Heating System", + "cooling_system": "Cooling System", + "hot_water_system": "Hot Water System", + "block_service_man_count": "Number of Service Officers", + "security_service_man_count": "Number of Security Officers", + "garage_count": "Number of Garages", + } + + +class InsertBuild(BaseModelRegular, BuildValidation): + + gov_address_code: str + build_name: str + build_types_uu_id: str + max_floor: int + underground_floor: int + address_uu_id: str + build_date: datetime + decision_period_date: datetime + + tax_no: Optional[str] = None + lift_count: Optional[int] = None + heating_system: Optional[bool] = None + cooling_system: Optional[bool] = None + hot_water_system: Optional[bool] = None + block_service_man_count: Optional[int] = None + security_service_man_count: Optional[int] = None + garage_count: Optional[int] = None + + +class BuildUpdateValidation: + tr = { + **BuildValidation.tr, + **PydanticBaseModelValidation.tr, + } + en = { + **BuildValidation.en, + **PydanticBaseModelValidation.en, + } + + +class UpdateBuild(PydanticBaseModel, BuildUpdateValidation): + gov_address_code: Optional[str] = None + build_name: Optional[str] = None + build_no: Optional[str] = None + build_types_uu_id: Optional[str] = None + max_floor: Optional[int] = None + underground_floor: Optional[int] = None + build_date: Optional[datetime] = None + tax_no: Optional[str] = None + lift_count: Optional[int] = None + heating_system: Optional[bool] = None + cooling_system: Optional[bool] = None + hot_water_system: Optional[bool] = None + block_service_man_count: Optional[int] = None + security_service_man_count: Optional[int] = None + garage_count: Optional[int] = None + address_uu_id: Optional[str] = None diff --git a/ApiValidations/Request/company.py b/ApiValidations/Request/company.py new file mode 100644 index 0000000..22a3787 --- /dev/null +++ b/ApiValidations/Request/company.py @@ -0,0 +1,74 @@ +from typing import Optional, List +from api_validations.core_validations import BaseModelRegular +from api_validations.validations_request import ( + PydanticBaseModel, + PydanticBaseModelValidation, +) + + +class CompanyValidation: + tr = { + "formal_name": "Resmi Ad", + "company_type": "Şirket Tipi", + "commercial_type": "Ticari Tip", + "tax_no": "Vergi No", + "public_name": "Halka Açık Ad", + "company_tag": "Şirket Etiketi", + "default_lang_type": "Varsayılan Dil Tipi", + "default_money_type": "Varsayılan Para Tipi", + "official_address_uu_id": "Resmi Adres UU ID", + } + + +class InsertCompany(BaseModelRegular, CompanyValidation): + formal_name: str + company_type: str + commercial_type: str + tax_no: str + public_name: Optional[str] = None + company_tag: Optional[str] = None + default_lang_type: Optional[str] = None + default_money_type: Optional[str] = None + official_address_uu_id: Optional[str] = None + # parent_uu_id: Optional[int] = None + + +class CompanyUpdateValidation: + tr = { + **CompanyValidation.tr, + **PydanticBaseModelValidation.tr, + } + en = { + **CompanyValidation.tr, + **PydanticBaseModelValidation.en, + } + + +class UpdateCompany(PydanticBaseModel, CompanyUpdateValidation): + company_uu_id: str + public_name: Optional[str] = None + formal_name: Optional[str] = None + tax_no: Optional[str] = None + company_tag: Optional[str] = None + default_lang_type: Optional[str] = None + default_money_type: Optional[str] = None + official_address_uu_id: Optional[str] = None + + +class MatchCompany2CompanyValidation: + tr = { + **PydanticBaseModelValidation.tr, + "match_company_uu_id": "Eşleşen Şirket UU ID", + "duty_uu_id": "Görev UU ID", + } + en = { + **PydanticBaseModelValidation.en, + "match_company_uu_id": "Match Company UU ID", + "duty_uu_id": "Duty UU ID", + } + + +class MatchCompany2Company(PydanticBaseModel, MatchCompany2CompanyValidation): + match_company_uu_id: List[str] + duty_uu_id: str + show_only: Optional[bool] = None diff --git a/ApiValidations/Request/core_request_validations.py b/ApiValidations/Request/core_request_validations.py new file mode 100644 index 0000000..37081a4 --- /dev/null +++ b/ApiValidations/Request/core_request_validations.py @@ -0,0 +1,116 @@ +from typing import Optional + +from api_validations.core_validations import BaseModelRegular + + +class ListOptionsValidation: + tr = { + "page": "Sayfa", + "size": "Boyut", + "order_field": "Sıralama Alanı", + "order_type": "Sıralama Türü", + "include_joins": "Alt İçerikleri", + "query": "Sorgu", + } + en = { + "page": "Page", + "size": "Size", + "order_field": "Order Field", + "order_type": "Order Type", + "include_joins": "Include Joins", + "query": "Query", + } + + +class ListOptions(BaseModelRegular, ListOptionsValidation): + page: Optional[int] = 1 + size: Optional[int] = 10 + order_field: Optional[str] = "id" + order_type: Optional[str] = "asc" + include_joins: Optional[list] = None + query: Optional[dict] = None + + +class CrudRecordValidation: + tr = { + "uu_id": "UUID", + "created_at": "Oluşturulma Tarihi", + "updated_at": "Güncellenme Tarihi", + "created_by": "Oluşturan", + "updated_by": "Güncelleyen", + "confirmed_by": "Onaylayan", + "is_confirmed": "Onay", + "expiry_starts": "Geçerlilik Başlangıç Tarihi", + "expiry_ends": "Geçerlilik Bitiş Tarihi", + "active": "Aktif", + "is_notification_send": "Bildirim Gönderildi", + "is_email_send": "E-posta Gönderildi", + } + en = { + "uu_id": "UUID", + "created_at": "Created At", + "updated_at": "Updated At", + "created_by": "Created By", + "updated_by": "Updated By", + "confirmed_by": "Confirmed By", + "is_confirmed": "Confirmed", + "expiry_starts": "Expiry Starts", + "expiry_ends": "Expiry Ends", + "active": "Active", + "is_notification_send": "Notification Send", + "is_email_send": "Email Send", + } + + +class CrudRecords: + uu_id: Optional[str] = None + created_at: Optional[str] = None + updated_at: Optional[str] = None + created_by: Optional[str] = None + updated_by: Optional[str] = None + confirmed_by: Optional[str] = None + is_confirmed: Optional[bool] = None + active: Optional[bool] = None + is_notification_send: Optional[bool] = None + is_email_send: Optional[bool] = None + + +class PydanticBaseModelValidation: + tr = { + "active": "Aktif", + "deleted": "Silinmiş", + "expiry_starts": "Geçerlilik Başlangıç Tarihi", + "expiry_ends": "Geçerlilik Bitiş Tarihi", + "is_confirmed": "Onay", + } + en = { + "active": "Active", + "deleted": "Deleted", + "expiry_starts": "Expiry Starts", + "expiry_ends": "Expiry Ends", + "is_confirmed": "Confirmed", + } + + +class PydanticBaseModel(BaseModelRegular): + + active: Optional[bool] = None + deleted: Optional[bool] = None + expiry_starts: Optional[str] = None + # expiry_ends: Optional[str] = None + is_confirmed: Optional[bool] = None + + +class EndpointPydantic(BaseModelRegular): + data: Optional[dict] = None + + +class EndpointValidation(BaseModelRegular): + endpoint: Optional[str] = None + + +class PatchRecord(BaseModelRegular): + + confirm: Optional[bool] = None + delete: Optional[bool] = None + active: Optional[bool] = None diff --git a/ApiValidations/Request/create_model.py b/ApiValidations/Request/create_model.py new file mode 100644 index 0000000..b16da10 --- /dev/null +++ b/ApiValidations/Request/create_model.py @@ -0,0 +1,73 @@ +import typing + +from datetime import datetime + + +class ConvertField: + + def __init__(self, match, default_val=None): + self.match = match + self.default_val = default_val + + def typing_return(self): + typing_dict = { + "": float, + "": bool, + "": int, + "": str, + "": dict, + "": list, + "": datetime, + "typing.Optional[datetime.datetime]": typing.Optional[datetime], + "typing.Optional[bool]": typing.Optional[bool], + "typing.Optional[list]": typing.Optional[list], + "typing.Optional[str]": typing.Optional[str], + "typing.Optional[int]": typing.Optional[int], + "typing.Optional[float]": typing.Optional[float], + "typing.Optional[dict]": typing.Optional[dict], + } + matches_with = typing_dict.get(self.match, typing.Optional[str]) + default_value = getattr(self.default_val, "field_default_value", None) + return matches_with, default_value + + +# +# def create_model_from_database(model_id: typing.Union[int, str]): +# if isinstance(model_id, int): +# selected_model = Models.find_one(id=model_id) +# else: +# selected_model = Models.find_one(uu_id=str(model_id)) +# +# if not selected_model: +# raise HTTPException( +# status_code=202, +# detail=f"Model {selected_model.model_name} not found in database. Please add model to api.", +# ) +# pydantic_class = getattr(root_validates, selected_model.model_type, None) +# if not pydantic_class: +# raise HTTPException( +# status_code=202, +# detail=f"Pydantic class {selected_model.model_type} not found in database. Please add model to api.", +# ) +# +# model_entities_records = ModelEntities.filter_all( +# ModelEntities.model_id == selected_model.id +# ).data +# +# if not model_entities_records: +# raise HTTPException( +# status_code=202, +# detail="Model has no entities registered. Please add entities to model.", +# ) +# +# fields = {} +# for entity in model_entities_records: +# fields[entity.field_name] = ConvertField( +# entity.field_type, entity.field_default_value +# ).typing_return() +# +# return create_model( +# __model_name=selected_model.model_name, # pydantic_name(User) +# __module__=pydantic_class.__module__, # field_name(uu_id) +# **fields, # field_name = (field_type (Optional[str]), default_value(None)) +# ) diff --git a/ApiValidations/Request/decision_book.py b/ApiValidations/Request/decision_book.py new file mode 100644 index 0000000..1c1f8f4 --- /dev/null +++ b/ApiValidations/Request/decision_book.py @@ -0,0 +1,356 @@ +from typing import Optional +from api_validations.core_validations import BaseModelRegular +from api_validations.validations_request import ( + PydanticBaseModel, + PydanticBaseModelValidation, + ListOptions, +) + + +class DecisionBookDecisionBookInvitationsValidation: + tr = { + "build_decision_book_uu_id": "Karar Defteri UUID", + "message": "Mesaj", + "planned_date": "Planlanan Tarih", + } + en = { + "build_decision_book_uu_id": "Decision Book UUID", + "message": "Message", + "planned_date": "Planned Date", + } + + +class DecisionBookDecisionBookInvitations( + BaseModelRegular, DecisionBookDecisionBookInvitationsValidation +): + build_decision_book_uu_id: str + message: str + planned_date: str + + +class DecisionBookDecisionBookInvitationsAttendValidation: + tr = { + "token": "Token", + "is_attend": "Katılacak mı?", + } + en = { + "token": "Token", + "is_attend": "Is Attend?", + } + + +class DecisionBookDecisionBookInvitationsAttend( + BaseModelRegular, DecisionBookDecisionBookInvitationsAttendValidation +): + token: str + is_attend: bool + + +class DecisionBookDecisionBookInvitationsAssignValidation: + tr = { + "token": "Token", + "build_living_space_uu_id": "Yapı Yaşam Alanı UUID", + "occupant_type_uu_id": "Sakin Tipi UUID", + } + en = { + "token": "Token", + "build_living_space_uu_id": "Build Living Space UUID", + "occupant_type_uu_id": "Occupant Type UUID", + } + + +class DecisionBookDecisionBookInvitationsAssign( + BaseModelRegular, DecisionBookDecisionBookInvitationsAssignValidation +): + token: str + build_living_space_uu_id: str + occupant_type_uu_id: str + + +class DecisionBookDecisionBookInvitationsUpdateValidation: + tr = { + **PydanticBaseModelValidation.tr, + "token": "Token", + "occupant_type_uu_id": "Sakin Tipi UUID", + } + en = { + **PydanticBaseModelValidation.en, + "token": "Token", + "occupant_type_uu_id": "Occupant Type UUID", + } + + +class DecisionBookDecisionBookInvitationsUpdate( + PydanticBaseModel, DecisionBookDecisionBookInvitationsUpdateValidation +): + token: str + occupant_type_uu_id: Optional[str] = None + + +class ListDecisionBookValidation: + tr = { + "build_decision_book_uu_id": "Karar Defteri UUID", + } + en = { + "build_decision_book_uu_id": "Decision Book UUID", + } + + +class ListDecisionBook(ListOptions, ListDecisionBookValidation): + build_decision_book_uu_id: Optional[str] = None + + +class InsertDecisionBookValidation: + tr = { + **PydanticBaseModelValidation.tr, + "build_uu_id": "Yapı UUID", + "decision_type": "Karar Tipi", + "meeting_date": "Toplantı Tarihi", + "is_out_sourced": "Dış Kaynak mı?", + "resp_company_fix_wage": "Firma Sabit Ücreti", + "resp_company_uu_id": "Firma UUID", + } + en = { + **PydanticBaseModelValidation.en, + "build_uu_id": "Build UUID", + "decision_type": "Decision Type", + "meeting_date": "Meeting Date", + "is_out_sourced": "Is Out Sourced?", + "resp_company_fix_wage": "Company Fixed Wage", + "resp_company_uu_id": "Company UUID", + } + + +class InsertDecisionBook(PydanticBaseModel, InsertDecisionBookValidation): + build_uu_id: str + decision_type: str + meeting_date: str + is_out_sourced: bool + + resp_company_fix_wage: Optional[float] = None + resp_company_uu_id: Optional[str] = None + + +class InsertDecisionBookCompletedValidation: + tr = { + "build_decision_book_uu_id": "Karar Defteri UUID", + "meeting_completed_date": "Toplantı Tamamlanma Tarihi", + } + en = { + "build_decision_book_uu_id": "Decision Book UUID", + "meeting_completed_date": "Meeting Completed Date", + } + + +class InsertDecisionBookCompleted( + BaseModelRegular, InsertDecisionBookCompletedValidation +): + build_decision_book_uu_id: str + meeting_completed_date: str + + +class InsertDecisionBookPersonValidation: + tr = { + "person_uu_id": "Kişi UUID", + "build_decision_book_uu_id": "Karar Defteri UUID", + "management_typecode_uu_id": "Yönetim Tipi UUID", + "dues_discount_approval_date": "Aidat İndirim Onay Tarihi", + "dues_fix_discount": "Aidat Sabit İndirim", + "dues_percent_discount": "Aidat Yüzde İndirim", + } + en = { + "person_uu_id": "Person UUID", + "build_decision_book_uu_id": "Decision Book UUID", + "management_typecode_uu_id": "Management Type UUID", + "dues_discount_approval_date": "Dues Discount Approval Date", + "dues_fix_discount": "Dues Fix Discount", + "dues_percent_discount": "Dues Percent Discount", + } + + +class InsertDecisionBookPerson(BaseModelRegular, InsertDecisionBookPersonValidation): + person_uu_id: str + build_decision_book_uu_id: str + management_typecode_uu_id: str + + dues_discount_approval_date: Optional[str] = None + dues_fix_discount: Optional[float] = None + dues_percent_discount: Optional[int] = None + + +class UpdateDecisionBookPersonValidation: + tr = { + **PydanticBaseModelValidation.tr, + "dues_fix_discount": "Aidat Sabit İndirim", + "dues_percent_discount": "Aidat Yüzde İndirim", + } + en = { + **PydanticBaseModelValidation.en, + "dues_fix_discount": "Dues Fix Discount", + "dues_percent_discount": "Dues Percent Discount", + } + + +class UpdateDecisionBookPerson(PydanticBaseModel, UpdateDecisionBookPersonValidation): + + dues_fix_discount: Optional[float] = None + dues_percent_discount: Optional[int] = None + + +class RemoveDecisionBookPersonValidation: + tr = { + "person_uu_id": "Kişi UUID", + "build_decision_book_person_uu_id": "Karar Defteri Kişi UUID", + } + en = { + "person_uu_id": "Person UUID", + "build_decision_book_person_uu_id": "Decision Book Person UUID", + } + + +class RemoveDecisionBookPerson(PydanticBaseModel, RemoveDecisionBookPersonValidation): + person_uu_id: str + build_decision_book_person_uu_id: str + + +class UpdateDecisionBookValidation: + tr = { + **PydanticBaseModelValidation.tr, + "decision_book_pdf_path": "Karar Defteri PDF Yolu", + "is_out_sourced": "Dış Kaynak mı?", + "contact_agreement_path": "İletişim Anlaşma Yolu", + "contact_agreement_date": "İletişim Anlaşma Tarihi", + "meeting_date": "Toplantı Tarihi", + "decision_type": "Karar Tipi", + "resp_company_fix_wage": "Firma Sabit Ücreti", + "resp_company_uu_id": "Firma UUID", + } + en = { + **PydanticBaseModelValidation.en, + "decision_book_pdf_path": "Decision Book PDF Path", + "is_out_sourced": "Is Out Sourced?", + "contact_agreement_path": "Contact Agreement Path", + "contact_agreement_date": "Contact Agreement Date", + "meeting_date": "Meeting Date", + "decision_type": "Decision Type", + "resp_company_fix_wage": "Company Fixed Wage", + "resp_company_uu_id": "Company UUID", + } + + +class UpdateDecisionBook(PydanticBaseModel, UpdateDecisionBookValidation): + decision_book_pdf_path: Optional[str] = None + is_out_sourced: Optional[bool] = None + contact_agreement_path: Optional[str] = None + contact_agreement_date: Optional[str] = None + meeting_date: Optional[str] = None + decision_type: Optional[str] = None + + resp_company_fix_wage: Optional[float] = None + resp_company_uu_id: Optional[str] = None + + +class InsertBuildDecisionBookItemsValidation: + tr = { + "token": "Token", + "info_type_uu_id": "Bilgi Tipi UUID", + "item_comment": "Öğe Yorumu / Açıklama", + "currency": "Para Birimi", + "unit_type": "Birim Tipi", + "debit_start_date": "Borç Başlangıç Tarihi", + "debit_end_date": "Borç Bitiş Tarihi", + "unit_price_is_fixed": "Birim Fiyat Sabit mi?", + "unit_price": "Birim Fiyat", + } + en = { + "token": "Token", + "info_type_uu_id": "Info Type UUID", + "item_comment": "Item Comment", + "currency": "Currency", + "unit_type": "Unit Type", + "debit_start_date": "Debit Start Date", + "debit_end_date": "Debit End Date", + "unit_price_is_fixed": "Unit Price Is Fixed?", + "unit_price": "Unit Price", + } + + +class InsertBuildDecisionBookItems( + BaseModelRegular, InsertBuildDecisionBookItemsValidation +): + token: str + info_type_uu_id: str + item_comment: str + + currency: Optional[str] = "TL" + unit_type: Optional[str] = "M2" + debit_start_date: Optional[str] = None + debit_end_date: Optional[str] = None + unit_price_is_fixed: Optional[bool] = False + unit_price: Optional[float] = 0.00 + + # build_decision_book_uu_id: str + # item_objection: Optional[str] = None + + +class UpdateBuildDecisionBookItemsValidation: + tr = { + **PydanticBaseModelValidation.tr, + "item_comment": "Öğe Yorumu / Açıklama", + "item_objection": "Öğe İtirazı", + } + en = { + **PydanticBaseModelValidation.en, + "item_comment": "Item Comment", + "item_objection": "Item Objection", + } + + +class UpdateBuildDecisionBookItems( + PydanticBaseModel, UpdateBuildDecisionBookItemsValidation +): + item_comment: Optional[str] = None + item_objection: Optional[str] = None + + +class InsertBuildDecisionBookItemDebitsValidation: + tr = { + "build_decision_book_item_uu_id": "Karar Defteri Öğe UUID", + "dues_values": "Aidat Değerleri", + } + en = { + "build_decision_book_item_uu_id": "Decision Book Item UUID", + "dues_values": "Dues Values", + } + + +class InsertBuildDecisionBookItemDebits( + BaseModelRegular, InsertBuildDecisionBookItemDebitsValidation +): + build_decision_book_item_uu_id: str + dues_values: dict + # dues_types_uu_id: str + # decision_taken: Optional[bool] = None + + +class UpdateBuildDecisionBookItemDebitsValidation: + tr = { + **PydanticBaseModelValidation.tr, + "dues_types_uu_id": "Aidat Tipi UUID", + "dues_values": "Aidat Değerleri", + "decision_taken": "Karar Alındı mı?", + } + en = { + **PydanticBaseModelValidation.en, + "dues_types_uu_id": "Dues Type UUID", + "dues_values": "Dues Values", + "decision_taken": "Decision Taken?", + } + + +class UpdateBuildDecisionBookItemDebits( + PydanticBaseModel, UpdateBuildDecisionBookItemDebitsValidation +): + dues_types_uu_id: Optional[str] = None + dues_values: Optional[dict] = None + decision_taken: Optional[bool] = None diff --git a/ApiValidations/Request/departments.py b/ApiValidations/Request/departments.py new file mode 100644 index 0000000..03c61e1 --- /dev/null +++ b/ApiValidations/Request/departments.py @@ -0,0 +1,40 @@ +from typing import Optional +from api_validations.validations_request import ( + PydanticBaseModel, + PydanticBaseModelValidation, +) + + +class DepartmentsPydanticValidation: + tr = { + "department_code": "Department Kodu", + "department_name": "Departman Adı", + "department_description": "Departman Açıklaması", + "company_uu_id": "Şirket UUID", + "parent_department_uu_id": "Üst Departman UUID", + } + en = { + "department_code": "Department Code", + "department_name": "Department Name", + "department_description": "Department Description", + "company_uu_id": "Company UUID", + "parent_department_uu_id": "Parent Department UUID", + } + + +class DepartmentsPydantic(PydanticBaseModel, PydanticBaseModelValidation): + + department_code: Optional[str] + department_name: Optional[str] + department_description: Optional[str] = None + company_uu_id: Optional[str] = None + parent_department_uu_id: Optional[int] = None + + +# class UpdateDepartments(PydanticBaseModel): +# +# department_code: Optional[str] = None +# department_name: Optional[str] = None +# department_description: Optional[str] = None +# company_uu_id: Optional[str] = None +# parent_department_uu_id: Optional[int] = None diff --git a/ApiValidations/Request/employee.py b/ApiValidations/Request/employee.py new file mode 100644 index 0000000..163928a --- /dev/null +++ b/ApiValidations/Request/employee.py @@ -0,0 +1,251 @@ +from typing import Optional +from api_validations.core_validations import BaseModelRegular +from api_validations.validations_request import ( + PydanticBaseModel, + PydanticBaseModelValidation, +) + + +class BindEmployees2PeopleValidation: + tr = { + **PydanticBaseModelValidation.tr, + "staff_uu_id": "Kadro UUID", + "people_uu_id": "Kişi UUID", + "expiry_starts": "Başlangıç Tarihi", + } + en = { + **PydanticBaseModelValidation.en, + "staff_uu_id": "Staff UUID", + "people_uu_id": "People UUID", + "expiry_starts": "Start Date", + } + + +class BindEmployees2People(PydanticBaseModel, BindEmployees2PeopleValidation): + staff_uu_id: str + people_uu_id: str + expiry_starts: Optional[str] = None + + +class UnBindEmployees2PeopleValidation: + tr = { + **PydanticBaseModelValidation.tr, + "people_uu_id": "Kişi UUID", + "expiry_ends": "Bitiş Tarihi", + } + en = { + **PydanticBaseModelValidation.en, + "people_uu_id": "People UUID", + "expiry_ends": "End Date", + } + + +class UnBindEmployees2People(PydanticBaseModel, UnBindEmployees2PeopleValidation): + people_uu_id: str + expiry_ends: str + + +class InsertEmployeesValidation: + tr = { + "staff_uu_id": "Kadro UUID", + "people_uu_id": "Kişi UUID", + } + en = { + "staff_uu_id": "Staff UUID", + "people_uu_id": "People UUID", + } + + +class InsertEmployees(BaseModelRegular, InsertEmployeesValidation): + staff_uu_id: str + people_uu_id: Optional[str] = None + + +class InsertCompanyDutyValidation: + tr = { + "duty_code": "Görev Kodu", + "duty_name": "Görev Adı", + "duty_description": "Görev Açıklaması", + } + en = { + "duty_code": "Duty Code", + "duty_name": "Duty Name", + "duty_description": "Duty Description", + } + + +class InsertCompanyDuty(BaseModelRegular, InsertCompanyDutyValidation): + duty_code: str + duty_name: str + duty_description: Optional[str] = None + + +class SelectDutiesValidation: + tr = { + "duty_uu_id": "Görev UUID", + } + en = { + "duty_uu_id": "Duty UUID", + } + + +class SelectDuties(BaseModelRegular, SelectDutiesValidation): + duty_uu_id: Optional[str] = None + + +class InsertDutiesValidation: + tr = { + "duties_uu_id": "Görev UUID", + "department_uu_id": "Departman UUID", + "is_default_duty": "Varsayılan Görev", + } + en = { + "duties_uu_id": "Duty UUID", + "department_uu_id": "Department UUID", + "is_default_duty": "Default Duty", + } + + +class InsertDuties(BaseModelRegular, InsertDutiesValidation): + duties_uu_id: str + department_uu_id: str + is_default_duty: Optional[bool] = False + + +class UpdateDutiesValidation: + tr = { + **PydanticBaseModelValidation.tr, + "duties_uu_id": "Görev UUID", + "department_uu_id": "Departman UUID", + "is_default_duty": "Varsayılan Görev", + } + en = { + **PydanticBaseModelValidation.en, + "duties_uu_id": "Duty UUID", + "department_uu_id": "Department UUID", + "is_default_duty": "Default Duty", + } + + +class UpdateDuties(PydanticBaseModel): + duties_uu_id: Optional[str] = None + department_uu_id: Optional[str] = None + is_default_duty: Optional[bool] = None + + +class UpdateCompanyDutyValidation: + tr = { + **PydanticBaseModelValidation.tr, + "duty_code": "Görev Kodu", + "duty_name": "Görev Adı", + "duty_description": "Görev Açıklaması", + } + en = { + **PydanticBaseModelValidation.en, + "duty_code": "Duty Code", + "duty_name": "Duty Name", + "duty_description": "Duty Description", + } + + +class UpdateCompanyDuty(PydanticBaseModel): + duty_code: Optional[str] = None + duty_name: Optional[str] = None + duty_description: Optional[str] = None + + +class InsertCompanyEmployeesSalariesValidation: + tr = { + "gross_salary": "Brüt Maaş", + "net_salary": "Net Maaş", + "start_date": "Başlangıç Tarihi", + "stop_date": "Bitiş Tarihi", + "people_id": "Kişi ID", + } + en = { + "gross_salary": "Gross Salary", + "net_salary": "Net Salary", + "start_date": "Start Date", + "stop_date": "Stop Date", + "people_id": "People ID", + } + + +class InsertCompanyEmployeesSalaries(BaseModelRegular): + gross_salary: float + net_salary: float + start_date: str + stop_date: Optional[str] = None + people_id: int + + +class UpdateCompanyEmployeesSalariesValidation: + tr = { + **PydanticBaseModelValidation.tr, + "gross_salary": "Brüt Maaş", + "net_salary": "Net Maaş", + "start_date": "Başlangıç Tarihi", + "stop_date": "Bitiş Tarihi", + "people_id": "Kişi ID", + } + en = { + **PydanticBaseModelValidation.en, + "gross_salary": "Gross Salary", + "net_salary": "Net Salary", + "start_date": "Start Date", + "stop_date": "Stop Date", + "people_id": "People ID", + } + + +class UpdateCompanyEmployeesSalaries(PydanticBaseModel): + gross_salary: Optional[float] = None + net_salary: Optional[float] = None + start_date: Optional[str] = None + stop_date: Optional[str] = None + people_id: Optional[int] = None + + +class InsertCompanyEmployeesValidation: + tr = { + "employee_description": "Çalışan Açıklaması", + "person_uu_id": "Kişi UUID", + "duty_uu_id": "Görev UUID", + "start_date": "Başlangıç Tarihi", + "stop_date": "Bitiş Tarihi", + } + en = { + "employee_description": "Employee Description", + "person_uu_id": "Person UUID", + "duty_uu_id": "Duty UUID", + "start_date": "Start Date", + "stop_date": "Stop Date", + } + + +class InsertCompanyEmployees(BaseModelRegular, InsertCompanyEmployeesValidation): + + employee_description: Optional[str] = None + person_uu_id: str + duty_uu_id: str + + start_date: Optional[str] = None + stop_date: Optional[str] = None + + +class UpdateCompanyEmployeesValidation: + tr = { + **PydanticBaseModelValidation.tr, + "stop_date": "Bitiş Tarihi", + "employee_description": "Çalışan Açıklaması", + } + en = { + **PydanticBaseModelValidation.en, + "stop_date": "Stop Date", + "employee_description": "Employee Description", + } + + +class UpdateCompanyEmployees(PydanticBaseModel, UpdateCompanyEmployeesValidation): + stop_date: Optional[str] = None + employee_description: Optional[str] = None diff --git a/ApiValidations/Request/events.py b/ApiValidations/Request/events.py new file mode 100644 index 0000000..0cfe276 --- /dev/null +++ b/ApiValidations/Request/events.py @@ -0,0 +1,37 @@ +from typing import Optional +from api_validations.core_validations import BaseModelRegular + + +class RegisterEvents2EmployeeValidation: + tr = { + "event_uu_id_list": "Etkinlikler Listesi", + "employee_uu_id": "Çalışan UU ID", + } + en = { + "event_uu_id_list": "Event List", + "employee_uu_id": "Employee UU ID", + } + + +class RegisterEvents2Employee(BaseModelRegular, RegisterEvents2EmployeeValidation): + event_uu_id_list: list[str] = None + employee_uu_id: Optional[str] = None + + +class RegisterEvents2OccupantValidation: + tr = { + "event_uu_id_list": "Etkinlikler Listesi", + "build_part_uu_id": "Bina Parça UU ID", + "occupant_uu_id": "Apartman Sakini UU ID", + } + en = { + "event_uu_id_list": "Event List", + "build_part_uu_id": "Building Part UU ID", + "occupant_uu_id": "Occupant UU ID", + } + + +class RegisterEvents2Occupant(BaseModelRegular, RegisterEvents2OccupantValidation): + event_uu_id_list: list[str] = None + build_part_uu_id: Optional[str] = None + occupant_uu_id: Optional[str] = None diff --git a/ApiValidations/Request/modules.py b/ApiValidations/Request/modules.py new file mode 100644 index 0000000..42076d3 --- /dev/null +++ b/ApiValidations/Request/modules.py @@ -0,0 +1,36 @@ +from api_validations.core_validations import BaseModelRegular + + +class RegisterModules2OccupantValidation: + tr = { + "modules_uu_id": "Modül Listesi", + "occupant_uu_id": "Mülk Sahibi", + "build_part_uu_id": "Daire UUID", + } + en = { + "modules_uu_id": "Module List", + "occupant_uu_id": "Occupant", + "build_part_uu_id": "Flat UUID", + } + + +class RegisterModules2Occupant(BaseModelRegular, RegisterModules2OccupantValidation): + modules_uu_id: str + occupant_uu_id: str + build_part_uu_id: str + + +class RegisterModules2EmployeeValidation: + tr = { + "modules_uu_id": "Modül Listesi", + "employee_uu_id": "Çalışan", + } + en = { + "modules_uu_id": "Module List", + "employee_uu_id": "Employee", + } + + +class RegisterModules2Employee(BaseModelRegular, RegisterModules2EmployeeValidation): + modules_uu_id: str + employee_uu_id: str diff --git a/ApiValidations/Request/people.py b/ApiValidations/Request/people.py new file mode 100644 index 0000000..36182ec --- /dev/null +++ b/ApiValidations/Request/people.py @@ -0,0 +1,98 @@ +from typing import Optional +from api_validations.core_validations import BaseModelRegular +from api_validations.validations_request import ( + PydanticBaseModel, + PydanticBaseModelValidation, +) + + +class InsertPersonValidation: + tr = { + "firstname": "İsim", + "surname": "Soyisim", + "sex_code": "Cinsiyet", + "national_identity_id": "T.C. Kimlik Numarası", + "middle_name": "Orta İsim", + "father_name": "Baba Adı", + "mother_name": "Anne Adı", + "country_code": "Ülke Kodu", + "birth_place": "Doğum Yeri", + "birth_date": "Doğum Tarihi", + "tax_no": "Vergi Numarası", + "ref_id": "Referans ID", + } + + +class InsertPerson(BaseModelRegular, InsertPersonValidation): + firstname: str + surname: str + sex_code: str + national_identity_id: str + middle_name: Optional[str] = None + father_name: Optional[str] = None + mother_name: Optional[str] = None + country_code: Optional[str] = "TR" + birth_place: Optional[str] = None + birth_date: Optional[str] = None + tax_no: Optional[str] = None + ref_id: Optional[str] = None + + +class UpdatePersonValidation: + tr = { + **PydanticBaseModelValidation.tr, + **InsertPersonValidation.tr, + } + en = { + **PydanticBaseModelValidation.en, + **InsertPersonValidation.tr, + } + + +class UpdatePerson(PydanticBaseModel, UpdatePersonValidation): + firstname: Optional[str] = None + surname: Optional[str] = None + middle_name: Optional[str] + father_name: Optional[str] = None + mother_name: Optional[str] = None + sex_code: Optional[str] = None + country_code: Optional[str] = None + national_identity_id: Optional[str] = None + birth_place: Optional[str] = None + birth_date: Optional[str] = None + tax_no: Optional[str] = None + + +# +# class QueryPeople(PydanticBaseModel): +# uu_id: Optional[str] = None +# +# +# class InsertPeople(PydanticBaseModel): +# key_id: Optional[str] = None +# query: Optional[dict] = None +# data: Optional[_InsertPerson] = None +# +# +# class UpdatePeople(PydanticBaseModel): +# key_id: Optional[str] = None +# query: Optional[QueryPeople] = None +# data: Optional[_UpdatePerson] = None +# +# +# class DeletePeople(PydanticBaseModel): +# key_id: Optional[str] = None +# query: Optional[List[QueryPeople]] = None +# data: Optional[dict] = None +# +# +# class ListPeople(PydanticBaseModel): +# key_id: Optional[str] = None +# query: Optional[QueryPeople] = None +# data: Optional[ListOptions] = None +# +# +# class ActivePeople(PydanticBaseModel): +# key_id: Optional[str] = None +# query: Optional[List[QueryPeople]] = None +# data: Optional[dict] = None diff --git a/ApiValidations/Request/project_decision_book.py b/ApiValidations/Request/project_decision_book.py new file mode 100644 index 0000000..71fc1e4 --- /dev/null +++ b/ApiValidations/Request/project_decision_book.py @@ -0,0 +1,276 @@ +from typing import Optional +from api_validations.core_validations import BaseModelRegular +from api_validations.validations_request import ( + PydanticBaseModel, + PydanticBaseModelValidation, +) + + +class InsertBuildDecisionBookProjectItemsValidation: + tr = { + "build_decision_book_project_uu_id": "Proje UUID", + "item_header": "Başlık", + "item_comment": "Açıklama", + "attachment_pdf_path": "Ek Dosya Yolu", + "item_objection": "İtiraz", + } + en = { + "build_decision_book_project_uu_id": "Project UUID", + "item_header": "Header", + "item_comment": "Comment", + "attachment_pdf_path": "Attachment PDF Path", + "item_objection": "Objection", + } + + +class InsertBuildDecisionBookProjectItems( + BaseModelRegular, InsertBuildDecisionBookProjectItemsValidation +): + build_decision_book_project_uu_id: str + item_header: str + item_comment: str + attachment_pdf_path: Optional[str] = None + item_objection: Optional[str] = None + + +class UpdateBuildDecisionBookProjectItemsValidation: + tr = { + **InsertBuildDecisionBookProjectItemsValidation.tr, + **PydanticBaseModelValidation.tr, + } + en = { + **InsertBuildDecisionBookProjectItemsValidation.en, + **PydanticBaseModelValidation.en, + } + + +class UpdateBuildDecisionBookProjectItems(PydanticBaseModel): + item_header: Optional[str] = None + item_comment: Optional[str] = None + attachment_pdf_path: Optional[str] = None + item_estimated_cost: Optional[float] = None + build_decision_book_project_uu_id: Optional[str] = None + + +class InsertBuildDecisionBookProjectPersonValidation: + tr = { + "dues_percent_discount": "İskonto Oranı", + "job_fix_wage": "Sabit Ücret", + "bid_price": "Teklif Fiyatı", + "decision_price": "Karar Fiyatı", + "build_decision_book_project_uu_id": "Proje UUID", + "living_space_uu_id": "Yaşam Alanı UUID", + "project_team_type_uu_id": "Proje Takım Tipi UUID", + } + en = { + "dues_percent_discount": "Discount Rate", + "job_fix_wage": "Fixed Wage", + "bid_price": "Bid Price", + "decision_price": "Decision Price", + "build_decision_book_project_uu_id": "Project UUID", + "living_space_uu_id": "Living Space UUID", + "project_team_type_uu_id": "Project Team Type UUID", + } + + +class InsertBuildDecisionBookProjectPerson( + BaseModelRegular, InsertBuildDecisionBookProjectPersonValidation +): + dues_percent_discount: Optional[int] = None + job_fix_wage: Optional[float] = None + bid_price: Optional[float] = None + decision_price: Optional[float] = None + build_decision_book_project_uu_id: str + living_space_uu_id: str + project_team_type_uu_id: str + + +class UpdateBuildDecisionBookProjectPersonValidation: + tr = { + **InsertBuildDecisionBookProjectPersonValidation.tr, + **PydanticBaseModelValidation.tr, + } + en = { + **InsertBuildDecisionBookProjectPersonValidation.en, + **PydanticBaseModelValidation.en, + } + + +class UpdateBuildDecisionBookProjectPerson( + PydanticBaseModel, UpdateBuildDecisionBookProjectPersonValidation +): + dues_percent_discount: Optional[int] = None + job_fix_wage: Optional[float] = None + bid_price: Optional[float] = None + decision_price: Optional[float] = None + build_decision_book_project_uu_id: Optional[str] = None + living_space_uu_id: Optional[str] = None + project_team_type_uu_id: Optional[str] = None + + +class InsertBuildDecisionBookProjectsValidation: + tr = { + "build_decision_book_item_uu_id": "Karar Defteri UUID", + "project_responsible_person_uu_id": "Proje Sorumlu Kişi UUID", + "project_name": "Proje Adı", + "project_start_date": "Proje Başlangıç Tarihi", + "project_stop_date": "Proje Bitiş Tarihi", + "project_type": "Proje Tipi", + "is_out_sourced": "Dış Kaynak Kullanımı", + "project_note": "Proje Notu", + "decision_book_pdf_path": "Karar Defteri PDF Yolu", + "resp_company_fix_wage": "Firma Sabit Ücreti", + "contact_agreement_path": "İletişim Anlaşması Yolu", + "contact_agreement_date": "İletişim Anlaşması Tarihi", + "meeting_date": "Toplantı Tarihi", + "currency": "Para Birimi", + "bid_price": "Teklif Fiyatı", + "resp_company_uu_id": "Firma UUID", + } + en = { + "build_decision_book_item_uu_id": "Decision Book UUID", + "project_responsible_person_uu_id": "Project Responsible Person UUID", + "project_name": "Project Name", + "project_start_date": "Project Start Date", + "project_stop_date": "Project Stop Date", + "project_type": "Project Type", + "is_out_sourced": "Out Sourced", + "project_note": "Project Note", + "decision_book_pdf_path": "Decision Book PDF Path", + "resp_company_fix_wage": "Company Fixed Wage", + "contact_agreement_path": "Contact Agreement Path", + "contact_agreement_date": "Contact Agreement Date", + "meeting_date": "Meeting Date", + "currency": "Currency", + "bid_price": "Bid Price", + "resp_company_uu_id": "Company UUID", + } + + +class InsertBuildDecisionBookProjects( + BaseModelRegular, InsertBuildDecisionBookProjectsValidation +): + build_decision_book_item_uu_id: str + project_responsible_person_uu_id: str + project_name: str + project_start_date: str + project_stop_date: str + project_type: str + + is_out_sourced: Optional[bool] = False + project_note: Optional[str] = None + decision_book_pdf_path: Optional[str] = None + resp_company_fix_wage: Optional[float] = None + contact_agreement_path: Optional[str] = None + contact_agreement_date: Optional[str] = None + meeting_date: Optional[str] = None + currency: Optional[str] = None + bid_price: Optional[float] = None + resp_company_uu_id: Optional[str] = None + + +class UpdateBuildDecisionBookProjectsValidation: + tr = { + **InsertBuildDecisionBookProjectsValidation.tr, + **PydanticBaseModelValidation.tr, + } + en = { + **InsertBuildDecisionBookProjectsValidation.en, + **PydanticBaseModelValidation.en, + } + + +class UpdateBuildDecisionBookProjects( + PydanticBaseModel, UpdateBuildDecisionBookProjectsValidation +): + build_decision_book_project_uu_id: str + is_out_sourced: Optional[bool] = False + project_note: Optional[str] = None + # decision_book_pdf_path: Optional[str] = None + status_id: Optional[int] = None + resp_company_fix_wage: Optional[float] = None + contact_agreement_path: Optional[str] = None + contact_agreement_date: Optional[str] = None + contact_uu_id: Optional[str] = None + resp_company_uu_id: Optional[str] = None + approved_price: Optional[float] = None + + +class ApprovalsBuildDecisionBookProjectsValidation: + tr = { + "build_decision_book_project_uu_id": "Karar Defteri Proje UUID", + "project_stop_date": "Proje Bitiş Tarihi", + "status_code": "Durum Kodu", + "final_price_list": "Son Fiyat Listesi", + } + en = { + "build_decision_book_project_uu_id": "Decision Book Project UUID", + "project_stop_date": "Project Stop Date", + "status_code": "Status Code", + "final_price_list": "Final Price List", + } + + +class ApprovalsBuildDecisionBookProjects( + PydanticBaseModel, ApprovalsBuildDecisionBookProjectsValidation +): + build_decision_book_project_uu_id: str + project_stop_date: str + status_code: Optional[int] = None + final_price_list: Optional[list[dict]] = ( + None # {"date": "2021-01-01", "price": 1000} + ) + + +class InsertBuildDecisionBookProjectItemDebitsValidation: + tr = { + "build_decision_book_project_item_uu_id": "Karar Defteri Proje Öğe UUID", + "payment_date": "Ödeme Tarihi", + "dues_values": "Borç Değerleri", + "is_official": "Resmi Mi?", + "discount_value": "İskonto Oranı", + "discount_fix": "İskonto Sabit", + "decision_taken": "Karar Alındı Mı?", + } + en = { + "build_decision_book_project_item_uu_id": "Decision Book Project Item UUID", + "payment_date": "Payment Date", + "dues_values": "Dues Values", + "is_official": "Is Official?", + "discount_value": "Discount Rate", + "discount_fix": "Discount Fix", + "decision_taken": "Decision Taken?", + } + + +class InsertBuildDecisionBookProjectItemDebits( + PydanticBaseModel, InsertBuildDecisionBookProjectItemDebitsValidation +): + build_decision_book_project_item_uu_id: str + payment_date: str + dues_values: dict + is_official: Optional[bool] = False + discount_value: Optional[float] = None + discount_fix: Optional[float] = None + decision_taken: Optional[bool] = None + + +class UpdateBuildDecisionBookProjectItemDebitsValidation: + tr = { + **InsertBuildDecisionBookProjectItemDebitsValidation.tr, + **PydanticBaseModelValidation.tr, + } + en = { + **InsertBuildDecisionBookProjectItemDebitsValidation.en, + **PydanticBaseModelValidation.en, + } + + +class UpdateBuildDecisionBookProjectItemDebits( + PydanticBaseModel, UpdateBuildDecisionBookProjectItemDebitsValidation +): + dues_values: Optional[str] = None + discount_value: Optional[float] = None + discount_fix: Optional[float] = None + decision_taken: Optional[bool] = None + is_official: Optional[bool] = None diff --git a/ApiValidations/Request/rules.py b/ApiValidations/Request/rules.py new file mode 100644 index 0000000..23f22c7 --- /dev/null +++ b/ApiValidations/Request/rules.py @@ -0,0 +1,25 @@ +from typing import Optional, List +from api_validations.core_validations import BaseModelRegular +from api_validations.validations_request import ( + PydanticBaseModel, +) + + +class CheckEndpointAccess(BaseModelRegular): + endpoint: str + + +class InsertEndpointAccess(PydanticBaseModel): + duty_uu_id: str + endpoint_restriction_list_uu_ids: list + + +class UpdateEndpointAccess(PydanticBaseModel): + endpoint_restriction_uu_id: Optional[str] = None + deleted: Optional[bool] = None + active: Optional[bool] = None + is_confirmed: Optional[bool] = None + + +class UpdateEndpointAccessList(PydanticBaseModel): + endpoint_restriction_list: List[UpdateEndpointAccess] diff --git a/ApiValidations/Request/services.py b/ApiValidations/Request/services.py new file mode 100644 index 0000000..6ce55b4 --- /dev/null +++ b/ApiValidations/Request/services.py @@ -0,0 +1,36 @@ +from api_validations.core_validations import BaseModelRegular + + +class RegisterServices2OccupantValidation: + tr = { + "service_uu_id": "Hizmet UUID", + "occupant_uu_id": "Müşteri UUID", + "build_part_uu_id": "Bina Parça UUID", + } + en = { + "service_uu_id": "Service UUID", + "occupant_uu_id": "Occupant UUID", + "build_part_uu_id": "Building Part UUID", + } + + +class RegisterServices2Occupant(BaseModelRegular, RegisterServices2OccupantValidation): + service_uu_id: str + occupant_uu_id: str + build_part_uu_id: str + + +class RegisterServices2EmployeeValidation: + tr = { + "service_uu_id": "Hizmet UUID", + "employee_uu_id": "Personel UUID", + } + en = { + "service_uu_id": "Service UUID", + "employee_uu_id": "Employee UUID", + } + + +class RegisterServices2Employee(BaseModelRegular, RegisterServices2EmployeeValidation): + service_uu_id: str + employee_uu_id: str diff --git a/ApiValidations/Request/staff.py b/ApiValidations/Request/staff.py new file mode 100644 index 0000000..6222b2d --- /dev/null +++ b/ApiValidations/Request/staff.py @@ -0,0 +1,42 @@ +from typing import Optional +from api_validations.core_validations import BaseModelRegular +from api_validations.validations_request import ( + PydanticBaseModel, +) + + +class InsertStaffValidation: + tr = { + "staff_name": "Kadro Adı", + "staff_description": "Kadro Açıklaması", + "staff_code": "Kadro Kodu", + "duties_uu_id": "Görev UUID", + } + en = { + "staff_name": "Staff Name", + "staff_description": "Staff Description", + "staff_code": "Staff Code", + "duties_uu_id": "Duties UUID", + } + + +class InsertStaff(BaseModelRegular, InsertStaffValidation): + + staff_name: str + staff_description: Optional[str] = None + staff_code: Optional[str] = None + duties_uu_id: str + + +class SelectStaffValidation: + tr = { + "duties_uu_id": "Görev UUID", + } + en = { + "duties_uu_id": "Duties UUID", + } + + +class SelectStaff(PydanticBaseModel, SelectStaffValidation): + + duties_uu_id: str diff --git a/ApiValidations/Request/user.py b/ApiValidations/Request/user.py new file mode 100644 index 0000000..99f89c8 --- /dev/null +++ b/ApiValidations/Request/user.py @@ -0,0 +1,70 @@ +from typing import Optional +from api_validations.validations_request import ( + PydanticBaseModel, +) + + +class InsertUsersValidation: + tr = { + "people_uu_id": "Kişi UUID", + "user_tag": "Kullanıcı Etiketi", + "email": "E-posta", + "phone_number": "Telefon Numarası", + "avatar": "Avatar", + } + en = { + "people_uu_id": "People UUID", + "user_tag": "User Tag", + "email": "Email", + "phone_number": "Phone Number", + "avatar": "Avatar", + } + + +class InsertUsers(PydanticBaseModel, InsertUsersValidation): + people_uu_id: str + user_tag: str + email: Optional[str] = None + phone_number: Optional[str] = None + avatar: Optional[str] = None + + +class UpdateUsersValidation: + tr = { + "people_uu_id": "Kişi UUID", + "nick_name": "Kullanıcı Etiketi", + "domain_name": "Domain Adı", + "email": "E-posta", + "phone_number": "Telefon Numarası", + "avatar": "Avatar", + } + en = { + "people_uu_id": "People UUID", + "nick_name": "User Tag", + "domain_name": "Domain Name", + "email": "Email", + "phone_number": "Phone Number", + "avatar": "Avatar", + } + + +class UpdateUsers(PydanticBaseModel, UpdateUsersValidation): + people_uu_id: Optional[str] = None + nick_name: Optional[str] = None + domain_name: Optional[str] = None + email: Optional[str] = None + phone_number: Optional[str] = None + avatar: Optional[str] = None + + +class QueryUsersValidation: + tr = { + "uu_id": "UUID", + } + en = { + "uu_id": "UUID", + } + + +class QueryUsers(PydanticBaseModel): + uu_id: Optional[str] = None diff --git a/ErrorHandlers/LanguageModels/__init__.py b/ErrorHandlers/LanguageModels/__init__.py deleted file mode 100644 index a7963a9..0000000 --- a/ErrorHandlers/LanguageModels/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -from ErrorHandlers.LanguageModels.base_languages import BaseErrorLanguageModels - - -__all__ = ["BaseErrorLanguageModels"] diff --git a/LanguageModels/Database/Mixins/crud_mixin.py b/LanguageModels/Database/Mixins/crud_mixin.py new file mode 100644 index 0000000..dcbfa84 --- /dev/null +++ b/LanguageModels/Database/Mixins/crud_mixin.py @@ -0,0 +1,42 @@ +CrudCollectionLanguageModel = dict( + tr={ + "id": "ID", + "uu_id": "UUID", + "ref_id": "Referans ID", + "created_at": "Oluşturulma Tarihi", + "updated_at": "Güncellenme Tarihi", + "cryp_uu_id": "Şifreli ID", + "created_by": "Oluşturan", + "created_by_id": "Oluşturan ID", + "updated_by": "Güncelleyen", + "updated_by_id": "Güncelleyen ID", + "confirmed_by": "Onaylayan", + "confirmed_by_id": "Onaylayan ID", + "is_confirmed": "Onay Durumu", + "replication_id": "Replikasyon ID", + "deleted": "Silindi", + "active": "Aktif", + "is_notification_send": "Bildirim Gönderildi", + "is_email_send": "E-posta Gönderildi", + }, + en={ + "id": "Identity", + "uu_id": "UUID", + "ref_id": "Reference Identity", + "created_at": "Created At", + "updated_at": "Updated At", + "cryp_uu_id": "Encrypted Identity", + "created_by": "Created By", + "created_by_id": "Created By Identity", + "updated_by": "Updated By", + "updated_by_id": "Updated By Identity", + "confirmed_by": "Confirmed By", + "confirmed_by_id": "Confirmed By Identity", + "is_confirmed": "Confirmation Status", + "replication_id": "Replication Identity", + "deleted": "Deleted", + "active": "Active", + "is_notification_send": "Notification Sent", + "is_email_send": "Email Sent", + }, +) diff --git a/LanguageModels/Database/__init__.py b/LanguageModels/Database/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/LanguageModels/Database/account/account.py b/LanguageModels/Database/account/account.py new file mode 100644 index 0000000..8bb0857 --- /dev/null +++ b/LanguageModels/Database/account/account.py @@ -0,0 +1,388 @@ +from LanguageModels.Database.Mixins.crud_mixin import CrudCollectionLanguageModel + +AccountBooksLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "country": "Ülke", + "branch_type": "Şube Türü", + "company_id": "Şirket ID", + "company_uu_id": "Şirket UU ID", + "branch_id": "Şube ID", + "branch_uu_id": "Şube UU ID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "country": "Country", + "branch_type": "Branch Type", + "company_id": "Company ID", + "company_uu_id": "Company UU ID", + "branch_id": "Branch ID", + "branch_uu_id": "Branch UU ID", + }, +) + +AccountCodesLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "account_code": "Hesap Kodu", + "comment_line": "Yorum Satırı", + "is_receive_or_debit": "Alacak veya Borç", + "product_id": "Ürün ID", + "nvi_id": "Nvi ID", + "status_id": "Durum ID", + "account_code_seperator": "Hesap Kodu Ayırıcı", + "system_id": "Sistem ID", + "locked": "Kilitli", + "company_id": "Şirket ID", + "company_uu_id": "Şirket UU ID", + "customer_id": "Müşteri ID", + "customer_uu_id": "Müşteri UU ID", + "person_id": "Kişi ID", + "person_uu_id": "Kişi UU ID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "account_code": "Account Code", + "comment_line": "Comment Line", + "is_receive_or_debit": "Is Receive or Debit", + "product_id": "Product ID", + "nvi_id": "Nvi ID", + "status_id": "Status ID", + "account_code_seperator": "Account Code Seperator", + "system_id": "System ID", + "locked": "Locked", + "company_id": "Company ID", + "company_uu_id": "Company UU ID", + "customer_id": "Customer ID", + "customer_uu_id": "Customer UU ID", + "person_id": "Person ID", + "person_uu_id": "Person UU ID", + }, +) + +AccountCodeParserLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "account_code_1": "Hesap Kodu 1", + "account_code_2": "Hesap Kodu 2", + "account_code_3": "Hesap Kodu 3", + "account_code_4": "Hesap Kodu 4", + "account_code_5": "Hesap Kodu 5", + "account_code_6": "Hesap Kodu 6", + "account_code_id": "Hesap Kodu ID", + "account_code_uu_id": "Hesap Kodu UU ID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "account_code_1": "Account Code 1", + "account_code_2": "Account Code 2", + "account_code_3": "Account Code 3", + "account_code_4": "Account Code 4", + "account_code_5": "Account Code 5", + "account_code_6": "Account Code 6", + "account_code_id": "Account Code ID", + "account_code_uu_id": "Account Code UU ID", + }, +) + +AccountMasterLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "doc_date": "Belge Tarihi", + "plug_type": "Fiş Türü", + "plug_number": "Fiş Numarası", + "special_code": "Özel Kod", + "authorization_code": "Yetki Kodu", + "doc_code": "Belge Kodu", + "doc_type": "Belge Türü", + "comment_line1": "Yorum Satırı 1", + "comment_line2": "Yorum Satırı 2", + "comment_line3": "Yorum Satırı 3", + "comment_line4": "Yorum Satırı 4", + "comment_line5": "Yorum Satırı 5", + "comment_line6": "Yorum Satırı 6", + "project_code": "Proje Kodu", + "module_no": "Modül No", + "journal_no": "Defter No", + "status_id": "Durum ID", + "canceled": "İptal Edildi", + "print_count": "Yazdırma Sayısı", + "total_active": "Toplam Aktif", + "total_passive": "Toplam Pasif", + "total_active_1": "Toplam Aktif 1", + "total_passive_1": "Toplam Pasif 1", + "total_active_2": "Toplam Aktif 2", + "total_passive_2": "Toplam Pasif 2", + "total_active_3": "Toplam Aktif 3", + "total_passive_3": "Toplam Pasif 3", + "total_active_4": "Toplam Aktif 4", + "total_passive_4": "Toplam Pasif 4", + "cross_ref": "Çapraz Referans", + "data_center_id": "Veri Merkezi ID", + "data_center_rec_num": "Veri Merkezi Kayıt Numarası", + "account_header_id": "Hesap Başlığı ID", + "account_header_uu_id": "Hesap Başlığı UU ID", + "project_item_id": "Proje Öğesi ID", + "project_item_uu_id": "Proje Öğesi UU ID", + "department_id": "Departman ID", + "department_uu_id": "Departman UU ID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "doc_date": "Document Date", + "plug_type": "Plug Type", + "plug_number": "Plug Number", + "special_code": "Special Code", + "authorization_code": "Authorization Code", + "doc_code": "Document Code", + "doc_type": "Document Type", + "comment_line1": "Comment Line 1", + "comment_line2": "Comment Line 2", + "comment_line3": "Comment Line 3", + "comment_line4": "Comment Line 4", + "comment_line5": "Comment Line 5", + "comment_line6": "Comment Line 6", + "project_code": "Project Code", + "module_no": "Module No", + "journal_no": "Journal No", + "status_id": "Status ID", + "canceled": "Canceled", + "print_count": "Print Count", + "total_active": "Total Active", + "total_passive": "Total Passive", + "total_active_1": "Total Active 1", + "total_passive_1": "Total Passive 1", + "total_active_2": "Total Active 2", + "total_passive_2": "Total Passive 2", + "total_active_3": "Total Active 3", + "total_passive_3": "Total Passive 3", + "total_active_4": "Total Active 4", + "total_passive_4": "Total Passive 4", + "cross_ref": "Cross Reference", + "data_center_id": "Data Center ID", + "data_center_rec_num": "Data Center Record Number", + "account_header_id": "Account Header ID", + "account_header_uu_id": "Account Header UU ID", + "project_item_id": "Project Item ID", + "project_item_uu_id": "Project Item UU ID", + "department_id": "Department ID", + "department_uu_id": "Department UU ID", + }, +) + +AccountDetailLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "doc_date": "Belge Tarihi", + "plug_type": "Fiş Türü", + "plug_number": "Fiş Numarası", + "special_code": "Özel Kod", + "authorization_code": "Yetki Kodu", + "doc_code": "Belge Kodu", + "doc_type": "Belge Türü", + "comment_line1": "Yorum Satırı 1", + "comment_line2": "Yorum Satırı 2", + "comment_line3": "Yorum Satırı 3", + "comment_line4": "Yorum Satırı 4", + "comment_line5": "Yorum Satırı 5", + "comment_line6": "Yorum Satırı 6", + "project_code": "Proje Kodu", + "module_no": "Modül No", + "journal_no": "Defter No", + "status_id": "Durum ID", + "canceled": "İptal Edildi", + "print_count": "Yazdırma Sayısı", + "total_active": "Toplam Aktif", + "total_passive": "Toplam Pasif", + "total_active_1": "Toplam Aktif 1", + "total_passive_1": "Toplam Pasif 1", + "total_active_2": "Toplam Aktif 2", + "total_passive_2": "Toplam Pasif 2", + "total_active_3": "Toplam Aktif 3", + "total_passive_3": "Toplam Pasif 3", + "total_active_4": "Toplam Aktif 4", + "total_passive_4": "Toplam Pasif 4", + "cross_ref": "Çapraz Referans", + "data_center_id": "Veri Merkezi ID", + "data_center_rec_num": "Veri Merkezi Kayıt Numarası", + "account_header_id": "Hesap Başlığı ID", + "account_header_uu_id": "Hesap Başlığı UU ID", + "project_item_id": "Proje Öğesi ID", + "project_item_uu_id": "Proje Öğesi UU ID", + "department_id": "Departman ID", + "department_uu_id": "Departman UU ID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "doc_date": "Document Date", + "plug_type": "Plug Type", + "plug_number": "Plug Number", + "special_code": "Special Code", + "authorization_code": "Authorization Code", + "doc_code": "Document Code", + "doc_type": "Document Type", + "comment_line1": "Comment Line 1", + "comment_line2": "Comment Line 2", + "comment_line3": "Comment Line 3", + "comment_line4": "Comment Line 4", + "comment_line5": "Comment Line 5", + "comment_line6": "Comment Line 6", + "project_code": "Project Code", + "module_no": "Module No", + "journal_no": "Journal No", + "status_id": "Status ID", + "canceled": "Canceled", + "print_count": "Print Count", + "total_active": "Total Active", + "total_passive": "Total Passive", + "total_active_1": "Total Active 1", + "total_passive_1": "Total Passive 1", + "total_active_2": "Total Active 2", + "total_passive_2": "Total Passive 2", + "total_active_3": "Total Active 3", + "total_passive_3": "Total Passive 3", + "total_active_4": "Total Active 4", + "total_passive_4": "Total Passive 4", + "cross_ref": "Cross Reference", + "data_center_id": "Data Center ID", + "data_center_rec_num": "Data Center Record Number", + "account_header_id": "Account Header ID", + "account_header_uu_id": "Account Header UU ID", + "project_item_id": "Project Item ID", + "project_item_uu_id": "Project Item UU ID", + "department_id": "Department ID", + "department_uu_id": "Department UU ID", + }, +) + +AccountRecordsLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "iban": "IBAN", + "bank_date": "Banka Tarihi", + "currency_value": "Döviz Değeri", + "bank_balance": "Banka Bakiyesi", + "currency": "Döviz", + "additional_balance": "Ek Bakiye", + "channel_branch": "Kanal Şubesi", + "process_name": "İşlem Türü Adı", + "process_type": "İşlem Türü", + "process_comment": "İşlem Kayıt Yorumu", + "process_garbage": "İşlem Kayıt Çöpü", + "bank_reference_code": "Banka Referans Kodu", + "add_comment_note": "Yorum Not Ekle", + "is_receipt_mail_send": "Alındı Mail Gönderildi", + "found_from": "Bulunduğu", + "similarity": "Benzerlik", + "remainder_balance": "Kalan Bakiye", + "bank_date_y": "Banka Tarihi Yıl", + "bank_date_m": "Banka Tarihi Ay", + "bank_date_w": "Banka Tarihi Hafta", + "bank_date_d": "Banka Tarihi Gün", + "approving_accounting_record": "Onaylayan Muhasebe Kaydı", + "accounting_receipt_date": "Muhasebe Alındı Tarihi", + "accounting_receipt_number": "Muhasebe Alındı Numarası", + "status_id": "Durum ID", + "approved_record": "Onaylanmış Kayıt", + "import_file_name": "İçe Aktarım Dosya Adı", + "receive_debit": "Alacak Borç", + "receive_debit_uu_id": "Alacak Borç UU ID", + "budget_type": "Bütçe Türü", + "budget_type_uu_id": "Bütçe Türü UU ID", + "company_id": "Şirket ID", + "company_uu_id": "Şirket UU ID", + "send_company_id": "Gönderen Şirket ID", + "send_company_uu_id": "Gönderen Şirket UU ID", + "send_person_id": "Gönderen Kişi ID", + "send_person_uu_id": "Gönderen Kişi UU ID", + "approving_accounting_person": "Onaylayan Muhasebe Kişi", + "approving_accounting_person_uu_id": "Onaylayan Muhasebe Kişi UU ID", + "living_space_id": "Yaşam Alanı ID", + "living_space_uu_id": "Yaşam Alanı UU ID", + "customer_id": "Müşteri ID", + "customer_uu_id": "Müşteri UU ID", + "build_id": "Bina ID", + "build_uu_id": "Bina UU ID", + "build_parts_id": "Bina Parça ID", + "build_parts_uu_id": "Bina Parça UU ID", + "build_decision_book_id": "Bina Karar Defteri ID", + "build_decision_book_uu_id": "Bina Karar Defteri UU ID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "iban": "IBAN", + "bank_date": "Bank Date", + "currency_value": "Currency Value", + "bank_balance": "Bank Balance", + "currency": "Currency", + "additional_balance": "Additional Balance", + "channel_branch": "Channel Branch", + "process_name": "Process Type Name", + "process_type": "Process Type", + "process_comment": "Process Record Comment", + "process_garbage": "Process Record Garbage", + "bank_reference_code": "Bank Reference Code", + "add_comment_note": "Add Comment Note", + "is_receipt_mail_send": "Is Receipt Mail Send", + "found_from": "Found From", + "similarity": "Similarity", + "remainder_balance": "Remainder Balance", + "bank_date_y": "Bank Date Year", + "bank_date_m": "Bank Date Month", + "bank_date_w": "Bank Date Week", + "bank_date_d": "Bank Date Day", + "approving_accounting_record": "Approving Accounting Record", + "accounting_receipt_date": "Accounting Receipt Date", + "accounting_receipt_number": "Accounting Receipt Number", + "status_id": "Status ID", + "approved_record": "Approved Record", + "import_file_name": "Import File Name", + "receive_debit": "Receive Debit", + "receive_debit_uu_id": "Receive Debit UU ID", + "budget_type": "Budget Type", + "budget_type_uu_id": "Budget Type UU ID", + "company_id": "Company ID", + "company_uu_id": "Company UU ID", + "send_company_id": "Send Company ID", + "send_company_uu_id": "Send Company UU ID", + "send_person_id": "Send Person ID", + "send_person_uu_id": "Send Person UU ID", + "approving_accounting_person": "Approving Accounting Person", + "approving_accounting_person_uu_id": "Approving Accounting Person UU ID", + "living_space_id": "Living Space ID", + "living_space_uu_id": "Living Space UU ID", + "customer_id": "Customer ID", + "customer_uu_id": "Customer UU ID", + "build_id": "Build ID", + "build_uu_id": "Build UU ID", + "build_parts_id": "Build Parts ID", + "build_parts_uu_id": "Build Parts UU ID", + "build_decision_book_id": "Build Decision Book ID", + "build_decision_book_uu_id": "Build Decision Book UU ID", + }, +) + +AccountRecordExchangesLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "are_currency": "Para Birimi", + "are_exchange_rate": "Döviz Kuru", + "usd_exchange_rate_value": "USD Döviz Kuru Değeri", + "eur_exchange_rate_value": "EUR Döviz Kuru Değeri", + "gbp_exchange_rate_value": "GBP Döviz Kuru Değeri", + "cny_exchange_rate_value": "CNY Döviz Kuru Değeri", + "account_records_id": "Hesap Kayıt ID", + "account_records_uu_id": "Hesap Kayıt UU ID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "are_currency": "Currency", + "are_exchange_rate": "Exchange Rate", + "usd_exchange_rate_value": "USD Exchange Rate Value", + "eur_exchange_rate_value": "EUR Exchange Rate Value", + "gbp_exchange_rate_value": "GBP Exchange Rate Value", + "cny_exchange_rate_value": "CNY Exchange Rate Value", + "account_records_id": "Account Record ID", + "account_records_uu_id": "Account Record UU ID", + }, +) diff --git a/LanguageModels/Database/account/iban.py b/LanguageModels/Database/account/iban.py new file mode 100644 index 0000000..ccc1b49 --- /dev/null +++ b/LanguageModels/Database/account/iban.py @@ -0,0 +1,52 @@ +from LanguageModels.Database.Mixins.crud_mixin import CrudCollectionLanguageModel + +BuildIbansLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "iban": "IBAN Numarası", + "start_date": "Banka İşlem Başlangıç Tarihi", + "stop_date": "Banka İşlem Bitiş Tarihi", + "bank_code": "Banka Kodu", + "xcomment": "Yorum", + "build_id": "Bina ID", + "build_uu_id": "Bina UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "iban": "IBAN Number", + "start_date": "Bank Transaction Start Date", + "stop_date": "Bank Transaction End Date", + "bank_code": "Bank Code", + "xcomment": "Comment", + "build_id": "Build ID", + "build_uu_id": "Build UUID", + }, +) + + +BuildIbanDescriptionLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "iban": "IBAN Numarası", + "group_id": "Grup ID", + "search_word": "Arama Kelimesi", + "customer_id": "Müşteri ID", + "customer_uu_id": "Müşteri UUID", + "company_id": "Şirket ID", + "company_uu_id": "Şirket UUID", + "build_parts_id": "Bina Parça ID", + "build_parts_uu_id": "Bina Parça UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "iban": "IBAN Number", + "group_id": "Group ID", + "search_word": "Search Word", + "customer_id": "Customer ID", + "customer_uu_id": "Customer UUID", + "company_id": "Company ID", + "company_uu_id": "Company UUID", + "build_parts_id": "Build Parts ID", + "build_parts_uu_id": "Build Parts UUID", + }, +) diff --git a/LanguageModels/Database/building/budget.py b/LanguageModels/Database/building/budget.py new file mode 100644 index 0000000..515d6d5 --- /dev/null +++ b/LanguageModels/Database/building/budget.py @@ -0,0 +1,101 @@ +from LanguageModels.Database.Mixins.crud_mixin import CrudCollectionLanguageModel + +DecisionBookBudgetBooksLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "country": "Ülke", + "branch_type": "Şube Tipi", + "company_id": "Şirket ID", + "company_uu_id": "Şirket UUID", + "branch_id": "Şube ID", + "branch_uu_id": "Şube UUID", + "build_decision_book_id": "Karar Defteri ID", + "build_decision_book_uu_id": "Karar Defteri UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "country": "Country", + "branch_type": "Branch Type", + "company_id": "Company ID", + "company_uu_id": "Company UUID", + "branch_id": "Branch ID", + "branch_uu_id": "Branch UUID", + "build_decision_book_id": "Build Decision Book ID", + "build_decision_book_uu_id": "Build Decision Book UUID", + }, +) + +DecisionBookBudgetCodesLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "budget_code": "Bütçe Kodu", + "comment_line": "Yorum Satırı", + "build_decision_book_id": "Karar Defteri ID", + "build_decision_book_uu_id": "Karar Defteri UUID", + "build_parts_id": "Bina Parça ID", + "build_parts_uu_id": "Bina Parça UUID", + "company_id": "Şirket ID", + "company_uu_id": "Şirket UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "budget_code": "Budget Code", + "comment_line": "Comment Line", + "build_decision_book_id": "Build Decision Book ID", + "build_decision_book_uu_id": "Build Decision Book UUID", + "build_parts_id": "Build Parts ID", + "build_parts_uu_id": "Build Parts UUID", + "company_id": "Company ID", + "company_uu_id": "Company UUID", + }, +) + +DecisionBookBudgetMasterLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "budget_type": "Bütçe Tipi", + "currency": "Para Birimi", + "total_budget": "Toplam Bütçe", + "tracking_period_id": "Takip Dönemi ID", + "tracking_period_uu_id": "Takip Dönemi UUID", + "budget_books_id": "Bütçe Kitapları ID", + "budget_books_uu_id": "Bütçe Kitapları UUID", + "department_id": "Departman ID", + "department_uu_id": "Departman UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "budget_type": "Budget Type", + "currency": "Currency", + "total_budget": "Total Budget", + "tracking_period_id": "Tracking Period ID", + "tracking_period_uu_id": "Tracking Period UUID", + "budget_books_id": "Budget Books ID", + "budget_books_uu_id": "Budget Books UUID", + "department_id": "Department ID", + "department_uu_id": "Department UUID", + }, +) + +DecisionBookBudgetsLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "process_date": "İşlem Tarihi", + "budget_codes_id": "Bütçe Kodları ID", + "total_budget": "Toplam Bütçe", + "used_budget": "Kullanılan Bütçe", + "remaining_budget": "Kalan Bütçe", + "decision_book_budget_master_id": "Karar Defteri Bütçesi ID", + "decision_book_budget_master_uu_id": "Karar Defteri Bütçesi UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "process_date": "Process Date", + "budget_codes_id": "Budget Codes ID", + "total_budget": "Total Budget", + "used_budget": "Used Budget", + "remaining_budget": "Remaining Budget", + "decision_book_budget_master_id": "Decision Book Budget Master ID", + "decision_book_budget_master_uu_id": "Decision Book Budget Master UUID", + }, +) diff --git a/LanguageModels/Database/building/build.py b/LanguageModels/Database/building/build.py new file mode 100644 index 0000000..06aaa7e --- /dev/null +++ b/LanguageModels/Database/building/build.py @@ -0,0 +1,301 @@ +from LanguageModels.Database.Mixins.crud_mixin import CrudCollectionLanguageModel + +BuildTypesLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "function_code": "Fonksiyon Kodu", + "type_code": "Yapı Tipi Kodu", + "lang": "Dil", + "type_name": "Tip Adı", + }, + en={ + **CrudCollectionLanguageModel["en"], + "function_code": "Function Code", + "type_code": "Type Code", + "lang": "Language", + "type_name": "Type Name", + }, +) + +Part2EmployeeLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "build_id": "Bina ID", + "part_id": "Bina Parça ID", + "employee_id": "Çalışan ID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "build_id": "Build ID", + "part_id": "Build Part ID", + "employee_id": "Employee ID", + }, +) + +RelationshipEmployee2BuildLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "company_id": "Şirket ID", + "employee_id": "Çalışan ID", + "member_id": "Üye ID", + "relationship_type": "İlişki Tipi", + "show_only": "Sadece Göster", + }, + en={ + **CrudCollectionLanguageModel["en"], + "company_id": "Company ID", + "employee_id": "Employee ID", + "member_id": "Member ID", + "relationship_type": "Relationship Type", + "show_only": "Show Only", + }, +) + +BuildLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "gov_address_code": "Adres Kodu", + "build_name": "Bina Adı", + "build_no": "Bina No", + "max_floor": "Max Kat", + "underground_floor": "Zemin Kat", + "build_date": "Bina Tarihi", + "decision_period_date": "Karar Dönemi Tarihi", + "tax_no": "Vergi No", + "lift_count": "Asansör Sayısı", + "heating_system": "Isıtma Sistemi", + "cooling_system": "Soğutma Sistemi", + "hot_water_system": "Sıcak Su Sistemi", + "block_service_man_count": "Blok Hizmet Görevlisi Sayısı", + "security_service_man_count": "Güvenlik Görevlisi Sayısı", + "garage_count": "Garaj Sayısı", + "management_room_id": "Yönetim Odası ID", + "site_id": "Site ID", + "site_uu_id": "Site UUID", + "address_id": "Adres ID", + "address_uu_id": "Adres UUID", + "build_types_id": "Bina Tipi ID", + "build_types_uu_id": "Bina Tipi UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "gov_address_code": "Address Code", + "build_name": "Building Name", + "build_no": "Building Number", + "max_floor": "Max Floor", + "underground_floor": "Underground Floor", + "build_date": "Building Date", + "decision_period_date": "Decision Period Date", + "tax_no": "Tax No", + "lift_count": "Lift Count", + "heating_system": "Heating System", + "cooling_system": "Cooling System", + "hot_water_system": "Hot Water System", + "block_service_man_count": "Block Service Man Count", + "security_service_man_count": "Security Service Man Count", + "garage_count": "Garage Count", + "management_room_id": "Management Room ID", + "site_id": "Site ID", + "site_uu_id": "Site UUID", + "address_id": "Address ID", + "address_uu_id": "Address UUID", + "build_types_id": "Build Types ID", + "build_types_uu_id": "Build Types UUID", + }, +) + +BuildPartsLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "address_gov_code": "Adres Kodu", + "part_no": "Bina Parça No", + "part_level": "Bina Parça Katı", + "part_code": "Bina Parça Kodu", + "part_gross_size": "Bina Parça Brüt Alanı", + "part_net_size": "Bina Parça Net Alanı", + "default_accessory": "Varsayılan Aksesuar", + "human_livable": "İnsan Yaşam Alanı", + "due_part_key": "Ödeme Grubu", + "build_id": "Bina ID", + "build_uu_id": "Bina UUID", + "part_direction_id": "Bina Parça Yönü ID", + "part_direction_uu_id": "Bina Parça Yönü UUID", + "part_type_id": "Bina Parça Tipi ID", + "part_type_uu_id": "Bina Parça Tipi UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "address_gov_code": "Address Code", + "part_no": "Part Number", + "part_level": "Part Level", + "part_code": "Part Code", + "part_gross_size": "Part Gross Size", + "part_net_size": "Part Net Size", + "default_accessory": "Default Accessory", + "human_livable": "Human Livable", + "due_part_key": "Due Part Key", + "build_id": "Build ID", + "build_uu_id": "Build UUID", + "part_direction_id": "Part Direction ID", + "part_direction_uu_id": "Part Direction UUID", + "part_type_id": "Part Type ID", + "part_type_uu_id": "Part Type UUID", + }, +) + + +BuildLivingSpaceLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "fix_value": "Düz Değer", + "fix_percent": "Düz Yüzde", + "agreement_no": "Anlaşma No", + "marketing_process": "Pazarlama İşlemi", + "marketing_layer": "Pazarlama Katmanı", + "build_parts_id": "Bina Parça ID", + "build_parts_uu_id": "Bina Parça UUID", + "person_id": "Kişi ID", + "person_uu_id": "Kişi UUID", + "occupant_type": "Sakin Tipi", + "occupant_type_uu_id": "Sakin Tipi UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "fix_value": "Fixed Value", + "fix_percent": "Fixed Percent", + "agreement_no": "Agreement No", + "marketing_process": "Marketing Process", + "marketing_layer": "Marketing Layer", + "build_parts_id": "Build Part ID", + "build_parts_uu_id": "Build Part UUID", + "person_id": "Person ID", + "person_uu_id": "Person UUID", + "occupant_type": "Occupant Type", + "occupant_type_uu_id": "Occupant Type UUID", + }, +) + +BuildManagementLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "discounted_percentage": "İndirim Yüzdesi", + "discounted_price": "İndirimli Fiyat", + "calculated_price": "Hesaplanan Fiyat", + "occupant_type": "Sakin Tipi", + "occupant_type_uu_id": "Sakin Tipi UUID", + "build_id": "Bina ID", + "build_uu_id": "Bina UUID", + "build_parts_id": "Bina Parça ID", + "build_parts_uu_id": "Bina Parça UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "discounted_percentage": "Discounted Percentage", + "discounted_price": "Discounted Price", + "calculated_price": "Calculated Price", + "occupant_type": "Occupant Type", + "occupant_type_uu_id": "Occupant Type UUID", + "build_id": "Build ID", + "build_uu_id": "Build UUID", + "build_parts_id": "Build Part ID", + "build_parts_uu_id": "Build Part UUID", + }, +) + +BuildAreaLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "area_name": "Alan Adı", + "area_code": "Alan Kodu", + "area_type": "Alan Tipi", + "area_direction": "Alan Yönü", + "area_gross_size": "Alan Brüt Alanı", + "area_net_size": "Alan Net Alanı", + "width": "En", + "size": "Boyut", + "build_id": "Bina ID", + "build_uu_id": "Bina UUID", + "part_type_id": "Bina Parça Tipi ID", + "part_type_uu_id": "Bina Parça Tipi UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "area_name": "Area Name", + "area_code": "Area Code", + "area_type": "Area Type", + "area_direction": "Area Direction", + "area_gross_size": "Area Gross Size", + "area_net_size": "Area Net Size", + "width": "Width", + "size": "Size", + "build_id": "Build ID", + "build_uu_id": "Build UUID", + "part_type_id": "Part Type ID", + "part_type_uu_id": "Part Type UUID", + }, +) + + +BuildSitesLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "site_name": "Site Adı", + "site_no": "Site No", + "address_id": "Adres ID", + "address_uu_id": "Adres UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "site_name": "Site Name", + "site_no": "Site No", + "address_id": "Address ID", + "address_uu_id": "Address UUID", + }, +) + +BuildCompaniesProvidingLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "build_id": "Bina ID", + "build_uu_id": "Bina UUID", + "company_id": "Şirket ID", + "company_uu_id": "Şirket UUID", + "provide_id": "Sağlayıcı ID", + "provide_uu_id": "Sağlayıcı UUID", + "contract_id": "Sözleşme ID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "build_id": "Build ID", + "build_uu_id": "Build UUID", + "company_id": "Company ID", + "company_uu_id": "Company UUID", + "provide_id": "Provide ID", + "provide_uu_id": "Provide UUID", + "contract_id": "Contract ID", + }, +) + + +BuildPersonProvidingLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "build_id": "Bina ID", + "build_uu_id": "Bina UUID", + "people_id": "Kişi ID", + "people_uu_id": "Kişi UUID", + "provide_id": "Sağlayıcı ID", + "provide_uu_id": "Sağlayıcı UUID", + "contract_id": "Sözleşme ID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "build_id": "Build ID", + "build_uu_id": "Build UUID", + "people_id": "People ID", + "people_uu_id": "People UUID", + "provide_id": "Provide ID", + "provide_uu_id": "Provide UUID", + "contract_id": "Contract ID", + }, +) diff --git a/LanguageModels/Database/building/decision_book.py b/LanguageModels/Database/building/decision_book.py new file mode 100644 index 0000000..fb2f6f5 --- /dev/null +++ b/LanguageModels/Database/building/decision_book.py @@ -0,0 +1,398 @@ +from LanguageModels.Database.Mixins.crud_mixin import CrudCollectionLanguageModel + +BuildDecisionBookLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "decision_book_pdf_path": "Karar Defteri PDF Yolu", + "resp_company_fix_wage": "Firma Sabit Ücreti", + "is_out_sourced": "Dış Kaynak Kullanımı", + "meeting_date": "Toplantı Tarihi", + "decision_type": "Karar Türü", + "meeting_is_completed": "Toplantı Tamamlandı", + "meeting_completed_date": "Toplantı Tamamlanma Tarihi", + "build_id": "Bina ID", + "build_uu_id": "Bina UUID", + "resp_company_id": "Sorumlu Firma ID", + "resp_company_uu_id": "Sorumlu Firma UUID", + "contact_id": "İletişim ID", + "contact_uu_id": "İletişim UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "decision_book_pdf_path": "Decision Book PDF Path", + "resp_company_fix_wage": "Resp Company Fix Wage", + "is_out_sourced": "Is Out Sourced", + "meeting_date": "Meeting Date", + "decision_type": "Decision Type", + "meeting_is_completed": "Meeting Is Completed", + "meeting_completed_date": "Meeting Completed Date", + "build_id": "Build ID", + "build_uu_id": "Build UUID", + "resp_company_id": "Resp Company ID", + "resp_company_uu_id": "Resp Company UUID", + "contact_id": "Contact ID", + "contact_uu_id": "Contact UUID", + }, +) + +BuildDecisionBookInvitationsLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "build_id": "Bina ID", + "build_uu_id": "Bina UUID", + "decision_book_id": "Karar Defteri ID", + "decision_book_uu_id": "Karar Defteri UUID", + "invitation_type": "Davet Türü", + "invitation_attempt": "Davet Denemesi", + "living_part_count": "Yaşam Bölüm Sayısı", + "living_part_percentage": "Yaşam Bölüm Yüzdesi", + "message": "Davet Mesajı", + "planned_date": "Planlanan Tarih", + "planned_date_expires": "Planlanan Tarih Bitiş", + }, + en={ + **CrudCollectionLanguageModel["en"], + "build_id": "Build ID", + "build_uu_id": "Build UUID", + "decision_book_id": "Decision Book ID", + "decision_book_uu_id": "Decision Book UUID", + "invitation_type": "Invitation Type", + "invitation_attempt": "Invitation Attempt", + "living_part_count": "Living Part Count", + "living_part_percentage": "Living Part Percentage", + "message": "Message", + "planned_date": "Planned Date", + "planned_date_expires": "Planned Date Expires", + }, +) + +BuildDecisionBookPersonLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "dues_percent_discount": "Aidat İndirim Oranı", + "dues_fix_discount": "Aidat Sabit İndirim", + "dues_discount_approval_date": "İndirim Onay Tarihi", + "send_date": "Gönderme Tarihi", + "is_attending": "Katılıyor", + "confirmed_date": "Onay Tarihi", + "token": "Token", + "vicarious_person_id": "Vekil Kişi ID", + "vicarious_person_uu_id": "Vekil Kişi UUID", + "invite_id": "Davet ID", + "invite_uu_id": "Davet UUID", + "build_decision_book_id": "Karar Defteri ID", + "build_decision_book_uu_id": "Karar Defteri UUID", + "build_living_space_id": "Yaşam Alanı ID", + "build_living_space_uu_id": "Yaşam Alanı UUID", + "person_id": "Kişi ID", + "person_uu_id": "Kişi UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "dues_percent_discount": "Dues Percent Discount", + "dues_fix_discount": "Dues Fix Discount", + "dues_discount_approval_date": "Dues Discount Approval Date", + "send_date": "Send Date", + "is_attending": "Is Attending", + "confirmed_date": "Confirmed Date", + "token": "Token", + "vicarious_person_id": "Vicarious Person ID", + "vicarious_person_uu_id": "Vicarious Person UUID", + "invite_id": "Invite ID", + "invite_uu_id": "Invite UUID", + "build_decision_book_id": "Decision Book ID", + "build_decision_book_uu_id": "Decision Book UUID", + "build_living_space_id": "Living Space ID", + "build_living_space_uu_id": "Living Space UUID", + "person_id": "Person ID", + "person_uu_id": "Person UUID", + }, +) + +BuildDecisionBookPersonOccupantsLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "build_decision_book_person_id": "Karar Defteri Kişi ID", + "build_decision_book_person_uu_id": "Karar Defter Kişi UUID", + "invite_id": "Davet ID", + "invite_uu_id": "Davet UUID", + "occupant_type_id": "Kişi Tür ID", + "occupant_type_uu_id": "Kişi Tür UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "build_decision_book_person_id": "Build Decision Book Person ID", + "build_decision_book_person_uu_id": "Build Decision Book Person UUID", + "invite_id": "Invite ID", + "invite_uu_id": "Invite UUID", + "occupant_type_id": "Occupant Type ID", + "occupant_type_uu_id": "Occupant Type UUID", + }, +) + +BuildDecisionBookItemsLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "item_order": "Madde Sırası", + "item_comment": "Madde Yorumu", + "item_objection": "Madde İtirazı", + "info_is_completed": "Bilgi Tamamlandı", + "is_payment_created": "Ödeme Yapıldı", + "info_type_id": "Bilgi Türü ID", + "info_type_uu_id": "Bilgi Türü UUID", + "build_decision_book_id": "Karar Defteri ID", + "build_decision_book_uu_id": "Karar Defteri UUID", + "item_short_comment": "Kısa Yorum", + }, + en={ + **CrudCollectionLanguageModel["en"], + "item_order": "Item Order", + "item_comment": "Item Comment", + "item_objection": "Item Objection", + "info_is_completed": "Info Is Completed", + "is_payment_created": "Is Payment Created", + "info_type_id": "Info Type ID", + "info_type_uu_id": "Info Type UUID", + "build_decision_book_id": "Build Decision Book ID", + "build_decision_book_uu_id": "Build Decision Book UUID", + "item_short_comment": "Item Short Comment", + }, +) + +BuildDecisionBookItemsUnapprovedLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "item_objection": "Madde İtirazı", + "item_order": "Madde Sırası", + "decision_book_item_id": "Karar Defteri Madde ID", + "decision_book_item_uu_id": "Karar Defteri Madde UUID", + "person_id": "Kişi ID", + "person_uu_id": "Kişi UUID", + "build_decision_book_item": "Karar Defteri Madde ID", + "build_decision_book_item_uu_id": "Karar Defteri Madde UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "item_objection": "Item Objection", + "item_order": "Item Order", + "decision_book_item_id": "Decision Book Item ID", + "decision_book_item_uu_id": "Decision Book Item UUID", + "person_id": "Person ID", + "person_uu_id": "Person UUID", + "build_decision_book_item": "Build Decision Book Item ID", + "build_decision_book_item_uu_id": "Build Decision Book Item UUID", + }, +) + +BuildDecisionBookPaymentsLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "payment_plan_time_periods": "Ödeme Planı Zaman Periyodu", + "process_date": "Ödeme Tarihi", + "payment_amount": "Ödeme Miktarı", + "currency": "Para Birimi", + "payment_types_id": "Ödeme Türü ID", + "payment_types_uu_id": "Ödeme Türü UUID", + "period_time": "Dönem Zamanı", + "process_date_y": "Tarih Yılı", + "process_date_m": "Tarih Ayı", + "build_decision_book_item_id": "Karar Defteri Madde ID", + "build_decision_book_item_uu_id": "Karar Defteri Madde UUID", + "build_parts_id": "Bina Parça ID", + "build_parts_uu_id": "Bina Parça UUID", + "decision_book_project_id": "Karar Defteri Proje ID", + "decision_book_project_uu_id": "Karar Defteri Proje UUID", + "account_records_id": "Hesap Kayıtları ID", + "account_records_uu_id": "Hesap Kayıtları UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "payment_plan_time_periods": "Payment Plan Time Periods", + "process_date": "Process Date", + "payment_amount": "Payment Amount", + "currency": "Currency", + "payment_types_id": "Payment Types ID", + "payment_types_uu_id": "Payment Types UUID", + "period_time": "Period Time", + "process_date_y": "Process Date Year", + "process_date_m": "Process Date Month", + "build_decision_book_item_id": "Build Decision Book Item ID", + "build_decision_book_item_uu_id": "Build Decision Book Item UUID", + "build_parts_id": "Build Parts ID", + "build_parts_uu_id": "Build Parts UUID", + "decision_book_project_id": "Decision Book Project ID", + "decision_book_project_uu_id": "Decision Book Project UUID", + "account_records_id": "Account Records ID", + "account_records_uu_id": "Account Records UUID", + }, +) + +BuildDecisionBookLegalLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "period_start_date": "Dönem Başlangıç Tarihi", + "lawsuits_decision_number": "Dava Karar Numarası", + "lawsuits_decision_date": "Dava Karar Tarihi", + "period_stop_date": "Dönem Bitiş Tarihi", + "decision_book_pdf_path": "Karar Defteri PDF Yolu", + "resp_company_total_wage": "Firma Toplam Ücreti", + "contact_agreement_path": "İletişim Anlaşma Yolu", + "contact_agreement_date": "İletişim Anlaşma Tarihi", + "meeting_date": "Toplantı Tarihi", + "lawsuits_type": "Dava Türü", + "lawsuits_name": "Dava Adı", + "lawsuits_note": "Dava Notu", + "lawyer_cost": "Avukat Ücreti", + "mediator_lawyer_cost": "Arabulucu Avukat Ücreti", + "other_cost": "Diğer Ücret", + "legal_cost": "Yasal Ücret", + "approved_cost": "Onaylanan Ücret", + "total_price": "Toplam Ücret", + "build_db_item_id": "Karar Defteri Madde ID", + "build_db_item_uu_id": "Karar Defteri Madde UUID", + "resp_attorney_id": "Sorumlu Avukat ID", + "resp_attorney_uu_id": "Sorumlu Avukat UUID", + "resp_attorney_company_id": "Sorumlu Avukat Firma ID", + "resp_attorney_company_uu_id": "Sorumlu Avukat Firma UUID", + "mediator_lawyer_person_id": "Arabulucu Avukat Kişi ID", + "mediator_lawyer_person_uu_id": "Arabulucu Avukat Kişi UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "period_start_date": "Period Start Date", + "lawsuits_decision_number": "Lawsuits Decision Number", + "lawsuits_decision_date": "Lawsuits Decision Date", + "period_stop_date": "Period Stop Date", + "decision_book_pdf_path": "Decision Book PDF Path", + "resp_company_total_wage": "Resp Company Total Wage", + "contact_agreement_path": "Contact Agreement Path", + "contact_agreement_date": "Contact Agreement Date", + "meeting_date": "Meeting Date", + "lawsuits_type": "Lawsuits Type", + "lawsuits_name": "Lawsuits Name", + "lawsuits_note": "Lawsuits Note", + "lawyer_cost": "Lawyer Cost", + "mediator_lawyer_cost": "Mediator Lawyer Cost", + "other_cost": "Other Cost", + "legal_cost": "Legal Cost", + "approved_cost": "Approved Cost", + "total_price": "Total Price", + "build_db_item_id": "Build Decision Book Item ID", + "build_db_item_uu_id": "Build Decision Book Item UUID", + "resp_attorney_id": "Resp Attorney ID", + "resp_attorney_uu_id": "Resp Attorney UUID", + "resp_attorney_company_id": "Resp Attorney Company ID", + "resp_attorney_company_uu_id": "Resp Attorney Company UUID", + "mediator_lawyer_person_id": "Mediator Lawyer Person ID", + "mediator_lawyer_person_uu_id": "Mediator Lawyer Person UUID", + }, +) + +BuildDecisionBookProjectsLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "project_no": "Proje No", + "project_name": "Proje Adı", + "project_start_date": "Proje Başlangıç Tarihi", + "project_stop_date": "Proje Bitiş Tarihi", + "project_type": "Proje Türü", + "project_note": "Proje Notu", + "decision_book_pdf_path": "Karar Defteri PDF Yolu", + "is_completed": "Proje Tamamlandı", + "status_code": "Durum Kodu", + "resp_company_fix_wage": "Firma Sabit Ücreti", + "is_out_sourced": "Dış Kaynak Kullanımı", + "meeting_date": "Toplantı Tarihi", + "currency": "Para Birimi", + "bid_price": "Teklif Fiyatı", + "approved_price": "Onaylanan Fiyat", + "final_price": "Son Fiyat", + "contact_id": "İletişim ID", + "contact_uu_id": "İletişim UUID", + "build_decision_book_id": "Karar Defteri ID", + "build_decision_book_uu_id": "Karar Defteri UUID", + "build_decision_book_item_id": "Karar Defteri Madde ID", + "build_decision_book_item_uu_id": "Karar Defteri Madde UUID", + "project_response_living_space_id": "Proje Yanıt Yaşam Alanı ID", + "project_response_living_space_uu_id": "Proje Yanıt Yaşam Alanı UUID", + "resp_company_id": "Sorumlu Firma ID", + "resp_company_uu_id": "Sorumlu Firma UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "project_no": "Project No", + "project_name": "Project Name", + "project_start_date": "Project Start Date", + "project_stop_date": "Project Stop Date", + "project_type": "Project Type", + "project_note": "Project Note", + "decision_book_pdf_path": "Decision Book PDF Path", + "is_completed": "Is Completed", + "status_code": "Status Code", + "resp_company_fix_wage": "Resp Company Fix Wage", + "is_out_sourced": "Is Out Sourced", + "meeting_date": "Meeting Date", + "currency": "Currency", + "bid_price": "Bid Price", + "approved_price": "Approved Price", + "final_price": "Final Price", + "contact_id": "Contact ID", + "contact_uu_id": "Contact UUID", + "build_decision_book_id": "Build Decision Book ID", + "build_decision_book_uu_id": "Build Decision Book UUID", + "build_decision_book_item_id": "Build Decision Book Item ID", + "build_decision_book_item_uu_id": "Build Decision Book Item UUID", + "project_response_living_space_id": "Project Response Living Space ID", + "project_response_living_space_uu_id": "Project Response Living Space UUID", + "resp_company_id": "Resp Company ID", + "resp_company_uu_id": "Resp Company UUID", + }, +) + +BuildDecisionBookProjectPersonLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "dues_percent_discount": "Aidat İndirim Oranı", + "job_fix_wage": "İş Sabit Ücreti", + "bid_price": "Teklif Fiyatı", + "decision_price": "Karar Fiyatı", + "build_decision_book_project_id": "Karar Defteri Proje ID", + "build_decision_book_project_uu_id": "Karar Defteri Proje UUID", + "living_space_id": "Yaşam Alanı ID", + "living_space_uu_id": "Yaşam Alanı UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "dues_percent_discount": "Dues Percent Discount", + "job_fix_wage": "Job Fix Wage", + "bid_price": "Bid Price", + "decision_price": "Decision Price", + "build_decision_book_project_id": "Build Decision Book Project ID", + "build_decision_book_project_uu_id": "Build Decision Book Project UUID", + "living_space_id": "Living Space ID", + "living_space_uu_id": "Living Space UUID", + }, +) + +BuildDecisionBookProjectItemsLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "item_header": "Madde Başlığı", + "item_comment": "Madde Yorumu", + "attachment_pdf_path": "Ek PDF Yolu", + "item_estimated_cost": "Tahmini Maliyet", + "item_short_comment": "Kısa Yorum", + "build_decision_book_project_id": "Karar Defteri Proje ID", + "build_decision_book_project_uu_id": "Karar Defteri Proje UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "item_header": "Item Header", + "item_comment": "Item Comment", + "attachment_pdf_path": "Attachment PDF Path", + "item_estimated_cost": "Estimated Cost", + "item_short_comment": "Item Short Comment", + "build_decision_book_project_id": "Build Decision Book Project ID", + "build_decision_book_project_uu_id": "Build Decision Book Project UUID", + }, +) diff --git a/LanguageModels/Database/company/company.py b/LanguageModels/Database/company/company.py new file mode 100644 index 0000000..94bdb14 --- /dev/null +++ b/LanguageModels/Database/company/company.py @@ -0,0 +1,65 @@ +from LanguageModels.Database.Mixins.crud_mixin import CrudCollectionLanguageModel + +RelationshipDutyCompanyLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "owner_id": "Sahip ID", + "duties_id": "Görev ID", + "member_id": "Üye ID", + "parent_id": "Üst ID", + "relationship_type": "İlişki Tipi", + "child_count": "Çocuk Sayısı", + "show_only": "Sadece Göster", + }, + en={ + **CrudCollectionLanguageModel["en"], + "owner_id": "Owner ID", + "duties_id": "Duties ID", + "member_id": "Member ID", + "parent_id": "Parent ID", + "relationship_type": "Relationship Type", + "child_count": "Child Count", + "show_only": "Show Only", + }, +) + +CompaniesLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "formal_name": "Resmi Ad", + "company_type": "Şirket Tipi", + "commercial_type": "Ticari Tip", + "tax_no": "Vergi No", + "public_name": "Kamu Adı", + "company_tag": "Şirket Etiketi", + "default_lang_type": "Varsayılan Dil Tipi", + "default_money_type": "Varsayılan Para Tipi", + "is_commercial": "Ticari", + "is_blacklist": "Kara Liste", + "parent_id": "Üst ID", + "workplace_no": "İşyeri No", + "official_address_id": "Resmi Adres ID", + "official_address_uu_id": "Resmi Adres UUID", + "top_responsible_company_id": "Üst Sorumlu Şirket ID", + "top_responsible_company_uu_id": "Üst Sorumlu Şirket UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "formal_name": "Formal Name", + "company_type": "Company Type", + "commercial_type": "Commercial Type", + "tax_no": "Tax No", + "public_name": "Public Name", + "company_tag": "Company Tag", + "default_lang_type": "Default Language Type", + "default_money_type": "Default Money Type", + "is_commercial": "Commercial", + "is_blacklist": "Blacklist", + "parent_id": "Parent ID", + "workplace_no": "Workplace No", + "official_address_id": "Official Address ID", + "official_address_uu_id": "Official Address UUID", + "top_responsible_company_id": "Top Responsible Company ID", + "top_responsible_company_uu_id": "Top Responsible Company UUID", + }, +) diff --git a/LanguageModels/Database/company/department.py b/LanguageModels/Database/company/department.py new file mode 100644 index 0000000..77b79f1 --- /dev/null +++ b/LanguageModels/Database/company/department.py @@ -0,0 +1,62 @@ +from LanguageModels.Database.Mixins.crud_mixin import CrudCollectionLanguageModel + +DepartmentsLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "parent_department_id": "Üst Departman ID", + "department_code": "Departman Kodu", + "department_name": "Departman Adı", + "department_description": "Departman Açıklaması", + "company_id": "Şirket ID", + "company_uu_id": "Şirket UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "parent_department_id": "Parent Department ID", + "department_code": "Department Code", + "department_name": "Department Name", + "department_description": "Department Description", + "company_id": "Company ID", + "company_uu_id": "Company UUID", + }, +) + +DutiesLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "users_default_duty": "Kullanıcılar için Varsayılan Görev", + "company_id": "Şirket ID", + "company_uu_id": "Şirket UUID", + "duties_id": "Görev ID", + "duties_uu_id": "Görev UUID", + "department_id": "Departman ID", + "department_uu_id": "Departman UUID", + "management_duty": "Yönetim Görevi", + }, + en={ + **CrudCollectionLanguageModel["en"], + "users_default_duty": "Default Duty for Users", + "company_id": "Company ID", + "company_uu_id": "Company UUID", + "duties_id": "Duty ID", + "duties_uu_id": "Duty UUID", + "department_id": "Department ID", + "department_uu_id": "Department UUID", + "management_duty": "Management Duty", + }, +) + +DutyLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "duty_name": "Görev Adı", + "duty_code": "Görev Kodu", + "duty_description": "Görev Açıklaması", + }, + en={ + **CrudCollectionLanguageModel["en"], + "duty_name": "Duty Name", + "duty_code": "Duty Code", + "duty_description": "Duty Description", + }, +) diff --git a/LanguageModels/Database/company/employee.py b/LanguageModels/Database/company/employee.py new file mode 100644 index 0000000..391d1f2 --- /dev/null +++ b/LanguageModels/Database/company/employee.py @@ -0,0 +1,71 @@ +from LanguageModels.Database.Mixins.crud_mixin import CrudCollectionLanguageModel + +StaffLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "staff_description": "Personel Açıklaması", + "staff_name": "Personel Adı", + "staff_code": "Personel Kodu", + "duties_id": "Görev ID", + "duties_uu_id": "Görev UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "staff_description": "Staff Description", + "staff_name": "Staff Name", + "staff_code": "Staff Code", + "duties_id": "Duty ID", + "duties_uu_id": "Duty UUID", + }, +) + +EmployeesLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "staff_id": "Personel ID", + "staff_uu_id": "Personel UUID", + "people_id": "Kişi ID", + "people_uu_id": "Kişi UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "staff_id": "Staff ID", + "staff_uu_id": "Staff UUID", + "people_id": "People ID", + "people_uu_id": "People UUID", + }, +) + +EmployeeHistoryLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "staff_id": "Personel ID", + "staff_uu_id": "Personel UUID", + "people_id": "Kişi ID", + "people_uu_id": "Kişi UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "staff_id": "Staff ID", + "staff_uu_id": "Staff UUID", + "people_id": "People ID", + "people_uu_id": "People UUID", + }, +) + +EmployeesSalariesLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "gross_salary": "Brüt Maaş", + "net_salary": "Net Maaş", + "people_id": "Kişi ID", + "people_uu_id": "Kişi UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "gross_salary": "Gross Salary", + "net_salary": "Net Salary", + "people_id": "People ID", + "people_uu_id": "People UUID", + }, +) diff --git a/LanguageModels/Database/event/event.py b/LanguageModels/Database/event/event.py new file mode 100644 index 0000000..184608e --- /dev/null +++ b/LanguageModels/Database/event/event.py @@ -0,0 +1,185 @@ +from LanguageModels.Database.Mixins.crud_mixin import CrudCollectionLanguageModel + + +EventsLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "event_type": "Etkinlik Türü", + "function_code": "Fonksiyon Kodu", + "function_class": "Fonksiyon Sınıfı", + "description": "Açıklama", + "property_description": "Özellik Açıklaması", + "marketing_layer": "Pazarlama Katmanı", + "cost": "Maliyet", + "unit_price": "Birim Fiyat", + "endpoint_id": "Endpoint ID", + "endpoint_uu_id": "Endpoint UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "event_type": "Event Type", + "function_code": "Function Code", + "function_class": "Function Class", + "description": "Description", + "property_description": "Property Description", + "marketing_layer": "Marketing Layer", + "cost": "Cost", + "unit_price": "Unit Price", + "endpoint_id": "Endpoint ID", + "endpoint_uu_id": "Endpoint UUID", + }, +) + +ModulesLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "module_name": "Modül Adı", + "module_description": "Modül Açıklaması", + "module_code": "Modül Kodu", + "module_layer": "Modül Katmanı", + "is_default_module": "Varsayılan Modül", + }, + en={ + **CrudCollectionLanguageModel["en"], + "module_name": "Module Name", + "module_description": "Module Description", + "module_code": "Module Code", + "module_layer": "Module Layer", + "is_default_module": "Default Module", + }, +) + +ServicesLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "module_id": "Modül ID", + "module_uu_id": "Modül UUID", + "service_name": "Servis Adı", + "service_description": "Servis Açıklaması", + "service_code": "Servis Kodu", + "related_responsibility": "İlgili Sorumluluk", + }, + en={ + **CrudCollectionLanguageModel["en"], + "module_id": "Module ID", + "module_uu_id": "Module UUID", + "service_name": "Service Name", + "service_description": "Service Description", + "service_code": "Service Code", + "related_responsibility": "Related Responsibility", + }, +) + +Service2EventsLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "service_id": "Servis ID", + "service_uu_id": "Servis UUID", + "event_id": "Etkinlik ID", + "event_uu_id": "Etkinlik UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "service_id": "Service ID", + "service_uu_id": "Service UUID", + "event_id": "Event ID", + "event_uu_id": "Event UUID", + }, +) + +Event2OccupantExtraLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "build_living_space_id": "Bina Yaşam Alanı ID", + "build_living_space_uu_id": "Bina Yaşam Alanı UUID", + "event_id": "Etkinlik ID", + "event_uu_id": "Etkinlik UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "build_living_space_id": "Build Living Space ID", + "build_living_space_uu_id": "Build Living Space UUID", + "event_id": "Event ID", + "event_uu_id": "Event UUID", + }, +) + +Event2EmployeeExtraLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "employee_id": "Çalışan ID", + "employee_uu_id": "Çalışan UUID", + "event_id": "Etkinlik ID", + "event_uu_id": "Etkinlik UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "employee_id": "Employee ID", + "employee_uu_id": "Employee UUID", + "event_id": "Event ID", + "event_uu_id": "Event UUID", + }, +) + +Event2EmployeeLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "employee_id": "Çalışan ID", + "employee_uu_id": "Çalışan UUID", + "event_service_id": "Etkinlik Servis ID", + "event_service_uu_id": "Etkinlik Servis UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "employee_id": "Employee ID", + "employee_uu_id": "Employee UUID", + "event_service_id": "Event Service ID", + "event_service_uu_id": "Event Service UUID", + }, +) + +Event2OccupantLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "build_living_space_id": "Bina Yaşam Alanı ID", + "build_living_space_uu_id": "Bina Yaşam Alanı UUID", + "event_service_id": "Etkinlik Servis ID", + "event_service_uu_id": "Etkinlik Servis UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "build_living_space_id": "Build Living Space ID", + "build_living_space_uu_id": "Build Living Space UUID", + "event_service_id": "Event Service ID", + "event_service_uu_id": "Event Service UUID", + }, +) + +ModulePriceLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "campaign_code": "Kampanya Kodu", + "module_id": "Modül ID", + "module_uu_id": "Modül UUID", + "service_id": "Servis ID", + "service_uu_id": "Servis UUID", + "event_id": "Etkinlik ID", + "event_uu_id": "Etkinlik UUID", + "is_counted_percentage": "İndirim Oranı", + "discounted_price": "İndirimli Fiyat", + "calculated_price": "Hesaplanan Fiyat", + }, + en={ + **CrudCollectionLanguageModel["en"], + "campaign_code": "Campaign Code", + "module_id": "Module ID", + "module_uu_id": "Module UUID", + "service_id": "Service ID", + "service_uu_id": "Service UUID", + "event_id": "Event ID", + "event_uu_id": "Event UUID", + "is_counted_percentage": "Discount Rate", + "discounted_price": "Discounted Price", + "calculated_price": "Calculated Price", + }, +) diff --git a/LanguageModels/Database/identity/identity.py b/LanguageModels/Database/identity/identity.py new file mode 100644 index 0000000..aeb7869 --- /dev/null +++ b/LanguageModels/Database/identity/identity.py @@ -0,0 +1,424 @@ +from LanguageModels.Database.Mixins.crud_mixin import CrudCollectionLanguageModel + +UsersTokensLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "user_id": "Kullanıcı ID", + "token_type": "Token Türü", + "token": "Token", + "domain": "Domain", + "expires_at": "Bitiş Tarihi", + }, + en={ + **CrudCollectionLanguageModel["en"], + "user_id": "User ID", + "token_type": "Token Type", + "token": "Token", + "domain": "Domain", + "expires_at": "Expires At", + }, +) + +UsersLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "user_tag": "Kullanıcı Etiketi", + "email": "E-posta", + "phone_number": "Telefon Numarası", + "via": "Via", + "avatar": "Avatar", + "hash_password": "Şifre", + "password_token": "Şifre Token", + "remember_me": "Beni Hatırla", + "password_expires_day": "Şifre Son Kullanma Günü", + "password_expiry_begins": "Şifre Son Kullanma Başlangıç", + "related_company": "İlgili Şirket", + "person_id": "Kişi ID", + "person_uu_id": "Kişi UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "user_tag": "User Tag", + "email": "Email", + "phone_number": "Phone Number", + "via": "Via", + "avatar": "Avatar", + "hash_password": "Password", + "password_token": "Password Token", + "remember_me": "Remember Me", + "password_expires_day": "Password Expires Day", + "password_expiry_begins": "Password Expiry Begins", + "related_company": "Related Company", + "person_id": "Person ID", + "person_uu_id": "Person UUID", + }, +) + +RelationshipDutyPeopleLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "company_id": "Şirket ID", + "duties_id": "Görev ID", + "member_id": "Üye ID", + "relationship_type": "İlişki Türü", + "show_only": "Sadece Göster", + }, + en={ + **CrudCollectionLanguageModel["en"], + "company_id": "Company ID", + "duties_id": "Duty ID", + "member_id": "Member ID", + "relationship_type": "Relationship Type", + "show_only": "Show Only", + }, +) + +PeopleLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "firstname": "Ad", + "surname": "Soyad", + "middle_name": "Orta Ad", + "sex_code": "Cinsiyet Kodu", + "person_ref": "Kişi Referansı", + "person_tag": "Kişi Etiketi", + "father_name": "Baba Adı", + "mother_name": "Anne Adı", + "country_code": "Ülke Kodu", + "national_identity_id": "Kimlik Numarası", + "birth_place": "Doğum Yeri", + "birth_date": "Doğum Tarihi", + "tax_no": "Vergi Numarası", + }, + en={ + **CrudCollectionLanguageModel["en"], + "firstname": "First Name", + "surname": "Last Name", + "middle_name": "Middle Name", + "sex_code": "Gender", + "person_ref": "Person Reference", + "person_tag": "Person Tag", + "father_name": "Father Name", + "mother_name": "Mother Name", + "country_code": "Country Code", + "national_identity_id": "National Identity ID", + "birth_place": "Birth Place", + "birth_date": "Birth Date", + "tax_no": "Tax No", + }, +) + +RelationshipEmployee2PostCodeLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "company_id": "Şirket ID", + "employee_id": "Çalışan ID", + "member_id": "Üye ID", + "relationship_type": "İlişki Türü", + "show_only": "Sadece Göster", + }, + en={ + **CrudCollectionLanguageModel["en"], + "company_id": "Company ID", + "employee_id": "Employee ID", + "member_id": "Member ID", + "relationship_type": "Relationship Type", + "show_only": "Show Only", + }, +) + +AddressPostcodeLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "street_id": "Sokak ID", + "street_uu_id": "Sokak UUID", + "postcode": "Posta Kodu", + }, + en={ + **CrudCollectionLanguageModel["en"], + "street_id": "Street ID", + "street_uu_id": "Street UUID", + "postcode": "Postcode", + }, +) + +AddressesLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "build_number": "Bina Numarası", + "door_number": "Kapı Numarası", + "floor_number": "Kat Numarası", + "comment_address": "Adres", + "letter_address": "Adres", + "short_letter_address": "Adres", + "latitude": "Enlem", + "longitude": "Boylam", + "street_id": "Sokak ID", + "street_uu_id": "Sokak UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "build_number": "Build Number", + "door_number": "Door Number", + "floor_number": "Floor Number", + "comment_address": "Address", + "letter_address": "Address", + "short_letter_address": "Address", + "latitude": "Latitude", + "longitude": "Longitude", + "street_id": "Street ID", + "street_uu_id": "Street UUID", + }, +) + +AddressGeographicLocationsLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "geo_table": "Tablo Adı", + "geo_id": "ID", + "geo_name": "Ad", + "geo_latitude": "Enlem", + "geo_longitude": "Boylam", + "geo_altitude": "Yükseklik", + "geo_description": "Açıklama", + "geo_area_size": "Alan", + "geo_population": "Nüfus", + }, + en={ + **CrudCollectionLanguageModel["en"], + "geo_table": "Table Name", + "geo_id": "ID", + "geo_name": "Name", + "geo_latitude": "Latitude", + "geo_longitude": "Longitude", + "geo_altitude": "Altitude", + "geo_description": "Description", + "geo_area_size": "Area", + "geo_population": "Population", + }, +) + +AddressCountryLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "country_code": "Ülke Kodu", + "country_name": "Ülke Adı", + "money_code": "Para Kodu", + "language": "Dil Kodu", + "address_geographic_id": "Adres Coğrafi ID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "country_code": "Country Code", + "country_name": "Country Name", + "money_code": "Money Code", + "language": "Language Code", + "address_geographic_id": "Address Geographic ID", + }, +) + +AddressStateLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "state_code": "Eyalet Kodu", + "state_name": "Eyalet Adı", + "licence_plate": "Plaka Kodu", + "phone_code": "Telefon Kodu", + "gov_code": "Hükümet Kodu", + "address_geographic_id": "Adres Coğrafi ID", + "country_id": "Ülke ID", + "country_uu_id": "Ülke UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "state_code": "State Code", + "state_name": "State Name", + "licence_plate": "Licence Plate", + "phone_code": "Phone Code", + "gov_code": "Government Code", + "address_geographic_id": "Address Geographic ID", + "country_id": "Country ID", + "country_uu_id": "Country UUID", + }, +) + +AddressCityLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "city_code": "Şehir Kodu", + "city_name": "Şehir Adı", + "licence_plate": "Plaka Kodu", + "phone_code": "Telefon Kodu", + "gov_code": "Hükümet Kodu", + "address_geographic_id": "Adres Coğrafi ID", + "state_id": "Eyalet ID", + "state_uu_id": "Eyalet UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "city_code": "City Code", + "city_name": "City Name", + "licence_plate": "Licence Plate", + "phone_code": "Phone Code", + "gov_code": "Government Code", + "address_geographic_id": "Address Geographic ID", + "state_id": "State ID", + "state_uu_id": "State UUID", + }, +) + +AddressDistrictLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "district_code": "İlçe Kodu", + "district_name": "İlçe Adı", + "phone_code": "Telefon Kodu", + "gov_code": "Hükümet Kodu", + "address_geographic_id": "Adres Coğrafi ID", + "city_id": "Şehir ID", + "city_uu_id": "Şehir UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "district_code": "District Code", + "district_name": "District Name", + "phone_code": "Phone Code", + "gov_code": "Government Code", + "address_geographic_id": "Address Geographic ID", + "city_id": "City ID", + "city_uu_id": "City UUID", + }, +) + +AddressLocalityLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "locality_code": "Mahalle Kodu", + "locality_name": "Mahalle Adı", + "type_code": "Tip Kodu", + "type_description": "Tip Açıklaması", + "gov_code": "Hükümet Kodu", + "address_show": "Adres Göster", + "address_geographic_id": "Adres Coğrafi ID", + "district_id": "İlçe ID", + "district_uu_id": "İlçe UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "locality_code": "Locality Code", + "locality_name": "Locality Name", + "type_code": "Type Code", + "type_description": "Type Description", + "gov_code": "Government Code", + "address_show": "Address Show", + "address_geographic_id": "Address Geographic ID", + "district_id": "District ID", + "district_uu_id": "District UUID", + }, +) + +AddressNeighborhoodLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "neighborhood_code": "Mahalle Kodu", + "neighborhood_name": "Mahalle Adı", + "type_code": "Tip Kodu", + "type_description": "Tip Açıklaması", + "gov_code": "Hükümet Kodu", + "address_show": "Adres Göster", + "address_geographic_id": "Adres Coğrafi ID", + "district_id": "İlçe ID", + "district_uu_id": "İlçe UUID", + "locality_id": "Mahalle ID", + "locality_uu_id": "Mahalle UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "neighborhood_code": "Neighborhood Code", + "neighborhood_name": "Neighborhood Name", + "type_code": "Type Code", + "type_description": "Type Description", + "gov_code": "Government Code", + "address_show": "Address Show", + "address_geographic_id": "Address Geographic ID", + "district_id": "District ID", + "district_uu_id": "District UUID", + "locality_id": "Locality ID", + "locality_uu_id": "Locality UUID", + }, +) + +AddressStreetLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "street_code": "Sokak Kodu", + "street_name": "Sokak Adı", + "type_code": "Tip Kodu", + "type_description": "Tip Açıklaması", + "gov_code": "Hükümet Kodu", + "address_geographic_id": "Adres Coğrafi ID", + "neighborhood_id": "Mahalle ID", + "neighborhood_uu_id": "Mahalle UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "street_code": "Street Code", + "street_name": "Street Name", + "type_code": "Type Code", + "type_description": "Type Description", + "gov_code": "Government Code", + "address_geographic_id": "Address Geographic ID", + "neighborhood_id": "Neighborhood ID", + "neighborhood_uu_id": "Neighborhood UUID", + }, +) + +OccupantTypesLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "occupant_type": "Kişi Türü", + "occupant_description": "Kişi Açıklaması", + "occupant_code": "Kişi Kodu", + "occupant_category": "Kişi Kategori", + "occupant_category_type": "Kişi Kategori Türü", + "occupant_is_unique": "Kişi Benzersiz", + }, + en={ + **CrudCollectionLanguageModel["en"], + "occupant_type": "Occupant Type", + "occupant_description": "Occupant Description", + "occupant_code": "Occupant Code", + "occupant_category": "Occupant Category", + "occupant_category_type": "Occupant Category Type", + "occupant_is_unique": "Occupant Unique", + }, +) + +ContractsLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "contract_type": "Sözleşme Türü", + "contract_title": "Sözleşme Başlığı", + "contract_details": "Sözleşme Detayları", + "contract_terms": "Sözleşme Şartları", + "contract_code": "Sözleşme Kodu", + "contract_date": "Sözleşme Tarihi", + "company_id": "Şirket ID", + "company_uu_id": "Şirket UUID", + "person_id": "Kişi ID", + "person_uu_id": "Kişi UUID", + }, + en={ + **CrudCollectionLanguageModel["en"], + "contract_type": "Contract Type", + "contract_title": "Contract Title", + "contract_details": "Contract Details", + "contract_terms": "Contract Terms", + "contract_code": "Contract Code", + "contract_date": "Contract Date", + "company_id": "Company ID", + "company_uu_id": "Company UUID", + "person_id": "Person ID", + "person_uu_id": "Person UUID", + }, +) diff --git a/LanguageModels/Database/rules/rules.py b/LanguageModels/Database/rules/rules.py new file mode 100644 index 0000000..4d3f52e --- /dev/null +++ b/LanguageModels/Database/rules/rules.py @@ -0,0 +1,20 @@ +from LanguageModels.Database.Mixins.crud_mixin import CrudCollectionLanguageModel + +EndpointRestrictionLanguageModel = dict( + tr={ + **CrudCollectionLanguageModel["tr"], + "endpoint_function": "API Fonksiyonu", + "endpoint_name": "API Adı", + "endpoint_method": "API Metodu", + "endpoint_desc": "API Açıklaması", + "endpoint_code": "API Kodu", + }, + en={ + **CrudCollectionLanguageModel["en"], + "endpoint_function": "API Function", + "endpoint_name": "API Name", + "endpoint_method": "API Method", + "endpoint_desc": "API Description", + "endpoint_code": "API Code", + }, +) diff --git a/LanguageModels/Errors/__init__.py b/LanguageModels/Errors/__init__.py new file mode 100644 index 0000000..bb27acf --- /dev/null +++ b/LanguageModels/Errors/__init__.py @@ -0,0 +1,3 @@ +from LanguageModels.Errors.base_languages import BaseErrorLanguageModels + +__all__ = ["BaseErrorLanguageModels"] diff --git a/ErrorHandlers/LanguageModels/base_languages.py b/LanguageModels/Errors/base_languages.py similarity index 100% rename from ErrorHandlers/LanguageModels/base_languages.py rename to LanguageModels/Errors/base_languages.py diff --git a/LanguageModels/__init__.py b/LanguageModels/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Schemas/__init__.py b/Schemas/__init__.py new file mode 100644 index 0000000..f3278e2 --- /dev/null +++ b/Schemas/__init__.py @@ -0,0 +1,179 @@ +# SQL Models +from Schemas.account.account import ( + AccountBooks, + AccountCodeParser, + AccountRecords, + AccountCodes, + AccountDetail, + AccountMaster, + AccountRecordExchanges, +) +from Schemas.building.budget import ( + DecisionBookBudgetBooks, + DecisionBookBudgetCodes, + DecisionBookBudgetMaster, + DecisionBookBudgets, +) +from Schemas.account.iban import ( + BuildIbans, + BuildIbanDescription, +) +from Schemas.api.encrypter import CrypterEngine +from Schemas.building.build import ( + Build, + BuildTypes, + BuildParts, + BuildArea, + BuildSites, + BuildLivingSpace, + BuildPersonProviding, + BuildCompaniesProviding, + RelationshipEmployee2Build, +) +from Schemas.building.decision_book import ( + BuildDecisionBook, + BuildDecisionBookItems, + BuildDecisionBookPerson, + BuildDecisionBookLegal, + BuildDecisionBookItemsUnapproved, + BuildDecisionBookInvitations, + BuildDecisionBookPayments, + BuildDecisionBookProjects, + BuildDecisionBookProjectPerson, + BuildDecisionBookPersonOccupants, + BuildDecisionBookProjectItems, +) +from Schemas.company.company import ( + Companies, + RelationshipDutyCompany, +) +from Schemas.company.employee import ( + Employees, + EmployeesSalaries, + EmployeeHistory, + Staff, +) +from Schemas.company.department import ( + Duty, + Duties, + Departments, +) +from Schemas.event.event import ( + Modules, + Services, + Service2Events, + Events, + Event2Occupant, + Event2Employee, + Event2OccupantExtra, + Event2EmployeeExtra, +) +from Schemas.identity.identity import ( + Addresses, + AddressCity, + AddressStreet, + AddressLocality, + AddressDistrict, + AddressNeighborhood, + AddressState, + AddressCountry, + AddressPostcode, + AddressGeographicLocations, + UsersTokens, + OccupantTypes, + People, + Users, + RelationshipDutyPeople, + RelationshipEmployee2PostCode, + Contracts, +) +from Schemas.others.enums import ( + ApiEnumDropdown, +) +from Schemas.rules.rules import ( + EndpointRestriction, +) + +# # NO-SQL Models +# from Schemas.no_sql_models.mongo_database import ( +# MongoQuery, +# ) +# from Schemas.no_sql_models.identity import ( +# MongoQueryIdentity, +# ) + +__all__ = [ + "AccountBooks", + "AccountCodeParser", + "AccountRecords", + "AccountCodes", + "AccountDetail", + "AccountMaster", + "AccountRecordExchanges", + "BuildIbans", + "BuildIbanDescription", + "CrypterEngine", + "Build", + "BuildTypes", + "BuildParts", + "BuildArea", + "BuildSites", + "BuildLivingSpace", + "BuildPersonProviding", + "BuildCompaniesProviding", + "BuildDecisionBook", + "BuildDecisionBookItems", + "BuildDecisionBookPerson", + "BuildDecisionBookLegal", + "BuildDecisionBookItemsUnapproved", + "BuildDecisionBookInvitations", + "BuildDecisionBookPayments", + "BuildDecisionBookProjects", + "BuildDecisionBookProjectPerson", + "BuildDecisionBookPersonOccupants", + "BuildDecisionBookProjectItems", + "DecisionBookBudgetBooks", + "DecisionBookBudgetCodes", + "DecisionBookBudgetMaster", + "DecisionBookBudgets", + "Companies", + "RelationshipDutyCompany", + "Employees", + "EmployeesSalaries", + "EmployeeHistory", + "Staff", + "Duty", + "Duties", + "Departments", + "Modules", + "Services", + "Service2Events", + "Events", + "Event2Occupant", + "Event2Employee", + "Event2OccupantExtra", + "Event2EmployeeExtra", + "Addresses", + "AddressCity", + "AddressStreet", + "AddressLocality", + "AddressDistrict", + "AddressNeighborhood", + "AddressState", + "AddressCountry", + "AddressPostcode", + "AddressGeographicLocations", + "UsersTokens", + "OccupantTypes", + "People", + "Users", + "RelationshipDutyPeople", + "RelationshipEmployee2PostCode", + "Contracts", + "ApiEnumDropdown", + "EndpointRestriction", + "RelationshipEmployee2Build", + # ------------------------------------------------ + "MongoQuery", + "MongoQueryIdentity", +] diff --git a/Schemas/account/account.py b/Schemas/account/account.py new file mode 100644 index 0000000..707a233 --- /dev/null +++ b/Schemas/account/account.py @@ -0,0 +1,641 @@ +from sqlalchemy.orm import mapped_column, Mapped +from sqlalchemy import ( + String, + Integer, + Boolean, + ForeignKey, + Index, + TIMESTAMP, + Numeric, + SmallInteger, +) + +from Services.PostgresDb import CrudCollection +from LanguageModels.Database.account.account import ( + AccountBooksLanguageModel, + AccountCodesLanguageModel, + AccountRecordsLanguageModel, + AccountRecordExchangesLanguageModel, + AccountDetailLanguageModel, + AccountCodeParserLanguageModel, + AccountMasterLanguageModel, +) + + +class AccountBooks(CrudCollection): + + __tablename__ = "account_books" + __exclude__fields__ = [] + __language_model__ = AccountBooksLanguageModel + + country: Mapped[str] = mapped_column(String, nullable=False) + branch_type: Mapped[int] = mapped_column(SmallInteger, server_default="0") + + company_id: Mapped[int] = mapped_column(ForeignKey("companies.id"), nullable=False) + company_uu_id: Mapped[str] = mapped_column(String, nullable=False) + branch_id: Mapped[int] = mapped_column(ForeignKey("companies.id")) + branch_uu_id: Mapped[str] = mapped_column(String, comment="Branch UU ID") + + __table_args__ = ( + Index("account_companies_book_ndx_00", company_id, "expiry_starts"), + {"comment": "Account Book Information"}, + ) + + +class AccountCodes(CrudCollection): + + __tablename__ = "account_codes" + __exclude__fields__ = [] + __language_model__ = AccountCodesLanguageModel + + account_code: Mapped[str] = mapped_column( + String(48), nullable=False, comment="Account Code" + ) + comment_line: Mapped[str] = mapped_column( + String(128), nullable=False, comment="Comment Line" + ) + + is_receive_or_debit: Mapped[bool] = mapped_column(Boolean) + product_id: Mapped[int] = mapped_column(Integer, server_default="0") + nvi_id: Mapped[str] = mapped_column(String(48), server_default="") + status_id: Mapped[int] = mapped_column(SmallInteger, server_default="0") + account_code_seperator: Mapped[str] = mapped_column(String(1), server_default=".") + + system_id: Mapped[int] = mapped_column(SmallInteger, server_default="0") + locked: Mapped[int] = mapped_column(SmallInteger, server_default="0") + + company_id: Mapped[int] = mapped_column(ForeignKey("companies.id")) + company_uu_id: Mapped[str] = mapped_column( + String, nullable=False, comment="Company UU ID" + ) + customer_id: Mapped[int] = mapped_column(ForeignKey("companies.id")) + customer_uu_id: Mapped[str] = mapped_column( + String, nullable=False, comment="Customer UU ID" + ) + person_id: Mapped[int] = mapped_column(ForeignKey("people.id")) + person_uu_id: Mapped[str] = mapped_column( + String, nullable=False, comment="Person UU ID" + ) + + __table_args__ = ({"comment": "Account Code Information"},) + + +class AccountCodeParser(CrudCollection): + + __tablename__ = "account_code_parser" + __exclude__fields__ = [] + __language_model__ = AccountCodesLanguageModel + + account_code_1: Mapped[str] = mapped_column(String, nullable=False, comment="Order") + account_code_2: Mapped[str] = mapped_column(String, nullable=False, comment="Order") + account_code_3: Mapped[str] = mapped_column(String, nullable=False, comment="Order") + account_code_4: Mapped[str] = mapped_column(String, server_default="") + account_code_5: Mapped[str] = mapped_column(String, server_default="") + account_code_6: Mapped[str] = mapped_column(String, server_default="") + + account_code_id: Mapped[int] = mapped_column( + ForeignKey("account_codes.id"), nullable=False + ) + account_code_uu_id: Mapped[str] = mapped_column( + String, nullable=False, comment="Account Code UU ID" + ) + + __table_args__ = ( + Index("_account_code_parser_ndx_00", account_code_id), + {"comment": "Account Code Parser Information"}, + ) + + @property + def get_account_code(self): + return f"{self.account_codes.account_code_seperator}".join( + [ + getattr(self, f"account_code_{i}") + for i in range(1, 7) + if getattr(self, f"account_code_{i}") + ] + ) + + +class AccountMaster(CrudCollection): + """ + AccountCodes class based on declarative_base and CrudCollection via session + """ + + __tablename__ = "account_master" + __exclude__fields__ = [] + __language_model__ = AccountMasterLanguageModel + + doc_date: Mapped[TIMESTAMP] = mapped_column( + TIMESTAMP(timezone=True), nullable=False, comment="Document Date" + ) + plug_type: Mapped[str] = mapped_column(String, nullable=False, comment="Plug Type") + plug_number: Mapped[int] = mapped_column( + Integer, nullable=False, comment="Plug Number" + ) + + special_code: Mapped[str] = mapped_column(String(12), server_default="") + authorization_code: Mapped[str] = mapped_column(String(12), server_default="") + + doc_code: Mapped[str] = mapped_column(String(12), server_default="") + doc_type: Mapped[int] = mapped_column(SmallInteger, server_default="0") + + comment_line1: Mapped[str] = mapped_column(String, server_default="") + comment_line2: Mapped[str] = mapped_column(String, server_default="") + comment_line3: Mapped[str] = mapped_column(String, server_default="") + comment_line4: Mapped[str] = mapped_column(String, server_default="") + comment_line5: Mapped[str] = mapped_column(String, server_default="") + comment_line6: Mapped[str] = mapped_column(String, server_default="") + project_code: Mapped[str] = mapped_column(String(12), server_default="") + module_no: Mapped[str] = mapped_column(String, server_default="") + journal_no: Mapped[int] = mapped_column(Integer, server_default="0") + + status_id: Mapped[int] = mapped_column(SmallInteger, server_default="0") + canceled: Mapped[bool] = mapped_column(Boolean, server_default="0") + print_count: Mapped[int] = mapped_column(SmallInteger, server_default="0") + total_active: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0") + total_passive: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0") + total_active_1: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0") + total_passive_1: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0") + total_active_2: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0") + total_passive_2: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0") + total_active_3: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0") + total_passive_3: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0") + total_active_4: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0") + total_passive_4: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0") + cross_ref: Mapped[int] = mapped_column(Integer, server_default="0") + data_center_id: Mapped[str] = mapped_column(String, server_default="") + data_center_rec_num: Mapped[int] = mapped_column(Integer, server_default="0") + + account_header_id: Mapped[int] = mapped_column( + ForeignKey("account_books.id"), nullable=False + ) + account_header_uu_id: Mapped[str] = mapped_column( + String, nullable=False, comment="Account Header UU ID" + ) + project_item_id: Mapped[int] = mapped_column( + ForeignKey("build_decision_book_projects.id") + ) + project_item_uu_id: Mapped[str] = mapped_column( + String, comment="Project Item UU ID" + ) + department_id: Mapped[int] = mapped_column(ForeignKey("departments.id")) + department_uu_id: Mapped[str] = mapped_column(String, comment="Department UU ID") + + __table_args__ = ( + Index("_account_master_ndx_00", doc_date, account_header_id), + {"comment": "Account Master Information"}, + ) + + +class AccountDetail(CrudCollection): + """ + AccountCodes class based on declarative_base and CrudCollection via session + """ + + __tablename__ = "account_detail" + __exclude__fields__ = [] + __enum_list__ = [("plug_type", "AccountingReceiptTypes", "M")] + __language_model__ = AccountDetailLanguageModel + + doc_date: Mapped[TIMESTAMP] = mapped_column( + TIMESTAMP(timezone=True), nullable=False, comment="Document Date" + ) + line_no: Mapped[int] = mapped_column( + SmallInteger, nullable=False, comment="Line Number" + ) + receive_debit: Mapped[str] = mapped_column( + String(1), nullable=False, comment="Receive Debit" + ) + debit: Mapped[float] = mapped_column( + Numeric(20, 6), nullable=False, comment="Debit" + ) + + department: Mapped[str] = mapped_column(String(24), server_default="") + special_code: Mapped[str] = mapped_column(String(12), server_default="") + account_ref: Mapped[int] = mapped_column(Integer, server_default="0") + account_fiche_ref: Mapped[int] = mapped_column(Integer, server_default="0") + center_ref: Mapped[int] = mapped_column(Integer, server_default="0") + general_code: Mapped[str] = mapped_column(String(32), server_default="") + credit: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0") + currency_type: Mapped[str] = mapped_column(String(4), server_default="TL") + exchange_rate: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0") + debit_cur: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0") + credit_cur: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0") + discount_cur: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0") + amount: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0") + cross_account_code: Mapped[float] = mapped_column(String(32), server_default="") + inf_index: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0") + not_inflated: Mapped[int] = mapped_column(SmallInteger, server_default="0") + not_calculated: Mapped[int] = mapped_column(SmallInteger, server_default="0") + comment_line1: Mapped[str] = mapped_column(String(64), server_default="") + comment_line2: Mapped[str] = mapped_column(String(64), server_default="") + comment_line3: Mapped[str] = mapped_column(String(64), server_default="") + comment_line4: Mapped[str] = mapped_column(String(64), server_default="") + comment_line5: Mapped[str] = mapped_column(String(64), server_default="") + comment_line6: Mapped[str] = mapped_column(String(64), server_default="") + owner_acc_ref: Mapped[int] = mapped_column(Integer, server_default="0") + from_where: Mapped[int] = mapped_column(Integer, server_default="0") + orj_eid: Mapped[int] = mapped_column(Integer, server_default="0") + canceled: Mapped[int] = mapped_column(SmallInteger, server_default="0") + cross_ref: Mapped[int] = mapped_column(Integer, server_default="0") + data_center_id: Mapped[str] = mapped_column(String, server_default="") + data_center_rec_num: Mapped[int] = mapped_column(Integer, server_default="0") + status_id: Mapped[int] = mapped_column(SmallInteger, server_default="0") + + plug_type_id: Mapped[int] = mapped_column( + ForeignKey("api_enum_dropdown.id"), nullable=True + ) + plug_type_uu_id = mapped_column(String, nullable=False, comment="Plug Type UU ID") + account_header_id: Mapped[int] = mapped_column( + ForeignKey("account_books.id"), nullable=False + ) + account_header_uu_id: Mapped[str] = mapped_column( + String, nullable=False, comment="Account Header UU ID" + ) + account_code_id: Mapped[int] = mapped_column( + ForeignKey("account_codes.id"), nullable=False + ) + account_code_uu_id: Mapped[str] = mapped_column( + String, nullable=False, comment="Account Code UU ID" + ) + account_master_id: Mapped[int] = mapped_column( + ForeignKey("account_master.id"), nullable=False + ) + account_master_uu_id: Mapped[str] = mapped_column( + String, nullable=False, comment="Account Master UU ID" + ) + project_id: Mapped[int] = mapped_column( + ForeignKey("build_decision_book_projects.id") + ) + project_uu_id: Mapped[str] = mapped_column(String, comment="Project UU ID") + + __table_args__ = ( + Index( + "_account_detail_ndx_00", + account_master_id, + doc_date, + line_no, + account_header_id, + unique=True, + ), + {"comment": "Account Detail Information"}, + ) + + +class AccountRecords(CrudCollection): + """ + build_decision_book_id = kaydın sorumlu olduğu karar defteri + send_company_id = kaydı gönderen firma, send_person_id = gönderen kişi + customer_id = sorumlu kullanıcı bilgisi, company_id = sorumlu firma + """ + + __tablename__ = "account_records" + __exclude__fields__ = [] + __enum_list__ = [ + ("receive_debit", "DebitTypes", "D"), + ("budget_type", "BudgetType", "B"), + ] + __language_model__ = AccountRecordsLanguageModel + + iban: Mapped[str] = mapped_column( + String(64), nullable=False, comment="IBAN Number of Bank" + ) + bank_date: Mapped[TIMESTAMP] = mapped_column( + TIMESTAMP(timezone=True), nullable=False, comment="Bank Transaction Date" + ) + + currency_value: Mapped[float] = mapped_column( + Numeric(20, 6), nullable=False, comment="Currency Value" + ) + bank_balance: Mapped[float] = mapped_column( + Numeric(20, 6), nullable=False, comment="Bank Balance" + ) + currency: Mapped[str] = mapped_column( + String(5), nullable=False, comment="Unit of Currency" + ) + additional_balance: Mapped[float] = mapped_column( + Numeric(20, 6), nullable=False, comment="Additional Balance" + ) + channel_branch: Mapped[str] = mapped_column( + String(120), nullable=False, comment="Branch Bank" + ) + process_name: Mapped[str] = mapped_column( + String, nullable=False, comment="Bank Process Type Name" + ) + process_type: Mapped[str] = mapped_column( + String, nullable=False, comment="Bank Process Type" + ) + process_comment: Mapped[str] = mapped_column( + String, nullable=False, comment="Transaction Record Comment" + ) + process_garbage: Mapped[str] = mapped_column( + String, nullable=True, comment="Transaction Record Garbage" + ) + bank_reference_code: Mapped[str] = mapped_column( + String, nullable=False, comment="Bank Reference Code" + ) + + add_comment_note: Mapped[str] = mapped_column(String, server_default="") + is_receipt_mail_send: Mapped[bool] = mapped_column(Boolean, server_default="0") + found_from = mapped_column(String, server_default="") + similarity: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0") + remainder_balance: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0") + + bank_date_y: Mapped[int] = mapped_column(Integer) + bank_date_m: Mapped[int] = mapped_column(SmallInteger) + bank_date_w: Mapped[int] = mapped_column(SmallInteger) + bank_date_d: Mapped[int] = mapped_column(SmallInteger) + + approving_accounting_record: Mapped[bool] = mapped_column( + Boolean, server_default="0" + ) + accounting_receipt_date: Mapped[TIMESTAMP] = mapped_column( + TIMESTAMP(timezone=True), server_default="1900-01-01 00:00:00" + ) + accounting_receipt_number: Mapped[int] = mapped_column(Integer, server_default="0") + 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" + ) + + 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 + ) + budget_type_uu_id: Mapped[str] = mapped_column( + String, nullable=True, comment="Budget Type UU ID" + ) + 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" + ) + + 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 + ) + approving_accounting_person_uu_id: Mapped[str] = mapped_column( + String, nullable=True, comment="Approving Accounting Person UU ID" + ) + + living_space_id: Mapped[int] = mapped_column( + ForeignKey("build_living_space.id"), nullable=True + ) + living_space_uu_id: Mapped[str] = mapped_column( + String, nullable=True, comment="Living Space 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") + + build_id: Mapped[int] = mapped_column(ForeignKey("build.id"), nullable=True) + build_uu_id: Mapped[str] = mapped_column( + String, nullable=True, comment="Build UU ID" + ) + 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" + ) + build_decision_book_id: Mapped[int] = mapped_column( + ForeignKey("build_decision_book.id"), nullable=True + ) + build_decision_book_uu_id: Mapped[str] = mapped_column( + String, nullable=True, comment="Build Decision Book UU ID" + ) + + __table_args__ = ( + Index("_budget_records_ndx_00", is_receipt_mail_send, bank_date), + Index( + "_budget_records_ndx_01", + iban, + bank_date, + bank_reference_code, + bank_balance, + unique=True, + ), + Index("_budget_records_ndx_02", status_id, bank_date), + { + "comment": "Bank Records that are related to building and financial transactions" + }, + ) + + # def payment_budget_record_close(self): + # from database_sql_models import ( + # DecisionBookProjectPaymentsMaster, + # ApiEnumDropdown, + # BuildDecisionBook, + # BuildDecisionBookPaymentsMaster, + # ) + # + # budget_record = self + # if self.receive_debit == ApiEnumDropdown.uuid_of_enum( + # enum_class="DebitTypes", key="R" + # ): + # print( + # "This record is not debit. Debit:", + # self.receive_debit, + # "DebitTypes.R.name", + # # str(DebitTypes.R.name), + # ) + # return + # if abs(budget_record.currency_value + budget_record.remainder_balance) > 0: + # payment_dict = { + # "budget_records_id": self.id, + # "build_decision_book_id": budget_record.build_decision_book_id, + # "build_parts_id": budget_record.build_parts_id, + # "start_date": budget_record.bank_date, + # "paid_value": budget_record.currency_value + # - budget_record.remainder_balance, + # "is_all": False, + # } + # (paid_value, start_paid_value, balance) = ( + # float(budget_record.currency_value - budget_record.remainder_balance), + # float(budget_record.currency_value - budget_record.remainder_balance), + # float(budget_record.remainder_balance), + # ) + # print( + # "self.id", + # self.id, + # "paid_value", + # paid_value, + # "start_paid_value", + # start_paid_value, + # "balance", + # balance, + # self.receive_debit, + # ) + # + # if not BuildDecisionBook.find_one( + # id=payment_dict["build_decision_book_id"] + # ): + # return paid_value + # + # if budget_record.replication_id == 55: + # if paid_value > 0: + # payment_dict["dues_type"] = ApiEnumDropdown.uuid_of_enum( + # enum_class="BuildDuesTypes", key="L" + # ) + # paid_value = ( + # DecisionBookProjectPaymentsMaster.pay_law_and_ren_of_build_part( + # **payment_dict + # ) + # ) + # print("dues_type", payment_dict["dues_type"], paid_value) + # if paid_value > 0: + # payment_dict.pop("dues_type", None) + # paid_value = BuildDecisionBookPaymentsMaster.pay_dues_of_build_part( + # **payment_dict + # ) + # print("dues_type", None, paid_value) + # if paid_value > 0: + # payment_dict["dues_type"] = ApiEnumDropdown.uuid_of_enum( + # enum_class="BuildDuesTypes", key="R" + # ) + # paid_value = ( + # DecisionBookProjectPaymentsMaster.pay_law_and_ren_of_build_part( + # **payment_dict + # ) + # ) + # print("dues_type", payment_dict["dues_type"], paid_value) + # payment_dict["is_all"] = True + # if paid_value > 0: + # payment_dict["dues_type"] = ApiEnumDropdown.uuid_of_enum( + # enum_class="BuildDuesTypes", key="L" + # ) + # paid_value = ( + # DecisionBookProjectPaymentsMaster.pay_law_and_ren_of_build_part( + # **payment_dict + # ) + # ) + # print("is all dues_type", payment_dict["dues_type"], paid_value) + # if paid_value > 0: + # payment_dict.pop("dues_type", None) + # paid_value = BuildDecisionBookPaymentsMaster.pay_dues_of_build_part( + # **payment_dict + # ) + # print("is all dues_type", None, paid_value) + # if paid_value > 0: + # payment_dict["dues_type"] = ApiEnumDropdown.uuid_of_enum( + # enum_class="BuildDuesTypes", key="R" + # ) + # paid_value = ( + # DecisionBookProjectPaymentsMaster.pay_law_and_ren_of_build_part( + # **payment_dict + # ) + # ) + # print("is all dues_type", payment_dict["dues_type"], paid_value) + + +# class AccountRecordDecisionPaymentClosed(CrudCollection): +# +# __tablename__ = "account_record_decision_payment_closed" +# __exclude__fields__ = [] +# +# arc_currency: Mapped[str] = mapped_column( +# String(5), nullable=False, comment="Unit of Currency" +# ) +# arc_processing_time: Mapped[TIMESTAMP] = mapped_column( +# TIMESTAMP(timezone=True), nullable=False, comment="Processing Time" +# ) +# arc_currency_value: Mapped[float] = mapped_column( +# Numeric(20, 6), nullable=False, comment="Currency Value" +# ) +# +# decision_book_budgets_id: Mapped[int] = mapped_column( +# ForeignKey("decision_book_budgets.id"), nullable=True +# ) +# decision_book_budgets_uu_id: Mapped[str] = mapped_column( +# String, nullable=True, comment="Budget UUID" +# ) +# +# build_decision_book_payment_id: Mapped[int] = mapped_column( +# ForeignKey("build_decision_book_payments.id") +# ) +# build_decision_book_payment_uu_id: Mapped[str] = mapped_column( +# String, nullable=True, comment="Build Decision Book Payment UU ID" +# ) +# account_records_id: Mapped[int] = mapped_column(ForeignKey("account_records.id")) +# account_records_uu_id: Mapped[str] = mapped_column( +# String, nullable=True, comment="Account Record UU ID" +# ) +# +# __table_args__ = ( +# Index( +# "_account_record_decision_payment_closed_ndx_00", +# account_records_id, +# build_decision_book_payment_id, +# arc_processing_time, +# ), +# Index( +# "_account_record_decision_payment_closed_ndx_01", +# build_decision_book_payment_id, +# account_records_id, +# arc_processing_time, +# ), +# {"comment": "Account Record Decision Payment Closed Information"}, +# ) + + +class AccountRecordExchanges(CrudCollection): + + __tablename__ = "account_record_exchanges" + __exclude__fields__ = [] + __language_model__ = AccountRecordExchangesLanguageModel + + are_currency: Mapped[str] = mapped_column( + String(5), nullable=False, comment="Unit of Currency" + ) + are_exchange_rate: Mapped[float] = mapped_column( + Numeric(18, 6), nullable=False, server_default="1" + ) + usd_exchange_rate_value: Mapped[float] = mapped_column( + Numeric(18, 6), + nullable=True, + server_default="0", + comment="It will be written by multiplying the usd exchange rate with the current value result.", + ) + eur_exchange_rate_value: Mapped[float] = mapped_column( + Numeric(18, 6), + nullable=True, + server_default="0", + comment="It will be written by multiplying the eur exchange rate with the current value result.", + ) + gbp_exchange_rate_value: Mapped[float] = mapped_column( + Numeric(18, 6), + nullable=True, + server_default="0", + comment="It will be written by multiplying the gpd exchange rate with the current value result.", + ) + cny_exchange_rate_value: Mapped[float] = mapped_column( + Numeric(18, 6), + nullable=True, + server_default="0", + comment="It will be written by multiplying the cny exchange rate with the current value result.", + ) + + account_records_id: Mapped[int] = mapped_column(ForeignKey("account_records.id")) + account_records_uu_id: Mapped[str] = mapped_column( + String, nullable=True, comment="Account Record UU ID" + ) + + __table_args__ = ( + Index("_account_record_exchanges_ndx_00", account_records_id), + {"comment": "Account Record Exchanges Information"}, + ) diff --git a/Schemas/account/iban.py b/Schemas/account/iban.py new file mode 100644 index 0000000..5010eb8 --- /dev/null +++ b/Schemas/account/iban.py @@ -0,0 +1,103 @@ +from sqlalchemy import String, ForeignKey, Index, TIMESTAMP, SmallInteger, Identity +from sqlalchemy.orm import mapped_column, Mapped + +from Services.PostgresDb import CrudCollection + + +class BuildIbans(CrudCollection): + """ + BuildParts class based on declarative_base and BaseMixin via session + """ + + __tablename__ = "build_ibans" + __exclude__fields__ = [] + + iban: Mapped[str] = mapped_column( + String(40), server_default="", nullable=False, comment="IBAN number" + ) + start_date: Mapped[TIMESTAMP] = mapped_column( + TIMESTAMP(timezone=True), nullable=False, comment="Bank Transaction Start Date" + ) + + stop_date: Mapped[TIMESTAMP] = mapped_column( + TIMESTAMP(timezone=True), server_default="2900-01-01 00:00:00" + ) + bank_code: Mapped[str] = mapped_column(String(24), server_default="TR0000000000000") + xcomment: Mapped[str] = mapped_column(String(64), server_default="????") + + build_id: Mapped[int] = mapped_column( + ForeignKey("build.id"), nullable=True, comment="Building ID" + ) + build_uu_id: Mapped[str] = mapped_column( + String, nullable=True, comment="Building UUID", index=True + ) + # building: Mapped["Build"] = relationship( + # "Build", back_populates="build_ibans", foreign_keys=[build_id] + # ) + + __table_args__ = ( + Index("_build_ibans_ndx_01", iban, start_date, unique=True), + {"comment": "IBANs related to money transactions due to building objects"}, + ) + + +class BuildIbanDescription(CrudCollection): + """ + SearchComments class based on declarative_base and CrudCollection via session + """ + + __tablename__ = "build_iban_description" + __exclude__fields__ = [] + + iban: Mapped[str] = mapped_column(String, nullable=False, comment="IBAN Number") + group_id: Mapped[int] = mapped_column( + SmallInteger, nullable=False, comment="Group ID" + ) + search_word: Mapped[str] = mapped_column( + String, nullable=False, comment="Search Word", index=True + ) + + # decision_book_project_id: Mapped[int] = mapped_column( + # ForeignKey("build_decision_book_projects.id") + # ) + # decision_book_project_uu_id: Mapped[str] = mapped_column( + # String, nullable=False, comment="Decision Book Project UUID" + # ) + customer_id: Mapped[int] = mapped_column(ForeignKey("people.id"), nullable=True) + customer_uu_id: Mapped[str] = mapped_column( + String, nullable=True, comment="Customer UUID" + ) + company_id: Mapped[int] = mapped_column(ForeignKey("companies.id"), nullable=True) + company_uu_id: Mapped[str] = mapped_column( + String, nullable=True, comment="Company UUID" + ) + 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 UUID" + ) + + # decision_book_project: Mapped["BuildDecisionBookProjects"] = relationship( + # "BuildDecisionBookProjects", + # back_populates="search_iban_description", + # foreign_keys=[decision_book_project_id], + # ) + # customer: Mapped["People"] = relationship( + # "People", back_populates="search_iban_description", foreign_keys=[customer_id] + # ) + # company: Mapped["Companies"] = relationship( + # "Company", back_populates="search_iban_description", foreign_keys=[company_id] + # ) + # parts: Mapped["BuildParts"] = relationship( + # "BuildParts", + # back_populates="search_iban_description", + # foreign_keys=[build_parts_id], + # ) + + __table_args__ = ( + Index( + "_search_iban_description_ndx_00", iban, search_word, group_id, unique=True + ), + {"comment": "Search Iban Description Information"}, + ) diff --git a/Schemas/api/encrypter.py b/Schemas/api/encrypter.py new file mode 100644 index 0000000..1924ba0 --- /dev/null +++ b/Schemas/api/encrypter.py @@ -0,0 +1,124 @@ +import random + +from datetime import datetime, timedelta + +from sqlalchemy import String +from sqlalchemy.orm import mapped_column, Mapped + +from cryptography.fernet import Fernet, MultiFernet +from databases.sql_models.core_mixin import CrudCollection + + +class CrypterEngine(CrudCollection): + + __tablename__ = "crypter_engine" + __table_args__ = () + encrypt_list = [] + decrypt_list = [] + keys_error = "Unable to retrieve encrypt keys" + alchemy_error = "Alchemy object is empty" + + key_first: Mapped[str] = mapped_column(String, nullable=False) + key_second: Mapped[str] = mapped_column(String, nullable=False) + + @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 + ): + 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)): + return ( + decrypt_row.key_first.decode(), + decrypt_row.key_second.decode(), + decrypt_row.uu_id, + ) + if encrypt_rows := cls.filter_all( + cls.created_at > datetime.now() - timedelta(days=29) + ).data: + encrypt_row = random.choice(encrypt_rows) + return ( + encrypt_row.key_first.encode(), + encrypt_row.key_second.encode(), + encrypt_rows.uu_id, + ) + return None, None, None + + @classmethod + def create_encrypt_keys(cls, count: int): + for _ in range(count): + key_first = Fernet.generate_key() + key_second = Fernet.generate_key() + cls.find_or_create( + key_first=key_first.decode(), key_second=key_second.decode() + ) + + @classmethod + def raise_exception(cls, message=None): + raise Exception(message if message else cls.keys_error) + + @classmethod + def encrypt_given_alchemy_list(cls, alchemy_object_list: list): + for alchemy_object in alchemy_object_list: + key_first, key_second, cryp_uu_id = cls.get_valid_keys() + fernet_keys = MultiFernet([Fernet(key_first), Fernet(key_second)]) + if not key_first or not key_second: + cls.raise_exception() + alchemy_dict = alchemy_object.get_dict() if alchemy_object else None + if not alchemy_dict: + cls.raise_exception(cls.alchemy_error) + for key, plain_row in alchemy_dict.items(): + if key in alchemy_object.__encrypt_list__: + alchemy_dict[key] = fernet_keys.encrypt(plain_row).decode() + alchemy_dict["cryp_uu_id"] = cryp_uu_id + cls.encrypt_list.append(alchemy_object.update(**alchemy_dict)) + return cls.encrypt_list + + @classmethod + def encrypt_given_alchemy_object(cls, alchemy_object_object): + key_first, key_second, cryp_uu_id = cls.get_valid_keys() + fernet_keys = MultiFernet([Fernet(key_first), Fernet(key_second)]) + if not key_first or not key_second: + cls.raise_exception() + alchemy_dict = ( + alchemy_object_object.get_dict() if alchemy_object_object else None + ) + if not alchemy_dict: + cls.raise_exception(cls.alchemy_error) + for key, plain_row in alchemy_dict.items(): + if key in alchemy_object_object.__encrypt_list__: + alchemy_dict[key] = fernet_keys.encrypt(plain_row).decode() + alchemy_dict["cryp_uu_id"] = cryp_uu_id + return alchemy_object_object.update(**alchemy_dict) + + @classmethod + def decrypt_given_alchemy(cls, alchemy_object_list: list): + for alchemy_object in alchemy_object_list: + key_first, key_second, cryp_uu_id = cls.get_valid_keys(row=alchemy_object) + fernet_keys = MultiFernet([Fernet(key_first), Fernet(key_second)]) + if not key_first or not key_second: + cls.raise_exception() + alchemy_dict = alchemy_object.get_dict() if alchemy_object else None + if not alchemy_dict: + cls.raise_exception(cls.alchemy_error) + for key, plain_row in alchemy_dict.items(): + if key in alchemy_object.__encrypt_list__: + alchemy_dict[key] = fernet_keys.decrypt(plain_row).decode() + cls.decrypt_list.append(alchemy_dict) + return cls.decrypt_list + + @classmethod + def decrypt_given_alchemy_object(cls, alchemy_object): + key_first, key_second, cryp_uu_id = cls.get_valid_keys(row=alchemy_object) + fernet_keys = MultiFernet([Fernet(key_first), Fernet(key_second)]) + if not key_first or not key_second: + cls.raise_exception() + alchemy_dict = alchemy_object.get_dict() if alchemy_object else None + if not alchemy_dict: + cls.raise_exception(cls.alchemy_error) + for key, plain_row in alchemy_dict.items(): + if key in alchemy_object.__encrypt_list__: + alchemy_dict[key] = fernet_keys.decrypt(plain_row).decode() + return alchemy_dict diff --git a/Schemas/building/budget.py b/Schemas/building/budget.py new file mode 100644 index 0000000..7bbdf52 --- /dev/null +++ b/Schemas/building/budget.py @@ -0,0 +1,156 @@ +from sqlalchemy import ( + String, + ForeignKey, + Index, + SmallInteger, + TIMESTAMP, + Text, + Numeric, + Integer, +) +from sqlalchemy.orm import mapped_column, Mapped +from Services.PostgresDb import CrudCollection + + +class DecisionBookBudgetBooks(CrudCollection): + + __tablename__ = "decision_book_budget_books" + __exclude__fields__ = [] + + country: Mapped[str] = mapped_column(String, nullable=False) + branch_type: Mapped[int] = mapped_column(SmallInteger, server_default="0") + + company_id: Mapped[int] = mapped_column(ForeignKey("companies.id"), nullable=False) + company_uu_id: Mapped[str] = mapped_column(String, nullable=False) + branch_id: Mapped[int] = mapped_column(ForeignKey("companies.id"), nullable=True) + branch_uu_id: Mapped[str] = mapped_column( + String, comment="Branch UU ID", nullable=True + ) + build_decision_book_id: Mapped[int] = mapped_column( + ForeignKey("build_decision_book.id"), nullable=False + ) + build_decision_book_uu_id: Mapped[str] = mapped_column( + String, nullable=True, comment="Build Decision Book UU ID" + ) + + __table_args__ = ( + Index( + "_decision_book_budget_companies_book_ndx_00", + company_id, + CrudCollection.created_at, + ), + {"comment": "budget Book Information"}, + ) + + +class DecisionBookBudgetCodes(CrudCollection): + + __tablename__ = "decision_book_budget_codes" + __exclude__fields__ = [] + + budget_code: Mapped[str] = mapped_column( + String(48), nullable=False, comment="budget Code" + ) + comment_line: Mapped[str] = mapped_column( + Text, nullable=False, comment="Comment Line" + ) + + build_decision_book_id: Mapped[int] = mapped_column( + ForeignKey("build_decision_book.id"), nullable=True + ) + build_decision_book_uu_id: Mapped[str] = mapped_column( + String, nullable=True, comment="Build Decision Book UU ID" + ) + + 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" + ) + + 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" + ) + + __table_args__ = ( + Index("_decision_book_budget_codes_ndx_00", budget_code, "created_at"), + Index("_decision_book_budget_codes_ndx_01", company_id, "created_at"), + {"comment": "budget Book Information"}, + ) + + +class DecisionBookBudgetMaster(CrudCollection): + + __tablename__ = "decision_book_budget_master" + __exclude__fields__ = [] + + budget_type: Mapped[str] = mapped_column( + String(50), nullable=False + ) # Bütçe tipi (örneğin: Operasyonel, Yatırım) + currency: Mapped[str] = mapped_column( + String(8), server_default="TRY" + ) # Bütçe para birimi + total_budget: Mapped[float] = mapped_column( + Numeric(10, 2), nullable=False + ) # Toplam bütçe + + tracking_period_id: Mapped[int] = mapped_column( + ForeignKey("api_enum_dropdown.id"), nullable=True + ) + tracking_period_uu_id: Mapped[str] = mapped_column( + String, nullable=True, comment="Part Direction UUID" + ) + budget_books_id: Mapped[int] = mapped_column( + Integer, ForeignKey("decision_book_budget_books.id"), nullable=False + ) + budget_books_uu_id: Mapped[str] = mapped_column( + String, nullable=True, comment="Budget Books UU ID" + ) + department_id: Mapped[int] = mapped_column( + Integer, ForeignKey("departments.id"), nullable=False + ) # Departman ile ilişki + department_uu_id: Mapped[str] = mapped_column( + String, nullable=True, comment="Department UU ID" + ) + + __table_args__ = ({"comment": "budget Book Information"},) + + +class DecisionBookBudgets(CrudCollection): + + __tablename__ = "decision_book_budgets" + __exclude__fields__ = [] + + process_date: Mapped[TIMESTAMP] = mapped_column( + TIMESTAMP(timezone=True), nullable=False + ) # Başlangıç tarihi + budget_codes_id: Mapped[int] = mapped_column( + Integer, ForeignKey("decision_book_budget_codes.id"), nullable=False + ) + total_budget: Mapped[float] = mapped_column( + Numeric(10, 2), nullable=False + ) # Toplam bütçe + used_budget: Mapped[float] = mapped_column( + Numeric(10, 2), nullable=False, default=0.0 + ) # Kullanılan bütçe + remaining_budget: Mapped[float] = mapped_column( + Numeric(10, 2), nullable=False, default=0.0 + ) # Kullanılan bütçe + + decision_book_budget_master_id: Mapped[int] = mapped_column( + Integer, ForeignKey("decision_book_budget_master.id"), nullable=False + ) + decision_book_budget_master_uu_id: Mapped[str] = mapped_column( + String, nullable=True, comment="Decision Book Budget Master UU ID" + ) + + __table_args__ = ( + Index( + "_decision_book_budgets_ndx_00", + decision_book_budget_master_uu_id, + process_date, + ), + {"comment": "budget Book Information"}, + ) diff --git a/Schemas/building/build.py b/Schemas/building/build.py new file mode 100644 index 0000000..cd204ef --- /dev/null +++ b/Schemas/building/build.py @@ -0,0 +1,807 @@ +from datetime import datetime, timedelta +from typing import List, Optional, Union + +from fastapi import HTTPException, status +from sqlalchemy.orm import mapped_column, relationship, Mapped +from sqlalchemy import ( + String, + Integer, + Boolean, + ForeignKey, + Index, + TIMESTAMP, + func, + Text, + Numeric, + or_, +) + +from api_library.date_time_actions.date_functions import system_arrow +from Services.PostgresDb import CrudCollection +from databases.extensions.selector_classes import SelectActionWithEmployee +from api_validations.validations_request import ( + InsertBuild, + InsertBuildParts, + InsertBuildLivingSpace, + UpdateBuild, +) +from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject +from databases.language_models.building.build import ( + BuildTypesLanguageModel, + Part2EmployeeLanguageModel, + BuildPartsLanguageModel, + BuildSitesLanguageModel, + RelationshipEmployee2BuildLanguageModel, + BuildLanguageModel, + BuildPartsLanguageModel, + BuildLivingSpaceLanguageModel, + BuildManagementLanguageModel, + BuildAreaLanguageModel, + BuildCompaniesProvidingLanguageModel, + BuildPersonProvidingLanguageModel, +) + + +class BuildTypes(CrudCollection): + """ + BuildTypes class based on declarative_base and BaseMixin via session + + """ + + __tablename__ = "build_types" + __exclude__fields__ = [] + __language_model__ = BuildTypesLanguageModel + __include__fields__ = [] + + function_code: Mapped[str] = mapped_column( + String(12), server_default="", nullable=False, comment="Function Code" + ) + type_code: Mapped[str] = mapped_column( + String(12), server_default="", nullable=False, comment="Structure Type Code" + ) + lang: Mapped[str] = mapped_column( + String(4), server_default="TR", nullable=False, comment="Language" + ) + type_name: Mapped[str] = mapped_column( + String(48), server_default="", nullable=False, comment="Type Name" + ) + + __table_args__ = ( + Index("_build_types_ndx_00", type_code, function_code, lang, unique=True), + {"comment": "Function group of building types with their language information"}, + ) + + +class Part2Employee(CrudCollection): + """ + Employee2Parts class based on declarative_base and BaseMixin via session + In between start and end date, a part can be assigned to only one employee + """ + + __tablename__ = "part2employee" + __exclude__fields__ = [] + __language_model__ = Part2EmployeeLanguageModel + __include__fields__ = [] + + build_id: Mapped[int] = mapped_column(Integer, comment="Building ID") + part_id: Mapped[int] = mapped_column( + ForeignKey("build_parts.id"), nullable=False, comment="Part ID" + ) + employee_id: Mapped[int] = mapped_column( + ForeignKey("employees.id"), nullable=False, comment="Employee ID" + ) + + __table_args__ = ( + Index("_part2employee_ndx_00", employee_id, part_id, unique=True), + {"comment": "Employee2Parts Information"}, + ) + + +class RelationshipEmployee2Build(CrudCollection): + """ + CompanyRelationship class based on declarative_base and CrudCollection via session + Company -> Sub Company -> Sub-Sub Company + + """ + + __tablename__ = "relationship_employee2build" + __exclude__fields__ = [] + __language_model__ = RelationshipEmployee2BuildLanguageModel + + company_id: Mapped[int] = mapped_column( + ForeignKey("companies.id"), nullable=False + ) # 1, 2, 3 + employee_id: Mapped[int] = mapped_column( + ForeignKey("employees.id"), nullable=False + ) # employee -> (n)person Evyos LTD + member_id: Mapped[int] = mapped_column( + ForeignKey("build.id"), nullable=False + ) # 2, 3, 4 + + relationship_type: Mapped[str] = mapped_column( + String, nullable=True, server_default="Employee" + ) # Commercial + show_only: Mapped[bool] = mapped_column(Boolean, server_default="False") + + __table_args__ = ( + Index( + "relationship_build_employee_ndx_00", + company_id, + employee_id, + member_id, + relationship_type, + unique=True, + ), + {"comment": "Build & Employee Relationship Information"}, + ) + + +class Build(CrudCollection, SelectActionWithEmployee): + """ + Builds class based on declarative_base and BaseMixin via session + """ + + __tablename__ = "build" + __exclude__fields__ = [] + __language_model__ = BuildLanguageModel + __include__fields__ = [] + __access_by__ = [] + __many__table__ = RelationshipEmployee2Build + # __explain__ = AbstractBuild() + + gov_address_code: Mapped[str] = mapped_column( + String, server_default="", unique=True + ) + build_name: Mapped[str] = mapped_column( + String, nullable=False, comment="Building Name" + ) + build_no: Mapped[str] = mapped_column( + String(8), nullable=False, comment="Building Number" + ) + + max_floor: Mapped[int] = mapped_column( + Integer, server_default="1", nullable=False, comment="Max Floor" + ) + underground_floor: Mapped[int] = mapped_column( + Integer, server_default="0", nullable=False, comment="Underground Floor" + ) + build_date: Mapped[TIMESTAMP] = mapped_column( + TIMESTAMP(timezone=True), server_default="1900-01-01" + ) + decision_period_date: Mapped[TIMESTAMP] = mapped_column( + TIMESTAMP(timezone=True), + server_default="1900-01-01", + comment="Building annual ordinary meeting period", + ) + tax_no: Mapped[str] = mapped_column(String(24), server_default="") + lift_count: Mapped[int] = mapped_column(Integer, server_default="0") + heating_system: Mapped[bool] = mapped_column(Boolean, server_default="True") + cooling_system: Mapped[bool] = mapped_column(Boolean, server_default="False") + hot_water_system: Mapped[bool] = mapped_column(Boolean, server_default="False") + block_service_man_count: Mapped[int] = mapped_column(Integer, server_default="0") + security_service_man_count: Mapped[int] = mapped_column(Integer, server_default="0") + garage_count: Mapped[int] = mapped_column( + Integer, server_default="0", comment="Garage Count" + ) + management_room_id: Mapped[int] = mapped_column( + Integer, nullable=True, comment="Management Room ID" + ) + + 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 + ) + build_types_id: Mapped[int] = mapped_column( + ForeignKey("build_types.id"), nullable=False, comment="Building Type" + ) + build_types_uu_id: Mapped[str] = mapped_column(String, comment="Building Type UUID") + + parts: Mapped[List["BuildParts"]] = relationship( + "BuildParts", back_populates="buildings", foreign_keys="BuildParts.build_id" + ) + decision_books: Mapped[List["BuildDecisionBook"]] = relationship( + "BuildDecisionBook", + back_populates="buildings", + foreign_keys="BuildDecisionBook.build_id", + ) + + # build_ibans: Mapped["BuildIbans"] = relationship( + # "BuildIbans", back_populates="building", foreign_keys="BuildIbans.build_id" + # ) + # areas: Mapped["BuildArea"] = relationship( + # "BuildArea", back_populates="buildings", foreign_keys="BuildArea.build_id" + # ) + # response_companies: Mapped["Companies"] = relationship( + # "Companies", + # back_populates="response_buildings", + # foreign_keys=[response_company_id], + # ) + # addresses: Mapped[List["Address"]] = relationship( + # "Address", back_populates="buildings", foreign_keys=[address_id] + # ) + # peoples: Mapped["People"] = relationship( + # "People", back_populates="buildings", foreign_keys=[people_id] + # ) + # sites: Mapped["BuildSites"] = relationship( + # "BuildSites", back_populates="buildings", foreign_keys=[site_id] + # ) + + __table_args__ = ( + Index("_builds_ndx_00", gov_address_code), + Index("_builds_ndx_01", build_name, build_no), + { + "comment": "Build objects are building that are created for living and store purposes" + }, + ) + + @property + def management_room(self): + if management_room := BuildParts.filter_by_one( + system=True, id=self.management_room_id, build_id=self.id + ).data: + return management_room + return None + + @classmethod + def create_action(cls, data: InsertBuild, token): + from databases import Addresses + + data_dict = data.excluded_dump() + data_dict["address_id"] = None + if data.address_uu_id: + official_address = Addresses.filter_one( + Addresses.uu_id == data.address_uu_id, + ).data + data_dict["address_id"] = official_address.id + data_dict["build_no"] = str(official_address.build_number) + if not data_dict["address_id"]: + raise HTTPException( + 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 + 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( + company_id=token.selected_company.company_id, + employee_id=token.selected_company.employee_id, + member_id=build_created.id, + ) + build_created.save() + build_created.update(is_confirmed=True) + build_created.save() + created_build_relation.update(is_confirmed=True) + created_build_relation.save() + return build_created + + @classmethod + def update_action(cls, data: UpdateBuild, build_uu_id: str, token): + from databases import Addresses + + print("data_dict", data.dump()) + data_dict = data.excluded_dump() + if data.address_uu_id: + official_address = Addresses.filter_one( + Addresses.uu_id == data.address_uu_id + ).data + data_dict["address_id"] = official_address.id if official_address else None + print("data_dict", data_dict) + if build_to_update := cls.filter_one(cls.uu_id == build_uu_id).data: + print("build_to_update", build_to_update.get_dict()) + updated_build = build_to_update.update(**data_dict) + updated_build.save() + print("updated_build", updated_build.get_dict()) + return updated_build + + @property + def top_flat(self): + max_flat_no = 0 + for part in self.parts: + if part.part_no > self.max_floor: + max_flat_no = part.part_no + return max_flat_no + + @property + def bottom_flat(self): + min_flat_no = 0 + for part in self.parts: + if part.part_no < self.max_floor: + min_flat_no = part.part_no + return min_flat_no + + @property + def human_livable_parts(self) -> tuple: + parts = list(part for part in self.parts if part.human_livable) + return parts, len(parts) + + @property + def livable_part_count(self): + livable_parts = BuildParts.filter_all( + BuildParts.build_id == self.id, + BuildParts.human_livable == True, + ) + if not livable_parts.data: + raise HTTPException( + status_code=status.HTTP_404_NOT_FOUND, + detail="There is no livable part in this building.", + ) + return livable_parts.count + + @property + def part_type_count(self): + 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 + if build_type.type_code in building_types: + building_types[build_type.type_code]["list"].append(part.part_no) + else: + building_types[build_type.type_code] = {"list": [part.part_no]} + + # for key, val in building_types.items(): + # list_parts = val["list"] + # building_types[key] = { + # "list": list_parts, + # "min": min(list_parts), + # "max": max(list_parts), + # "count": len(list_parts), + # } + return building_types + + +class BuildParts(CrudCollection): + """ + BuildParts class based on declarative_base and BaseMixin via session + Attentions: Part_no is unique for each building and Every building must have a management section.!!! default no 0 + """ + + __tablename__ = "build_parts" + __exclude__fields__ = [] + __language_model__ = BuildPartsLanguageModel + __include__fields__ = [] + __enum_list__ = [("part_direction", "Directions", "NN")] + + # https://adres.nvi.gov.tr/VatandasIslemleri/AdresSorgu + address_gov_code: Mapped[str] = mapped_column( + String, nullable=False, comment="Goverment Door Code" + ) + # part_name: Mapped[str] = mapped_column(String(24), server_default="", nullable=False, comment="Part Name") + part_no: Mapped[int] = mapped_column( + Integer, server_default="0", nullable=False, comment="Part Number" + ) + part_level: Mapped[int] = mapped_column( + Integer, server_default="0", comment="Building Part Level" + ) + part_code: Mapped[str] = mapped_column( + String, server_default="", nullable=False, comment="Part Code" + ) + 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" + ) + default_accessory: Mapped[str] = mapped_column( + Text, server_default="0", comment="Default Accessory" + ) + human_livable: Mapped[bool] = mapped_column( + Boolean, server_default="1", comment="Human Livable" + ) + due_part_key: Mapped[str] = mapped_column( + String, server_default="", nullable=False, comment="Constant Payment Group" + ) + + build_id: Mapped[int] = mapped_column( + ForeignKey("build.id"), nullable=False, comment="Building ID" + ) + build_uu_id: Mapped[str] = mapped_column( + String, nullable=False, comment="Building UUID" + ) + part_direction_id: Mapped[int] = mapped_column( + ForeignKey("api_enum_dropdown.id"), nullable=True + ) + part_direction_uu_id: Mapped[str] = mapped_column( + String, nullable=True, comment="Part Direction UUID" + ) + part_type_id: Mapped[int] = mapped_column( + ForeignKey("build_types.id"), nullable=False, comment="Building Part Type" + ) + part_type_uu_id: Mapped[str] = mapped_column( + String, nullable=False, comment="Building Part Type UUID" + ) + + buildings: Mapped["Build"] = relationship( + "Build", back_populates="parts", foreign_keys=[build_id] + ) + + __table_args__ = ( + Index("build_parts_ndx_01", build_id, part_no, unique=True), + {"comment": "Part objects that are belong to building objects"}, + ) + + @classmethod + def create_action(cls, data: InsertBuildParts, token): + from databases import ApiEnumDropdown + + data_dict = data.dump() + build_from_duty = Build.select_action( + employee_id=token.selected_company.employee_id, + filter_expr=[Build.uu_id == data.build_uu_id], + ) + building = build_from_duty.first() + if not building: + raise HTTPException( + status_code=status.HTTP_406_NOT_ACCEPTABLE, + detail="This Employee can not reach this building or building uu-id not found in database. " + "Check with your supervisor.", + ) + + if build_types := BuildTypes.filter_one( + BuildTypes.uu_id == data.build_part_type_uu_id, + ).data: + part_direction = ApiEnumDropdown.get_by_uuid( + uuid=str(data.part_direction_uu_id) + ) + + data_dict["part_gross_size"] = data.part_gross_size + data_dict["part_net_size"] = data.part_net_size + data_dict["part_type_id"] = build_types.id + data_dict["part_level"] = data.part_level + data_dict["build_id"] = building.id + data_dict["part_no"] = data.part_no + data_dict["part_code"] = ( + f"{build_types.type_code}:{str(data_dict['part_no']).zfill(2)}" + ) + data_dict["address_gov_code"] = data.address_gov_code + data_dict["default_accessory"] = data.default_accessory + data_dict["human_livable"] = bool(data.human_livable) + + data_dict["build_uu_id"] = str(data.build_uu_id) + data_dict["part_type_id"] = build_types.id + data_dict["part_type_uu_id"] = str(build_types.uu_id) + data_dict["part_direction_id"] = part_direction.id + data_dict["part_direction_uu_id"] = str(part_direction.uu_id) + # data_dict["part_direction"] = str(data.part_direction_uu_id) + + if not data_dict["part_gross_size"]: + raise HTTPException( + status_code=status.HTTP_406_NOT_ACCEPTABLE, + detail="Part Gross Size can not be empty.", + ) + + if not data_dict["part_net_size"]: + raise HTTPException( + status_code=status.HTTP_406_NOT_ACCEPTABLE, + detail="Part Net Size can not be empty.", + ) + pt = int(data_dict["part_net_size"]) + data_dict["due_part_key"] = str(pt + (5 - (pt % 5))) + "M2" + del data_dict["build_part_type_uu_id"] + return cls.find_or_create(**data_dict) + + raise HTTPException( + status_code=status.HTTP_418_IM_A_TEAPOT, + detail="Build Part can not be created.", + ) + + @property + def part_name(self): + if build_type := BuildTypes.filter_by_one( + system=True, id=self.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()}" + + +class BuildLivingSpace(CrudCollection): + """ + LivingSpace class based on declarative_base and BaseMixin via session + Owner or live person = Occupant of the build part + + Query OR(owner_person_id == person_id, life_person_id == person_id) AND (now(date)) + """ + + __tablename__ = "build_living_space" + __exclude__fields__ = [] + __language_model__ = BuildLivingSpaceLanguageModel + __include__fields__ = [] + + fix_value: Mapped[float] = mapped_column( + Numeric(20, 6), + server_default="0", + comment="Fixed value is deducted from debit.", + ) + fix_percent: Mapped[float] = mapped_column( + Numeric(6, 2), + server_default="0", + comment="Fixed percent is deducted from debit.", + ) + + agreement_no: Mapped[str] = mapped_column( + String, server_default="", comment="Agreement No" + ) + marketing_process: Mapped[bool] = mapped_column(Boolean, server_default="False") + marketing_layer: Mapped[int] = mapped_column(Integer, server_default="0") + + build_parts_id: Mapped[int] = mapped_column( + ForeignKey("build_parts.id"), + nullable=False, + index=True, + comment="Build Part ID", + ) + build_parts_uu_id: Mapped[str] = mapped_column( + String, nullable=False, comment="Build Part UUID" + ) + person_id: Mapped[int] = mapped_column( + ForeignKey("people.id"), + nullable=False, + index=True, + comment="Responsible People ID", + ) + person_uu_id: Mapped[str] = mapped_column( + String, nullable=False, comment="Responsible People UUID" + ) + occupant_type: Mapped[int] = mapped_column( + ForeignKey("occupant_types.id"), + nullable=False, + comment="Occupant Type", + ) + occupant_type_uu_id: Mapped[str] = mapped_column( + String, nullable=False, comment="Occupant Type UUID" + ) + + __table_args__ = ( + {"comment": "Living Space inside building parts that are related to people"}, + ) + + @classmethod + def create_action( + cls, + data: dict, + token_dict: Union[EmployeeTokenObject, OccupantTokenObject], + ): + from databases import Services, OccupantTypes + from api_events.events.events.events_bind_modules import ( + ModulesBindOccupantEventMethods, + ) + + 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 + ).data + related_service = Services.filter_by_one( + related_responsibility=occupant_type.occupant_code, + ).data + if not related_service: + raise HTTPException( + status_code=status.HTTP_418_IM_A_TEAPOT, + detail="Service is not found in database. Re-enter service record then try again.", + ) + ModulesBindOccupantEventMethods.bind_default_module_for_first_init_occupant( + build_living_space_id=created_living_space.id, + ) + created_living_space.save_and_confirm() + return created_living_space + + @classmethod + def find_living_from_customer_id( + 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_( + cls.owner_person_id == customer_id, + cls.life_person_id == customer_id, + ), + cls.start_date < formatted_date - timedelta(days=add_days), + cls.stop_date > formatted_date + timedelta(days=add_days), + ) + return living_spaces.data, living_spaces.count + + +class BuildManagement(CrudCollection): + + __tablename__ = "build_management" + __exclude__fields__ = [] + __language_model__ = BuildManagementLanguageModel + + discounted_percentage: Mapped[float] = mapped_column( + Numeric(6, 2), server_default="0.00" + ) # %22 + discounted_price: Mapped[float] = mapped_column( + Numeric(20, 2), server_default="0.00" + ) # Normal: 78.00 TL + calculated_price: Mapped[float] = mapped_column( + Numeric(20, 2), server_default="0.00" + ) # sana düz 75.00 TL yapar + + occupant_type: Mapped[int] = mapped_column( + ForeignKey("occupant_types.id"), + nullable=False, + comment="Occupant Type", + ) + occupant_type_uu_id: Mapped[str] = mapped_column( + String, nullable=False, comment="Occupant Type UUID" + ) + build_id: Mapped[int] = mapped_column( + ForeignKey("build.id"), nullable=False, comment="Building ID" + ) + build_uu_id: Mapped[str] = mapped_column( + String, nullable=False, comment="Building UUID" + ) + build_parts_id: Mapped[int] = mapped_column( + ForeignKey("build_parts.id"), + nullable=False, + index=True, + comment="Build Part ID", + ) + build_parts_uu_id: Mapped[str] = mapped_column( + String, nullable=False, comment="Build Part UUID" + ) + + __table_args__ = ( + Index( + "build_management_ndx_00", + build_parts_id, + occupant_type, + "expiry_starts", + unique=True, + ), + {"comment": "Management of the building parts that are related to people"}, + ) + + +class BuildArea(CrudCollection): + """ + Builds class based on declarative_base and BaseMixin via session + """ + + __tablename__ = "build_area" + __exclude__fields__ = [] + __language_model__ = BuildAreaLanguageModel + + area_name: Mapped[str] = mapped_column(String, server_default="") + area_code: Mapped[str] = mapped_column(String, server_default="") + area_type: Mapped[str] = mapped_column(String, server_default="GREEN") + area_direction: Mapped[str] = mapped_column(String(2), server_default="NN") + area_gross_size: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0") + area_net_size: Mapped[float] = mapped_column(Numeric(20, 6), server_default="0") + width = mapped_column(Integer, server_default="0") + size = mapped_column(Integer, server_default="0") + + build_id: Mapped[int] = mapped_column(ForeignKey("build.id")) + build_uu_id: Mapped[str] = mapped_column(String, comment="Building UUID") + part_type_id: Mapped[int] = mapped_column( + ForeignKey("build_types.id"), nullable=True, comment="Building Part Type" + ) + part_type_uu_id: Mapped[str] = mapped_column( + String, nullable=True, comment="Building Part Type UUID" + ) + + # buildings: Mapped["Build"] = relationship( + # "Build", back_populates="areas", foreign_keys=[build_id] + # ) + + _table_args_ = ( + Index("_edm_build_parts_area_ndx_00", build_id, area_code, unique=True), + ) + + +class BuildSites(CrudCollection): + """ + Builds class based on declarative_base and BaseMixin via session + """ + + __tablename__ = "build_sites" + __exclude__fields__ = [] + __language_model__ = BuildSitesLanguageModel + __include__fields__ = [] + + 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")) + address_uu_id: Mapped[str] = mapped_column(String, comment="Address UUID") + + # addresses: Mapped["Address"] = relationship( + # "Address", back_populates="site", foreign_keys=[address_id] + # ) + # buildings: Mapped["Build"] = relationship( + # "Build", back_populates="sites", foreign_keys="Build.site_id" + # ) + + __table_args__ = ( + Index("_sites_ndx_01", site_no, site_name), + {"comment": "Sites that groups building objets"}, + ) + + +class BuildCompaniesProviding(CrudCollection): + """ """ + + __tablename__ = "build_companies_providing" + __exclude__fields__ = [] + __language_model__ = BuildCompaniesProvidingLanguageModel + __include__fields__ = [] + + 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" + ) + company_id: Mapped[int] = mapped_column(ForeignKey("companies.id")) + 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 + ) + + __table_args__ = ( + Index( + "_build_companies_providing_ndx_00", + build_id, + company_id, + provide_id, + unique=True, + ), + {"comment": "Companies providing services for building"}, + ) + + +class BuildPersonProviding(CrudCollection): + """ """ + + __tablename__ = "build_person_providing" + __exclude__fields__ = [] + __language_model__ = BuildPersonProvidingLanguageModel + __include__fields__ = [] + + 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" + ) + people_id: Mapped[int] = mapped_column(ForeignKey("people.id")) + 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 + ) + + __table_args__ = ( + Index( + "_build_person_providing_ndx_00", + build_id, + people_id, + provide_id, + unique=True, + ), + {"comment": "People providing services for building"}, + ) diff --git a/Schemas/building/decision_book.py b/Schemas/building/decision_book.py new file mode 100644 index 0000000..12cd710 --- /dev/null +++ b/Schemas/building/decision_book.py @@ -0,0 +1,1793 @@ +import math +from datetime import datetime, timedelta +from decimal import Decimal +from typing import List +from fastapi import HTTPException, status + +from ApiLibrary.date_time_actions.date_functions import system_arrow + +from sqlalchemy import ( + String, + ForeignKey, + Index, + SmallInteger, + Boolean, + TIMESTAMP, + Text, + Numeric, + Integer, +) +from sqlalchemy.orm import Mapped, mapped_column, relationship + +from ApiValidations.Request import ( + InsertDecisionBook, + InsertBuildDecisionBookItems, + InsertBuildDecisionBookItemDebits, + InsertBuildDecisionBookProjects, +) +from Services.PostgresDb import CrudCollection +from LanguageModels.Database.building.decision_book import ( + BuildDecisionBookLanguageModel, + BuildDecisionBookInvitationsLanguageModel, + BuildDecisionBookPersonLanguageModel, + BuildDecisionBookPersonOccupantsLanguageModel, + BuildDecisionBookItemsLanguageModel, + BuildDecisionBookItemsUnapprovedLanguageModel, + BuildDecisionBookPaymentsLanguageModel, + BuildDecisionBookLegalLanguageModel, + BuildDecisionBookProjectsLanguageModel, + BuildDecisionBookProjectPersonLanguageModel, + BuildDecisionBookProjectItemsLanguageModel, +) + + +class BuildDecisionBook(CrudCollection): + """ + Builds class based on declarative_base and BaseMixin via session + The start dates of the decision log periods are determined from the 'decision_period_date' field in the decision log table within the building information. + decision_period_date = Her yıl yapılan karar toplantısı + 365 gün her yıl tekrar eden + decision_book_pdf_path: Karar defteri pdf dosyasının yolu + resp_company_fix_wage: Karar defterinin oluşmasını sağlayan dışardaki danışmanlık ücreti + is_out_sourced: Karar defterinin dışardan alınan hizmetle oluşturulup oluşturulmadığı + contact_agreement_path: Karar defterinin oluşmasını sağlayan dışardaki danışmanlık anlaşması dosyasının yolu + contact_agreement_date: Karar defterinin oluşmasını sağlayan dışardaki danışmanlık anlaşma tarihi + meeting_date: Karar defterinin oluşmasını sağlayan toplantı tarihi + decision_type: Karar defterinin tipi (Bina Yönetim Toplantısı (BYT), Yıllık Acil Toplantı (YAT) + """ + + __tablename__ = "build_decision_book" + __exclude__fields__ = [] + __language_model__ = BuildDecisionBookLanguageModel + + 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") + meeting_date: Mapped[TIMESTAMP] = mapped_column( + TIMESTAMP(timezone=True), server_default="1900-01-01" + ) + decision_type: Mapped[str] = mapped_column(String(3), server_default="RBM") + meeting_is_completed: Mapped[bool] = mapped_column(Boolean, server_default="0") + meeting_completed_date: Mapped[TIMESTAMP] = mapped_column( + TIMESTAMP(timezone=True), nullable=True, comment="Meeting Completed Date" + ) + + build_id: Mapped[int] = mapped_column(ForeignKey("build.id"), nullable=False) + build_uu_id: Mapped[str] = mapped_column( + String, nullable=True, comment="Build UUID" + ) + resp_company_id: Mapped[int] = mapped_column(ForeignKey("companies.id")) + resp_company_uu_id: Mapped[str] = mapped_column( + String, nullable=True, comment="Company UUID" + ) + contact_id: Mapped[int] = mapped_column( + ForeignKey("contracts.id"), nullable=True, comment="Contract id" + ) + contact_uu_id: Mapped[str] = mapped_column( + String, nullable=True, comment="Contract UUID" + ) + + buildings: Mapped["Build"] = relationship( + "Build", + back_populates="decision_books", + foreign_keys=build_id, + ) + decision_book_items: Mapped[List["BuildDecisionBookItems"]] = relationship( + "BuildDecisionBookItems", + back_populates="decision_books", + foreign_keys="BuildDecisionBookItems.build_decision_book_id", + ) + + __table_args__ = ( + Index("build_decision_book_ndx_011", meeting_date, build_id), + Index("build_decision_book_ndx_011", build_id, "expiry_starts", "expiry_ends"), + { + "comment": "Decision Book objects that are related to decision taken at building meetings" + }, + ) + + @classmethod + def retrieve_active_rbm(cls): + from Schemas.building.build import Build + + related_build = Build.find_one(id=cls.build_id) + related_date = system_arrow.get(related_build.build_date) + date_processed = related_date.replace( + year=system_arrow.now().date().year, month=related_date.month, day=1 + ) + if system_arrow.now().date() <= date_processed: + book = cls.filter_one( + cls.expiry_ends <= date_processed, + cls.decision_type == "RBM", + cls.build_id == related_build.id, + ).data + if not book: + cls.raise_http_exception( + status_code="HTTP_404_NOT_FOUND", + error_case="NOTFOUND", + message=f"Decision Book is not found for {related_build.build_name}-RBM", + data=dict( + build_id=str(related_build.uu_id), + build_name=related_build.build_name, + decision_type="RBM", + ), + ) + return book + return + + @classmethod + def select_action(cls, duty_id, token=None): + from Schemas import Build, Companies + + related_companies = Companies.select_action(duty_id_list=[int(duty_id)]) + 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_ids = list(related_.id for related_ in related_building.data) + return cls.filter_all(cls.build_id.in_(related_building_ids)).query + + @classmethod + def create_action(cls, data: InsertDecisionBook, token=None): + from Schemas import ( + Build, + Companies, + ) + + data_dict = data.model_dump() + if building := Build.find_one(uu_id=data.build_uu_id): + data_dict["build_id"] = building.id + if response_company := Companies.find_one( + uu_id=data_dict["resp_company_uu_id"] + ): + data_dict["resp_company_id"] = response_company.id + if not building: + raise HTTPException( + status_code=status.HTTP_406_NOT_ACCEPTABLE, + detail="Building must be given to create decision book.", + ) + expiry_starts = system_arrow.get(str(data_dict.get("expiry_starts"))).format( + "%Y-%m-%d" + ) + data_dict["expiry_starts"] = str(expiry_starts) + expiry_ends = system_arrow.get(str(data_dict.get("expiry_ends"))).format( + "%Y-%m-%d" + ) + data_dict["expiry_ends"] = str( + expiry_ends.replace(month=expiry_ends.month + 1, day=1) - timedelta(days=1) + ) + + if decision_book := BuildDecisionBook.filter_one( + BuildDecisionBook.build_id == building.id, + BuildDecisionBook.expiry_ends > data_dict["expiry_starts"], + BuildDecisionBook.decision_type == data_dict.get("decision_type"), + ).data: # Decision book is already exist: + cls.raise_http_exception( + status_code=status.HTTP_409_CONFLICT, + error_case="RECORDEXITS", + message="Decision Book is already exist.", + data=decision_book.get_dict(), + ) + + data_dict["expiry_starts"] = str(expiry_starts.replace(day=1)) + data_dict["expiry_ends"] = str( + expiry_ends.replace(month=expiry_ends.month + 1, day=1) - timedelta(days=1) + ) + del data_dict["build_uu_id"], data_dict["resp_company_uu_id"] + return cls.find_or_create(**data_dict) + + @property + def semester(self): + start_format = "".join( + [str(self.expiry_starts.year), "-", str(self.expiry_starts.month)] + ) + end_format = "".join( + [str(self.expiry_ends.year), "-", str(self.expiry_ends.month)] + ) + return "".join([start_format, " ", end_format]) + + def check_book_is_valid(self, bank_date: str): + if all( + [True if letter in str(bank_date) else False for letter in ["-", " ", ":"]] + ): + bank_date = datetime.strptime(str(bank_date), "%Y-%m-%d %H:%M:%S") + date_valid = ( + system_arrow.get(self.expiry_starts) + < system_arrow.get(bank_date) + < system_arrow.get(self.expiry_ends) + ) + return date_valid and self.active and not self.deleted + + @classmethod + def retrieve_valid_book(cls, bank_date, iban): + from Schemas import ( + BuildIbans, + ) + + if all( + [True if letter in str(bank_date) else False for letter in ["-", " ", ":"]] + ): + 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_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 + + +class BuildDecisionBookInvitations(CrudCollection): + """ + Builds class based on declarative_base and BaseMixin via session + """ + + __tablename__ = "build_decision_book_invitations" + __exclude__fields__ = [] + __language_model__ = BuildDecisionBookInvitationsLanguageModel + + build_id: Mapped[int] = mapped_column(Integer, nullable=False) + build_uu_id: Mapped[str] = mapped_column( + String, nullable=True, comment="Build UUID" + ) + decision_book_id: Mapped[int] = mapped_column( + ForeignKey("build_decision_book.id"), nullable=False + ) + decision_book_uu_id: Mapped[str] = mapped_column( + String, nullable=True, comment="Decision Book UUID" + ) + + invitation_type: Mapped[str] = mapped_column( + String, nullable=False, comment="Invite Type" + ) + invitation_attempt: Mapped[int] = mapped_column(SmallInteger, server_default="1") + living_part_count: Mapped[int] = mapped_column(SmallInteger, server_default="1") + living_part_percentage: Mapped[float] = mapped_column( + Numeric(10, 2), server_default="0.51" + ) + + message: Mapped[str] = mapped_column( + Text, nullable=True, comment="Invitation Message" + ) + planned_date: Mapped[TIMESTAMP] = mapped_column( + TIMESTAMP(timezone=True), nullable=False, comment="Planned Meeting Date" + ) + planned_date_expires: Mapped[TIMESTAMP] = mapped_column( + TIMESTAMP(timezone=True), nullable=False, comment="Planned Meeting Date Expires" + ) + + __table_args__ = ( + Index( + "_build_decision_book_invitations_ndx_01", + invitation_type, + planned_date, + invitation_attempt, + unique=True, + ), + {"comment": "People that are invited to building meetings."}, + ) + + @classmethod + def check_invites_are_ready_for_meeting(cls, selected_decision_book, token_dict): + 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, + detail=f"First Meeting Invitation is not found for Decision Book UUID : {selected_decision_book.uu_id}", + ) + need_attend_count = int(first_book_invitation.living_part_count) * Decimal( + first_book_invitation.living_part_percentage + ) + valid_invite_count = ( + BuildDecisionBookPerson.filter_all( + BuildDecisionBookPerson.invite_id == first_book_invitation.id, + BuildDecisionBookPerson.build_decision_book_id + == selected_decision_book.id, + BuildDecisionBookPerson.is_attending == True, + system=True, + ) + .query.distinct(BuildDecisionBookPerson.person_id) + .count() + ) + + 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, + detail=f"In order meeting to be held, {math.ceil(need_attend_count)} people must attend " + f"to the meeting. Only {valid_invite_count} people are attending to the meeting.", + ) + return first_book_invitation or second_book_invitation + + +class BuildDecisionBookPerson(CrudCollection): + """ + Builds class based on declarative_base and BaseMixin via session + Karar Defteri toplantılarına katılan kişiler veya yetkililer + dues_percent_discount: Katılımcının aidat indirim oranı Aidatdan yüzde indirim alır + dues_fix_discount: Katılımcının aidat sabit miktarı Aidatdan sabit bir miktar indirim alır + dues_discount_approval_date: Bu kişinin indiriminin onayladığı tarih + management_typecode: Kişinin toplantı görevi + """ + + __tablename__ = "build_decision_book_person" + __exclude__fields__ = [] + __enum_list__ = [("management_typecode", "BuildManagementType", "bm")] + __language_model__ = BuildDecisionBookPersonLanguageModel + + 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[TIMESTAMP] = mapped_column( + TIMESTAMP(timezone=True), server_default="1900-01-01 00:00:00" + ) + send_date: Mapped[TIMESTAMP] = mapped_column( + TIMESTAMP(timezone=True), nullable=False, comment="Confirmation Date" + ) + is_attending: Mapped[bool] = mapped_column( + Boolean, server_default="0", comment="Occupant is Attending to invitation" + ) + confirmed_date: Mapped[TIMESTAMP] = mapped_column( + TIMESTAMP(timezone=True), nullable=True, comment="Confirmation Date" + ) + token: Mapped[str] = mapped_column( + String, server_default="", comment="Invitation Token" + ) + + vicarious_person_id: Mapped[int] = mapped_column( + ForeignKey("people.id"), nullable=True, comment="Vicarious Person ID" + ) + vicarious_person_uu_id: Mapped[str] = mapped_column( + String, nullable=True, comment="Vicarious Person UUID" + ) + + 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[int] = mapped_column( + ForeignKey("build_decision_book.id"), nullable=False + ) + build_decision_book_uu_id: Mapped[str] = mapped_column( + String, nullable=False, comment="Decision Book UUID" + ) + build_living_space_id: Mapped[int] = mapped_column( + ForeignKey("build_living_space.id"), nullable=False + ) + 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) + # person_uu_id: Mapped[str] = mapped_column(String, nullable=False, comment="Person UUID") + + __table_args__ = ( + Index( + "_build_decision_book_person_ndx_01", + build_decision_book_id, + invite_id, + build_living_space_id, + unique=True, + ), + {"comment": "People that are attended to building meetings."}, + ) + + def retrieve_all_occupant_types(self): + all_decision_book_people = self.filter_all( + BuildDecisionBookPersonOccupants.invite_id == self.invite_id, + system=True, + ) + BuildDecisionBookPersonOccupants.pre_query = all_decision_book_people.query + return BuildDecisionBookPersonOccupants.filter_all(system=True).data + + def add_occupant_type(self, occupant_type, build_living_space_id: int = None): + from Schemas import ( + Build, + BuildLivingSpace, + Services, + ) + + # from api_events.events.events.events_bind_services import ( + # ServiceBindOccupantEventMethods, + # ) + + book_dict = dict( + build_decision_book_person_id=self.id, + build_decision_book_person_uu_id=str(self.uu_id), + invite_id=self.invite_id, + invite_uu_id=str(self.invite_uu_id), + occupant_type_id=occupant_type.id, + occupant_type_uu_id=str(occupant_type.uu_id), + ) + 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, + ).data + person_occupants.update( + expiry_starts=decision_book.expiry_starts, + expiry_ends=decision_book.expiry_ends, + ) + if build_living_space_id: + related_service = Services.filter_by_one( + related_responsibility=str(occupant_type.occupant_code), + **Services.valid_record_dict, + ).data + if not related_service: + raise HTTPException( + status_code=status.HTTP_404_NOT_FOUND, + detail=f"Service is not found for {occupant_type.occupant_code}", + ) + + decision_build = Build.filter_one( + Build.id == decision_book.build_id, + ).data + management_room = decision_build.management_room + if not management_room: + raise HTTPException( + status_code=status.HTTP_404_NOT_FOUND, + detail=f"Management Room is not found in {decision_build.build_name}", + ) + + living_space = BuildLivingSpace.filter_one( + BuildLivingSpace.id == build_living_space_id, + ).data + expiry_ends = str( + system_arrow.get(decision_book.meeting_date).shift(hours=23) + ) + expiry_starts = str(system_arrow.get(decision_book.meeting_date)) + related_living_space = BuildLivingSpace.find_or_create( + build_parts_id=management_room.id, + build_parts_uu_id=str(management_room.uu_id), + occupant_type=occupant_type.id, + occupant_type_uu_id=str(occupant_type.uu_id), + person_id=living_space.person_id, + person_uu_id=str(living_space.person_uu_id), + expiry_starts=expiry_starts, + expiry_ends=expiry_ends, + ) + expires_at = str( + system_arrow.get(decision_book.meeting_date).shift(days=15) + ) + related_living_space.save_and_confirm() + ServiceBindOccupantEventMethods.bind_services_occupant_system( + build_living_space_id=related_living_space.id, + service_id=related_service.id, + expires_at=expires_at, + ) + return person_occupants + return + + def get_occupant_types(self): + if occupants := BuildDecisionBookPersonOccupants.filter_all( + BuildDecisionBookPersonOccupants.build_decision_book_person_id == self.id, + ).data: + return occupants + return + + def check_occupant_type(self, occupant_type): + book_person_occupant_type = BuildDecisionBookPersonOccupants.filter_one( + BuildDecisionBookPersonOccupants.build_decision_book_person_id == self.id, + BuildDecisionBookPersonOccupants.occupant_type_id == occupant_type.id, + BuildDecisionBookPersonOccupants.active == True, + BuildDecisionBookPersonOccupants.is_confirmed == True, + ).data + if not book_person_occupant_type: + raise HTTPException( + status_code=status.HTTP_404_NOT_FOUND, + detail=f"Occupant Type : {occupant_type.occupant_code} is not found in " + f"Decision Book Person UUID {self.uu_id}", + ) + + +class BuildDecisionBookPersonOccupants(CrudCollection): + """ + Builds class based on declarative_base and BaseMixin via session + """ + + __tablename__ = "build_decision_book_person_occupants" + __exclude__fields__ = [] + __language_model__ = BuildDecisionBookPersonOccupantsLanguageModel + + build_decision_book_person_id: Mapped[int] = mapped_column( + ForeignKey("build_decision_book_person.id"), nullable=False + ) + build_decision_book_person_uu_id: Mapped[str] = mapped_column( + String, nullable=True, comment="Decision Book Person UUID" + ) + invite_id: Mapped[int] = mapped_column( + ForeignKey("build_decision_book_invitations.id"), nullable=True + ) + invite_uu_id: Mapped[str] = mapped_column( + String, nullable=True, comment="Invite UUID" + ) + + occupant_type_id: Mapped[int] = mapped_column( + ForeignKey("occupant_types.id"), nullable=False + ) + occupant_type_uu_id: Mapped[str] = mapped_column( + String, nullable=True, comment="Occupant UUID" + ) + + __table_args__ = ( + Index( + "_build_decision_book_person_occupants_ndx_01", + build_decision_book_person_id, + occupant_type_id, + unique=True, + ), + {"comment": "Occupant Types of People that are attended to building meetings."}, + ) + + +class BuildDecisionBookItems(CrudCollection): + """ + Builds class based on declarative_base and BaseMixin via session + item_commentary = metine itiraz şerh maddesi için + item_order = maddelerin sıralanma numarası + item_objection = maddelerin itiraz şerhi Text şeklinde + """ + + __tablename__ = "build_decision_book_items" + __exclude__fields__ = [] + __language_model__ = BuildDecisionBookItemsLanguageModel + + item_order: Mapped[int] = mapped_column( + SmallInteger, nullable=False, comment="Order Number of Item" + ) + item_comment: Mapped[str] = mapped_column( + Text, nullable=False, comment="Comment Content" + ) + item_objection: Mapped[str] = mapped_column( + Text, nullable=True, comment="Objection Content" + ) + info_is_completed: Mapped[bool] = mapped_column( + Boolean, server_default="0", comment="Info process is Completed" + ) + is_payment_created: Mapped[bool] = mapped_column( + Boolean, server_default="0", comment="Are payment Records Created" + ) + + info_type_id: Mapped[int] = mapped_column( + ForeignKey("api_enum_dropdown.id"), nullable=True + ) + info_type_uu_id: Mapped[str] = mapped_column( + String, nullable=True, comment="Info Type UUID" + ) + + build_decision_book_id: Mapped[int] = mapped_column( + ForeignKey("build_decision_book.id"), nullable=False + ) + build_decision_book_uu_id: Mapped[str] = mapped_column( + String, nullable=True, comment="Decision Book UUID" + ) + item_short_comment: Mapped[str] = mapped_column( + String(24), + nullable=True, + comment="This field is reserved for use in grouping data or in the pivot heading.", + ) + + decision_books: Mapped["BuildDecisionBook"] = relationship( + "BuildDecisionBook", + back_populates="decision_book_items", + foreign_keys=[build_decision_book_id], + ) + decision_book_project: Mapped["BuildDecisionBookProjects"] = relationship( + "BuildDecisionBookProjects", + back_populates="build_decision_book_item", + foreign_keys="BuildDecisionBookProjects.build_decision_book_item_id", + ) + + __table_args__ = ( + Index("_build_decision_book_item_ndx_01", build_decision_book_id), + Index( + "_build_decision_book_item_ndx_02", + build_decision_book_id, + item_order, + unique=True, + ), + { + "comment": "Decision Book Items that are related to decision taken at building meetings" + }, + ) + + @classmethod + def select_action(cls, duty_id, token=None): + from Schemas import ( + Build, + Companies, + ) + + related_companies = Companies.select_action(duty_id_list=[duty_id]) + related_companies_ids = list( + related_.id for related_ in related_companies.all() + ) + related_building = Build.query.filter( + Build.company_id.in_(related_companies_ids) + ) + related_building_ids = list(related_.id for related_ in related_building.all()) + related_decision_books = BuildDecisionBook.query.filter( + BuildDecisionBook.build_id.in_(related_building_ids) + ) + related_decision_books_ids = list( + related_.id for related_ in related_decision_books.all() + ) + return cls.query.filter( + cls.build_decision_book_id.in_(related_decision_books_ids) + ) + + @classmethod + def create_action(cls, data: InsertBuildDecisionBookItems, token): + data_dict = data.dump() + BuildDecisionBook.pre_query = BuildDecisionBook.select_action( + duty_id=token.duty_list["duty_id"] + ) + cls.pre_query = cls.select_action(duty_id=token.duty_list["duty_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 + ) + if decision_book_is_already := cls.find_one(**found_dict): + decision_book_is_already.is_found = True + return decision_book_is_already.get_dict() + data_dict["build_decision_book_id"] = decision_book.id + data_dict["is_confirmed"] = True + del data_dict["build_decision_book_uu_id"] + return BuildDecisionBookItems.find_or_create(**data_dict) + + @classmethod + def check_meeting_is_valid_to_start_add_attendance(cls, decision_book, token_dict): + from Schemas import ( + People, + OccupantTypes, + ) + + active_invite = ( + BuildDecisionBookInvitations.check_invites_are_ready_for_meeting( + selected_decision_book=decision_book, + token_dict=token_dict, + ) + ) + occupant_type_required_list = ("MT-PRS", "MT-WRT", "BU-MNG", "BU-SPV") + 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.filter_one( + BuildDecisionBookInvitations.id == active_invite.id + ).data + people_book_attend_count = None + if int(invitation.invitation_attempt) == 1: + people_book_attend_is_attending = BuildDecisionBookPerson.filter_all( + BuildDecisionBookPerson.invite_id == invitation.id, + BuildDecisionBookPerson.is_attending == True, + ) + people_book_attend = BuildDecisionBookPersonOccupants.filter_all( + BuildDecisionBookPersonOccupants.build_decision_book_person_id.in_( + [person.id for person in people_book_attend_is_attending.data] + ), + BuildDecisionBookPersonOccupants.occupant_type_id.in_( + [occupant_type.id for occupant_type in occupant_type_list] + ), + ) + people_book_attend_count = people_book_attend.count + if not people_book_attend_count == len(occupant_type_required_list) - 1: + error_detail = " - ".join(occupant_type_required_list) + raise HTTPException( + status_code=status.HTTP_400_BAD_REQUEST, + detail=f"{error_detail} occupant types must be attend to meeting. " + f"Check attendants and try again", + ) + + comment = ( + lambda id_, occ_type, full_name: f"{full_name} is nomindated for {occ_type} at Meeting Invite Code : {id_}" + ) + book_items_dict = dict( + build_decision_book_id=decision_book.id, + build_decision_book_uu_id=str(decision_book.uu_id), + is_confirmed=True, + active=True, + is_payment_created=True, + ) + 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.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 + created_attendance = BuildDecisionBookItems.find_or_create( + **book_items_dict, + item_order=1, + item_comment=comment( + id_=person_invite_pret.invite_uu_id, + occ_type=occupant_type_pre.occupant_type, + full_name=person.full_name, + ), + ) + created_attendance.save_and_confirm() + + 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 + created_attendance = BuildDecisionBookItems.find_or_create( + **book_items_dict, + item_order=2, + item_comment=comment( + id_=person_invite_wrt.invite_uu_id, + occ_type=occupant_type_wrt.occupant_type, + full_name=person.full_name, + ), + ) + created_attendance.save_and_confirm() + + 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 + created_attendance = BuildDecisionBookItems.find_or_create( + **book_items_dict, + item_order=3, + item_comment=comment( + id_=person_invite_mng.invite_uu_id, + occ_type=occupant_type_mng.occupant_type, + full_name=person.full_name, + ), + ) + created_attendance.save_and_confirm() + return people_book_attend_count + + +class BuildDecisionBookItemsUnapproved(CrudCollection): + """ + Builds class based on declarative_base and BaseMixin via session unapproved personnel + """ + + __tablename__ = "build_decision_book_items_unapproved" + __exclude__fields__ = [] + __language_model__ = BuildDecisionBookItemsUnapprovedLanguageModel + + 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[int] = mapped_column( + ForeignKey("build_decision_book_items.id"), nullable=False + ) + 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[int] = mapped_column( + ForeignKey("build_decision_book_items.id"), nullable=False + ) + build_decision_book_item_uu_id: Mapped[str] = mapped_column( + String, nullable=True, comment="Decision Book Item UUID" + ) + + __table_args__ = ( + Index("_build_decision_book_item_unapproved_ndx_01", build_decision_book_item), + { + "comment": "People that are unapproved partially or completely in decision book items" + }, + ) + + +class BuildDecisionBookPayments(CrudCollection): + """ + Builds class based on declarative_base and BaseMixin via session + period_time = to_char(NEW.process_date, 'YYYY-MM'); + """ + + __tablename__ = "build_decision_book_payments" + __exclude__fields__ = [] + __enum_list__ = [("receive_debit", "DebitTypes", "D")] + __language_model__ = BuildDecisionBookPaymentsLanguageModel + + payment_plan_time_periods: Mapped[str] = mapped_column( + String(10), nullable=False, comment="Payment Plan Time Periods" + ) + process_date: Mapped[TIMESTAMP] = mapped_column( + TIMESTAMP(timezone=True), 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") + + payment_types_id: Mapped[int] = mapped_column( + ForeignKey("api_enum_dropdown.id"), nullable=True + ) + payment_types_uu_id: Mapped[str] = mapped_column( + String, nullable=True, comment="Dues Type UUID" + ) + + period_time: Mapped[str] = mapped_column(String(12)) + process_date_y: Mapped[int] = mapped_column(SmallInteger) + process_date_m: Mapped[int] = mapped_column(SmallInteger) + + 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[str] = mapped_column( + String, nullable=False, comment="Decision Book Item UUID" + ) + # build_decision_book_id: Mapped[int] = mapped_column( + # ForeignKey("build_decision_book.id"), nullable=True + # ) + # build_decision_book_uu_id: Mapped[str] = mapped_column( + # String, nullable=True, comment="Decision Book UUID" + # ) + build_parts_id: Mapped[int] = mapped_column( + ForeignKey("build_parts.id"), nullable=False + ) + build_parts_uu_id: Mapped[str] = mapped_column( + String, nullable=False, comment="Build Part UUID" + ) + 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[str] = mapped_column( + String, nullable=True, comment="Decision Book Project UUID" + ) + account_records_id: Mapped[int] = mapped_column( + ForeignKey("account_records.id"), nullable=True + ) + account_records_uu_id: Mapped[str] = mapped_column( + String, nullable=True, comment="Account Record UU ID" + ) + + # budget_records_id: Mapped[int] = mapped_column(ForeignKey("account_records.id"), nullable=True) + # budget_records_uu_id: Mapped[str] = mapped_column( + # String, nullable=True, comment="Budget UUID" + # ) + # accounting_id: Mapped[int] = mapped_column(ForeignKey("account_detail.id"), nullable=True) + # accounting_uu_id: Mapped[str] = mapped_column( + # String, nullable=True, comment="Accounting UUID" + # ) + # receive_debit_id: Mapped[int] = mapped_column(ForeignKey("api_enum_dropdown.id"), nullable=True) + # receive_debit_uu_id: Mapped[str] = mapped_column(String, nullable=True, comment="Debit UUID") + + # accounting: Mapped["AccountDetail"] = relationship( + # "AccountDetail", + # back_populates="decision_book_payment_detail", + # foreign_keys=[accounting_id], + # ) + # + # decision_book_master: Mapped["BuildDecisionBookPaymentsMaster"] = relationship( + # "BuildDecisionBookPaymentsMaster", + # back_populates="decision_book_payment_detail", + # foreign_keys=[build_decision_book_payments_master_id], + # ) + # budget_records: Mapped["CompanyBudgetRecords"] = relationship( + # "CompanyBudgetRecords", + # back_populates="decision_book_payment_detail", + # foreign_keys=[budget_records_id], + # ) + + __table_args__ = ( + Index( + "build_decision_book_payments_detail_ndx_00", + build_decision_book_item_id, + build_parts_id, + payment_plan_time_periods, + process_date, + payment_types_id, + account_records_id, + unique=True, + ), + Index("build_decision_book_payments_detail_ndx_01", account_records_id), + {"comment": "Payment Details of Decision Book Payments"}, + ) + + +class BuildDecisionBookLegal(CrudCollection): + """ + Builds class based on declarative_base and BaseMixin via session + lawsuits_type C:Court Mehkeme M: mediator arabulucu + """ + + __tablename__ = "build_decision_book_legal" + __exclude__fields__ = [] + __language_model__ = BuildDecisionBookLegalLanguageModel + + period_start_date: Mapped[TIMESTAMP] = mapped_column( + TIMESTAMP(timezone=True), nullable=False, comment="Start Date of Legal Period" + ) + lawsuits_decision_number: Mapped[str] = mapped_column( + String, nullable=False, comment="Lawsuits Decision Number" + ) + lawsuits_decision_date: Mapped[TIMESTAMP] = mapped_column( + TIMESTAMP(timezone=True), nullable=False, comment="Lawsuits Decision Date" + ) + + period_stop_date: Mapped[TIMESTAMP] = mapped_column( + TIMESTAMP(timezone=True), server_default="2099-12-31 23:59:59" + ) + 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(timezone=True), server_default="1900-01-01 00:00:00", nullable=True + ) + meeting_date: Mapped[TIMESTAMP] = mapped_column( + TIMESTAMP(timezone=True), server_default="1900-01-01 00:00:00" + ) + 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)) + legal_cost: Mapped[float] = mapped_column(Numeric(20, 2)) + approved_cost: Mapped[float] = mapped_column(Numeric(20, 2)) + total_price: Mapped[float] = mapped_column(Numeric(20, 2)) + + build_db_item_id: Mapped[int] = mapped_column( + ForeignKey("build_decision_book_items.id"), nullable=False + ) + 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[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[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[str] = mapped_column( + String, nullable=True, comment="Mediator Lawyer UUID" + ) + + __table_args__ = ( + Index("_build_decision_book_legal_ndx_00", meeting_date), + { + "comment": "Legal items related to decision book items recoreded at building meetings" + }, + ) + + +class BuildDecisionBookProjects(CrudCollection): + """ + Builds class based on declarative_base and BaseMixin via session + project_type = C:Court Mehkeme M: mediator arabulucu + """ + + __tablename__ = "build_decision_book_projects" + __exclude__fields__ = [] + __language_model__ = BuildDecisionBookProjectsLanguageModel + + project_no: Mapped[str] = mapped_column( + String(12), nullable=True, comment="Project Number of Decision Book" + ) + project_name: Mapped[str] = mapped_column( + String, nullable=False, comment="Project Name" + ) + project_start_date: Mapped[TIMESTAMP] = mapped_column( + TIMESTAMP(timezone=True), nullable=False, comment="Project Start Date" + ) + project_stop_date: Mapped[TIMESTAMP] = mapped_column( + TIMESTAMP(timezone=True), 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[str] = mapped_column( + String, server_default="", nullable=True + ) + is_completed: Mapped[bool] = mapped_column( + Boolean, server_default="0", comment="Project is Completed" + ) + status_code: Mapped[int] = mapped_column(SmallInteger, 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") + + meeting_date: Mapped[TIMESTAMP] = mapped_column( + TIMESTAMP(timezone=True), server_default="1900-01-01 00:00:00", index=True + ) + currency: Mapped[str] = 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") + + contact_id: Mapped[int] = mapped_column( + ForeignKey("contracts.id"), nullable=True, comment="Contract id" + ) + contact_uu_id: Mapped[str] = mapped_column( + String, nullable=True, comment="Contract UUID" + ) + build_decision_book_id: Mapped[int] = mapped_column( + ForeignKey("build_decision_book.id"), nullable=False + ) + build_decision_book_uu_id: Mapped[str] = mapped_column( + String, nullable=True, comment="Decision Book UUID" + ) + build_decision_book_item_id: Mapped[int] = mapped_column( + ForeignKey("build_decision_book_items.id"), nullable=False + ) + build_decision_book_item_uu_id: Mapped[str] = mapped_column( + String, nullable=True, comment="Decision Book Item UUID" + ) + 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[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[str] = mapped_column( + String, nullable=True, comment="Company UUID" + ) + + build_decision_book_item: Mapped["BuildDecisionBookItems"] = relationship( + "BuildDecisionBookItems", + back_populates="decision_book_project", + foreign_keys=[build_decision_book_item_id], + ) + + @classmethod + def select_action(cls, duty_id, token=None): + from Schemas import ( + Build, + Companies, + ) + + related_companies = Companies.select_action(duty_id_list=[duty_id]) + 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_ids = list(related_.id for related_ in related_building.data) + related_decision_books = BuildDecisionBook.filter_all( + BuildDecisionBook.build_id.in_(related_building_ids), + ).data + related_decision_books_ids = list( + related_.id for related_ in related_decision_books + ) + related_decision_books_items = BuildDecisionBookItems.filter_all( + BuildDecisionBookItems.build_decision_book_id.in_( + related_decision_books_ids + ), + ).data + related_decision_books_items_ids = list( + related_.id for related_ in related_decision_books_items + ) + return cls.filter_all( + cls.build_decision_book_item_id.in_(related_decision_books_items_ids), + ).query + + @classmethod + def create_action(cls, data: InsertBuildDecisionBookProjects, token=None): + from Schemas import ( + People, + Companies, + ) + + data_dict = data.dump() + BuildDecisionBookItems.pre_query = BuildDecisionBookItems.select_action( + duty_id=token.duty_list["duty_id"] + ) + People.pre_query = People.select_action( + duty_id_list=[token.duty_list["duty_id"]] + ) + decision_book_project_item = BuildDecisionBookItems.find_one_or_abort( + uu_id=data_dict.get("build_decision_book_item_uu_id") + ) + project_response_person = People.find_one_or_abort( + uu_id=data_dict.get("project_response_person_uu_id") + ) + data_dict["build_decision_book_item_id"] = decision_book_project_item.id + data_dict["project_response_person_id"] = project_response_person.id + if data.resp_company_uu_id: + resp_company = Companies.find_one(uu_id=data.resp_company_uu_id) + data_dict["resp_company_id"] = resp_company.id + del ( + data_dict["build_decision_book_item_uu_id"], + data_dict["project_response_person_uu_id"], + ) + del data_dict["resp_company_uu_id"] + data_dict["is_confirmed"] = True + return cls.find_or_create(**data_dict) + + __table_args__ = ( + Index( + "_build_decision_book_project_ndx_00", + project_no, + project_start_date, + unique=True, + ), + { + "comment": "Project related to decision taken at building meetings on book items" + }, + ) + + @property + def get_project_year(self): + return self.decision_book_items.decision_books.period_start_date.year + + @property + def get_project_no(self): + return f"{self.get_project_year}-{str(self.id)[-4:].zfill(4)}" + + +class BuildDecisionBookProjectPerson(CrudCollection): + """ + Builds class based on declarative_base and BaseMixin via session + """ + + __tablename__ = "build_decision_book_project_person" + __exclude__fields__ = [] + __language_model__ = BuildDecisionBookProjectPersonLanguageModel + # __enum_list__ = [("management_typecode", "ProjectTeamTypes", "PTT-EMP")] + + 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[int] = mapped_column( + ForeignKey("build_decision_book_projects.id"), nullable=False + ) + 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[str] = mapped_column( + String, nullable=True, comment="Living Space UUID" + ) + + __table_args__ = ( + {"comment": "People that are attended to building project meetings."}, + ) + + +class BuildDecisionBookProjectItems(CrudCollection): + """ + Builds class based on declarative_base and BaseMixin via session + """ + + __tablename__ = "build_decision_book_project_items" + __exclude__fields__ = [] + __language_model__ = BuildDecisionBookProjectItemsLanguageModel + + item_header: Mapped[str] = mapped_column( + String, nullable=False, comment="Item Header" + ) + item_comment: Mapped[str] = mapped_column( + Text, nullable=False, comment="Item Comment" + ) + attachment_pdf_path: Mapped[str] = mapped_column( + String, server_default="", nullable=True, comment="Attachment PDF Path" + ) + item_estimated_cost: Mapped[float] = mapped_column( + Numeric(16, 2), server_default="0", comment="Estimated Cost" + ) + item_short_comment: Mapped[str] = mapped_column( + String(24), + nullable=True, + comment="This field is reserved for use in grouping data or in the pivot heading.", + ) + + build_decision_book_project_id: Mapped[int] = mapped_column( + ForeignKey("build_decision_book_projects.id"), nullable=False + ) + build_decision_book_project_uu_id: Mapped[str] = mapped_column( + String, nullable=True, comment="Decision Book Project UUID" + ) + + __table_args__ = ( + {"comment": "Project Items related to decision taken at building meetings"}, + ) + + +# +# class BuildDecisionBookPaymentsMaster(CrudCollection): +# """ +# Builds class based on declarative_base and BaseMixin via session +# """ +# +# __tablename__ = "build_decision_book_payments_master" +# __exclude__fields__ = [] +# __enum_list__ = [("dues_types", "BuildDuesTypes", "D")] +# +# payment_plan_time_periods = mapped_column( +# String(8), nullable=False, comment="Payment Plan Time Periods" +# ) +# default_payment_amount = mapped_column( +# Numeric(20, 2), nullable=False, comment="Default Payment Amount" +# ) +# +# dues_types_id: Mapped[int] = mapped_column(ForeignKey("api_enum_dropdown.id"), nullable=True) +# dues_types_uu_id = mapped_column(String, nullable=True, comment="Dues Type UUID") +# build_decision_book_item_debits_id = mapped_column( +# ForeignKey("build_decision_book_item_debits.id"), nullable=False +# ) +# build_decision_book_item_debits_uu_id = mapped_column( +# String, nullable=True, comment="Decision Book Item Debit UUID" +# ) +# build_parts_id: Mapped[int] = mapped_column(ForeignKey("build_parts.id"), nullable=False) +# build_parts_uu_id = mapped_column(String, nullable=True, comment="Build Part UUID") +# +# # decision_books_item_debits: Mapped["BuildDecisionBookItemDebits"] = relationship( +# # "BuildDecisionBookItemDebits", +# # back_populates="decision_book_payment_masters", +# # foreign_keys=[build_decision_book_item_debits_id], +# # ) +# # parts: Mapped["BuildParts"] = relationship( +# # "BuildParts", +# # back_populates="decision_book_payment_master", +# # foreign_keys=[build_parts_id], +# # ) +# # decision_book_payment_detail: Mapped[List["BuildDecisionBookPaymentsDetail"]] = ( +# # relationship( +# # "BuildDecisionBookPaymentsDetail", +# # back_populates="decision_book_master", +# # foreign_keys="BuildDecisionBookPaymentsDetail.build_decision_book_payments_master_id", +# # ) +# # ) +# +# __table_args__ = ( +# Index( +# "_build_decision_book_payments_master_ndx_00", +# build_decision_book_item_debits_id, +# build_parts_id, +# dues_types_id, +# unique=True, +# ), +# { +# "comment": "Master Payment Items related to decision taken at building meetings" +# }, +# ) +# +# # @classmethod +# # def pay_dues_of_build_part( +# # cls, +# # budget_records_id, +# # build_decision_book_id, +# # build_parts_id, +# # start_date, +# # paid_value, +# # is_all=False, +# # is_limited=False, +# # ): +# # +# # book_payment_master = cls.find_one( +# # build_decision_book_id=build_decision_book_id, +# # build_parts_id=build_parts_id, +# # dues_types=BuildDuesTypes.D.name, +# # ) +# # paid_amount = 0 +# # if book_payment_master: +# # month_start_date = ( +# # find_first_day_of_month(start_date) +# # if not is_all +# # else datetime(1900, 1, 1) +# # ) +# # last_date = ( +# # find_last_day_of_month(start_date) if not is_limited else start_date +# # ) +# # payment_dues, count = BuildDecisionBookPaymentsDetail.filter( +# # and_( +# # BuildDecisionBookPaymentsDetail.build_decision_book_payments_master_id +# # == book_payment_master.id, +# # BuildDecisionBookPaymentsDetail.process_date >= month_start_date, +# # BuildDecisionBookPaymentsDetail.process_date <= last_date, +# # ) +# # ) +# # period_amount = {} +# # for payment_due in payment_dues: +# # if payment_due.period_time not in period_amount: +# # period_amount[payment_due.period_time] = 0 +# # period_amount[payment_due.period_time] += float( +# # payment_due.payment_amount +# # ) +# # paid_amount += payment_due.payment_amount +# # print( +# # "period_amount", +# # period_amount, +# # "paid_amount", +# # paid_amount, +# # "paid_value", +# # paid_value, +# # ) +# # if paid_amount > 0: +# # return float(paid_value) +# # period_amounts = sorted( +# # period_amount.items(), key=lambda x: x[0], reverse=False +# # ) +# # for period_amount in period_amounts: +# # if period_amount[1] >= 0: +# # continue +# # if not paid_value > 0: +# # break +# # if budget_record := CompanyBudgetRecords.find_one(id=budget_records_id): +# # debit_to_pay = abs(float(period_amount[1])) +# # debit_to_pay = ( +# # paid_value if debit_to_pay > paid_value else debit_to_pay +# # ) +# # budget_record.remainder_balance = float(debit_to_pay) + float( +# # budget_record.remainder_balance +# # ) +# # budget_record.save() +# # BuildDecisionBookPaymentsDetail.find_or_create( +# # build_decision_book_payments_master_id=book_payment_master.id, +# # budget_records_id=budget_records_id, +# # process_date=str(start_date), +# # receive_debit=DebitTypes.R.name, +# # period_time=str(period_amount[0]), +# # process_date_y=str(period_amount[0]).split("-")[0], +# # process_date_m=str(period_amount[0]).split("-")[1], +# # payment_amount=abs(debit_to_pay), +# # ) +# # paid_value = float(paid_value) - float(debit_to_pay) +# # return float(paid_value) +# # + +# +# class BuildDecisionBookItemDebits(CrudCollection): +# """ +# Builds class based on declarative_base and BaseMixin via session +# dues_values = due_key, due_value +# """ +# +# __tablename__ = "build_decision_book_item_debits" +# __exclude__fields__ = [] +# __enum_list__ = [("dues_types", "BuildDuesTypes", "D")] +# +# dues_types_id: Mapped[int] = mapped_column(ForeignKey("api_enum_dropdown.id"), nullable=True) +# dues_types_uu_id = mapped_column(String, nullable=True, comment="Dues Type UUID") +# # dues_values = mapped_column( +# # MutableDict.as_mutable(JSONB()), +# # nullable=False, +# # comment="Due Part Key Description of inner parts", +# # ) +# flat_type = mapped_column( +# String, nullable=True, comment="Flat Type of Building Part" +# ) +# flat_payment = mapped_column( +# Numeric(20, 2), nullable=True, comment="Flat Payment Amount" +# ) +# decision_taken: Mapped[bool] = mapped_column(Boolean, server_default="0") +# +# build_decision_book_item_id = mapped_column( +# ForeignKey("build_decision_book_items.id"), nullable=False +# ) +# build_decision_book_item_uu_id = mapped_column( +# String, nullable=True, comment="Decision Book Item UUID" +# ) +# +# @classmethod +# def select_action(cls, duty_id, token=None): +# from database_sql_models import Companies +# +# related_companies = Companies.select_action(duty_id=duty_id) +# related_companies_ids = list( +# related_.id for related_ in related_companies.all() +# ) +# related_building = Build.query.filter( +# Build.company_id.in_(related_companies_ids) +# ) +# related_building_ids = list(related_.id for related_ in related_building.all()) +# related_decision_books = BuildDecisionBook.query.filter( +# BuildDecisionBook.build_id.in_(related_building_ids) +# ) +# related_decision_books_ids = list( +# related_.id for related_ in related_decision_books.all() +# ) +# related_decision_books_items = BuildDecisionBookItems.query.filter( +# BuildDecisionBookItems.build_decision_book_id.in_( +# related_decision_books_ids +# ) +# ) +# related_decision_books_items_ids = list( +# related_.id for related_ in related_decision_books_items.all() +# ) +# return cls.query.filter( +# cls.build_decision_book_item_id.in_(related_decision_books_items_ids) +# ) +# +# @classmethod +# def create_action(cls, data: InsertBuildDecisionBookItemDebits, token): +# from database_sql_models import ApiEnumDropdown +# from application.shared_functions import find_last_day_of_month +# +# data_dict = data.dump() +# BuildDecisionBookItems.pre_query = BuildDecisionBookItems.select_action( +# duty_id=token.duty_list["duty_id"] +# ) +# cls.pre_query = cls.select_action(duty_id=token.duty_list["duty_id"]) +# if decision_book_item := BuildDecisionBookItems.find_one_or_abort( +# uu_id=data.build_decision_book_item_uu_id +# ): +# data_dict["build_decision_book_item_id"] = decision_book_item.id +# dues_values, payment_master_list = data_dict["dues_values"], [] +# data_dict["is_confirmed"] = True +# del data_dict["build_decision_book_item_uu_id"] +# item_debits = cls.find_or_create(**data_dict) +# debit_dropdown = ApiEnumDropdown.find_one( +# enum_class="DebitTypes", value="Debit" +# ) +# for dues_key, dues_value in dues_values.items(): +# building_parts = decision_book_item.decision_books.buildings.parts +# decision_book = decision_book_item.decision_books +# for building_part in building_parts: +# detail_list = [] +# if str(building_part.due_part_key) == str(dues_key): +# book_master = BuildDecisionBookPaymentsMaster.create( +# build_decision_book_item_debits_id=item_debits.id, +# build_parts_id=building_part.id, +# dues_types=debit_dropdown.uu_id, +# payment_plan_time_periods="M", +# default_payment_amount=dues_value, +# is_confirmed=True, +# ) +# if book_master: +# start_date = decision_book.expiry_starts +# while start_date <= decision_book.expiry_ends: +# start_date = find_last_day_of_month(start_date) +# data_detail = BuildDecisionBookPaymentsDetail.find_or_create( +# build_decision_book_payments_master_id=book_master.id, +# budget_records_id=None, +# process_date=start_date, +# receive_debit=debit_dropdown.uu_id, +# period_time=start_date.strftime("%Y-%m"), +# process_date_y=start_date.year, +# process_date_m=start_date.month, +# accounting_id=None, +# payment_amount=float(dues_value) * -1, +# is_confirmed=True, +# ) +# start_date = start_date + timedelta(days=2) +# detail_list.append(data_detail.get_dict()) +# payment_master_list.append( +# {**book_master.get_dict(), "detail_list": detail_list} +# ) +# return_dict = { +# **item_debits.get_dict(), +# "debit_lists": payment_master_list, +# } +# return return_dict +# +# __table_args__ = ( +# { +# "comment": "Debits of Decision Book Items that are related to decision taken at building meetings" +# }, +# ) + + +# +# class BuildDecisionBookBudget(CrudCollection): +# """ +# Builds class based on declarative_base and BaseMixin via session +# """ +# +# __tablename__ = "build_decision_book_budget" +# +# item_order = mapped_column(SmallInteger, nullable=False, comment="Order Number") +# budget_type = mapped_column(String, nullable=False, comment="Budget Type") +# plan_value: Mapped[float] = mapped_column(Numeric(10, 2), nullable=False, comment="Plan Value") +# +# line_comment = mapped_column(String(32), server_default="") +# process_date_y: Mapped[int] = mapped_column(SmallInteger) +# process_date_m: Mapped[int] = mapped_column(SmallInteger) +# process_date_w: Mapped[int] = mapped_column(SmallInteger) +# period_time = mapped_column(String(12), server_default="") +# +# build_decision_book_id: Mapped[int] = mapped_column(ForeignKey("build_decision_book.id")) +# accounting_id = mapped_column(ForeignKey("account_detail.id")) +# +# __table_args__ = ( +# Index("_build_decision_book_budget_ndx_01", accounting_id), +# {"comment": "Budget Items related to decision taken at building meetings"}, +# ) +# +# +# class BuildDecisionBookBudgetItem(CrudCollection): +# """ +# Builds class based on declarative_base and BaseMixin via session +# """ +# +# __tablename__ = "build_decision_book_budget_item" +# __exclude__fields__ = [] +# +# paid_date = mapped_column(TIMESTAMP, nullable=False, comment="Payment Due Date") +# period_time = mapped_column(String(12), server_default="") +# paid_value: Mapped[float] = mapped_column(Numeric(10, 2), server_default="0") +# +# build_decision_book_budget_id = mapped_column( +# ForeignKey("build_decision_book_budget.id"), nullable=False +# ) +# +# __table_args__ = ( +# Index( +# "_build_decision_book_budget_item_ndx_01", +# build_decision_book_budget_id, +# paid_date, +# ), +# ) +# + + +# buildings: Mapped["Build"] = relationship( +# "Build", back_populates="decision_books", foreign_keys=[build_id] +# ) +# companies: Mapped[List["Company"]] = relationship( +# "Company", back_populates="decision_books", foreign_keys=[resp_company_id] +# ) +# budget_records: Mapped[List["CompanyBudgetRecords"]] = relationship( +# "CompanyBudgetRecords", +# back_populates="decision_books", +# foreign_keys="CompanyBudgetRecords.build_decision_book_id", +# ) +# decision_book_items: Mapped[List["BuildDecisionBookItems"]] = relationship( +# "BuildDecisionBookItems", +# back_populates="decision_books", +# foreign_keys="BuildDecisionBookItems.build_decision_book_id", +# ) +# +# decision_book_management: Mapped["BuildDecisionBookManagement"] = relationship( +# "BuildDecisionBookManagement", +# back_populates="decision_book", +# foreign_keys="BuildDecisionBookManagement.build_decision_book_id", +# ) +# +# decision_book_people: Mapped[List["BuildDecisionBookPerson"]] = relationship( +# "BuildDecisionBookPerson", +# back_populates="decision_books", +# foreign_keys="BuildDecisionBookPerson.build_decision_book_id", +# ) +# +# # decision_book_projects: Mapped[List["DecisionBookProjects"]] = relationship( +# # "DecisionBookProjects", +# # back_populates="decision_books", +# # foreign_keys="DecisionBookProjects.build_decision_book_id", +# # ) +# # decision_book_project_people: Mapped[List["BuildDecisionBookProjectPerson"]] = ( +# # relationship( +# # "BuildDecisionBookProjectPerson", +# # back_populates="decision_books", +# # foreign_keys="BuildDecisionBookProjectPerson.build_decision_book_id", +# # ) +# # ) +# decision_book_legal_people: Mapped["BuildDecisionBookProjectsLegal"] = relationship( +# "BuildDecisionBookProjectsLegal", +# back_populates="decision_books", +# foreign_keys="BuildDecisionBookProjectsLegal.build_decision_book_id", +# ) +# +# decision_book_budget: Mapped["BuildDecisionBookBudget"] = relationship( +# "BuildDecisionBookBudget", +# back_populates="decision_book", +# foreign_keys="BuildDecisionBookBudget.build_decision_book_id", +# ) + +# decision_book_items: Mapped[List["BuildDecisionBookItems"]] = relationship( +# "BuildDecisionBookItems", +# back_populates="decision_book_item_debits", +# foreign_keys=[build_decision_book_item_id], +# ) +# decision_book_payment_masters: Mapped[List["BuildDecisionBookPaymentsMaster"]] = relationship( +# "BuildDecisionBookPaymentsMaster", +# back_populates="decision_books_item_debits", +# foreign_keys="BuildDecisionBookPaymentsMaster.build_decision_book_item_debits_id", +# ) +# +# decision_books: Mapped["BuildDecisionBook"] = relationship( +# "BuildDecisionBook", +# back_populates="decision_book_items", +# foreign_keys=[build_decision_book_id], +# ) +# decision_book_item_debits: Mapped[List["BuildDecisionBookItemDebits"]] = ( +# relationship( +# "BuildDecisionBookItemDebits", +# back_populates="decision_book_items", +# foreign_keys="BuildDecisionBookItemDebits.build_decision_book_item_id", +# ) +# ) +# decision_book_projects: Mapped["DecisionBookProjects"] = relationship( +# "DecisionBookProjects", +# back_populates="decision_book_items", +# foreign_keys="DecisionBookProjects.build_decision_book_item_id", +# ) +# decision_book_legal: Mapped["BuildDecisionBookLegal"] = relationship( +# "BuildDecisionBookLegal", +# back_populates="decision_books_items", +# foreign_keys="BuildDecisionBookLegal.build_db_item_id", +# ) +# +# build_decision_book_item_unapproved: Mapped[ +# List["BuildDecisionBookItemsUnapproved"] +# ] = relationship( +# "BuildDecisionBookItemsUnapproved", +# back_populates="decision_book_items", +# foreign_keys="BuildDecisionBookItemsUnapproved.build_decision_book_item", +# ) + +# decision_books_items: Mapped["BuildDecisionBookItems"] = relationship( +# "BuildDecisionBookItems", +# back_populates="decision_book_legal", +# foreign_keys=[build_db_item_id], +# ) +# attorney_companies: Mapped["Companies"] = relationship( +# "Company", +# back_populates="decision_book_legal", +# foreign_keys=[resp_attorney_company], +# ) +# attorney_persons: Mapped["People"] = relationship( +# "People", +# back_populates="attorney_decision_book_legal", +# foreign_keys=[resp_attorney_id], +# ) +# lawyer_persons: Mapped["People"] = relationship( +# "People", +# back_populates="lawyer_decision_book_legal", +# foreign_keys=[mediator_lawyer_person_id], +# ) + +# decision_books: Mapped["BuildDecisionBook"] = relationship( +# "BuildDecisionBook", +# back_populates="decision_book_people", +# foreign_keys=[build_decision_book_id], +# ) +# people: Mapped["People"] = relationship( +# "People", back_populates="decision_book_people", foreign_keys=[person_id] +# ) + +# decision_book_budget: Mapped["BuildDecisionBookBudget"] = relationship( +# "BuildDecisionBookBudget", +# back_populates="decision_book_budget_item", +# foreign_keys=[build_decision_book_budget_id], +# ) + +# accounting: Mapped["AccountDetail"] = relationship( +# "AccountDetail", +# back_populates="decision_book_budget", +# foreign_keys=[accounting_id], +# ) +# decision_book: Mapped["BuildDecisionBook"] = relationship( +# "BuildDecisionBook", +# back_populates="decision_book_budget", +# foreign_keys=[build_decision_book_id], +# ) +# decision_book_budget_item: Mapped["BuildDecisionBookBudgetItem"] = relationship( +# "BuildDecisionBookBudgetItem", +# back_populates="decision_book_budget", +# foreign_keys="BuildDecisionBookBudgetItem.build_decision_book_budget_id", +# ) + +# decision_book_items: Mapped["BuildDecisionBookItems"] = relationship( +# "BuildDecisionBookItems", +# back_populates="build_decision_book_item_unapproved", +# foreign_keys=[build_decision_book_item], +# ) +# +# peoples: Mapped["People"] = relationship( +# "People", +# back_populates="build_decision_book_item_unapproved", +# foreign_keys=[person_id], +# ) +# +# class BuildDecisionBookInvitationsPerson(CrudCollection): +# """ +# Builds class based on declarative_base and BaseMixin via session +# """ +# +# __tablename__ = "build_decision_book_invitations_person" +# __exclude__fields__ = [] +# +# invite_id = mapped_column(ForeignKey("build_decision_book_invitations.id"), nullable=False) +# invite_uu_id = mapped_column(String, nullable=True, comment="Invite UUID") +# person_id = mapped_column(ForeignKey("people.id"), nullable=False) +# person_uu_id = mapped_column(String, nullable=False, comment="Person UUID") +# +# send_date = mapped_column(TIMESTAMP, nullable=False, comment="Confirmation Date") +# is_confirmed: Mapped[bool] = mapped_column(Boolean, server_default="0", comment="Message is Confirmed") +# confirmed_date = mapped_column(TIMESTAMP, nullable=True, comment="Confirmation Date") +# token = mapped_column(String, server_default="", comment="Invitation Token") +# +# __table_args__ = ( +# Index( +# "decision_book_invitations_person_ndx_01", +# invite_id, +# person_id, +# unique=True, +# ), +# {"comment": "People that are invited to building meetings."}, +# ) diff --git a/Schemas/company/company.py b/Schemas/company/company.py new file mode 100644 index 0000000..627124c --- /dev/null +++ b/Schemas/company/company.py @@ -0,0 +1,585 @@ +from fastapi.exceptions import HTTPException + +from databases.sql_models.core_mixin import CrudCollection + +from sqlalchemy import ( + String, + Integer, + Boolean, + ForeignKey, + Index, + Identity, + TIMESTAMP, + func, +) +from sqlalchemy.orm import mapped_column, relationship, Mapped + +from api_configs import RelationAccess +from databases.extensions import SelectAction +from api_validations.validations_request import ( + InsertCompany, + UpdateCompany, + MatchCompany2Company, +) +from api_objects.auth.token_objects import EmployeeTokenObject +from databases.language_models.company.company import ( + RelationshipDutyCompanyLanguageModel, + CompaniesLanguageModel, + # CompanyDutiesLanguageModel, +) + + +class RelationshipDutyCompany(CrudCollection): + """ + CompanyRelationship class based on declarative_base and CrudCollection via session + Company -> Sub Company -> Sub-Sub Company + + if owner_id == parent_id: can manipulate data of any record + else: Read-Only + duty_id = if relationship_type == base An organization / not operational / no responsible person + + relationship = company_id filter -> Action filter(company_id) relationship_type = Organization + relationship = company_id filter -> Action filter(company_id) relationship_type = Commercial + """ + + __tablename__ = "relationship_duty_company" + __exclude__fields__ = [] + __access_by__ = RelationAccess.SuperAccessList + __language_model__ = RelationshipDutyCompanyLanguageModel + + owner_id: Mapped[int] = mapped_column( + ForeignKey("companies.id"), nullable=False + ) # 1 + duties_id: Mapped[int] = mapped_column( + ForeignKey("duties.id"), nullable=False + ) # duty -> (n)employee Evyos LTD + + member_id: Mapped[int] = mapped_column( + ForeignKey("companies.id"), nullable=False + ) # 2, 3, 4 + parent_id: Mapped[int] = mapped_column( + ForeignKey("companies.id"), nullable=True + ) # None + + relationship_type: Mapped[str] = mapped_column( + String, nullable=True, server_default="Commercial" + ) # Commercial, Organization # Bulk + child_count: Mapped[int] = mapped_column(Integer) # 0 + show_only: Mapped[bool] = mapped_column(Boolean, server_default="0") + + # related_company: Mapped[List["Companies"]] = relationship( + # "Companies", + # back_populates="related_companies", + # foreign_keys=[related_company_id], + # ) + + @classmethod + def match_company_to_company_commercial(cls, data: MatchCompany2Company, token): + from databases import ( + Duties, + ) + + token_duties_id, token_company_id = token.get("duty_id"), token.get( + "company_id" + ) + list_match_company_id = [] + send_duties = Duties.filter_one( + Duties.uu_id == data.duty_uu_id, + ) + send_user_duties = Duties.filter_one( + Duties.duties_id == send_duties.id, + Duties.company_id == token_duties_id, + ) + if not send_user_duties: + raise Exception( + "Send Duty is not found in company. Please check duty uuid and try again." + ) + + for company_uu_id in list(data.match_company_uu_id): + company = Companies.filter_one( + Companies.uu_id == company_uu_id, + ) + bulk_company = RelationshipDutyCompany.filter_one( + RelationshipDutyCompany.owner_id == token_company_id, + RelationshipDutyCompany.relationship_type == "Bulk", + RelationshipDutyCompany.member_id == company.id, + ) + if not bulk_company: + raise Exception( + f"Bulk Company is not found in company. " + f"Please check company uuid {bulk_company.uu_id} and try again." + ) + list_match_company_id.append(bulk_company) + + for match_company_id in list_match_company_id: + RelationshipDutyCompany.find_or_create( + owner_id=token_company_id, + duties_id=send_user_duties.id, + member_id=match_company_id.id, + parent_id=match_company_id.parent_id, + relationship_type="Commercial", + show_only=False, + ) + + @classmethod + def match_company_to_company_organization(cls, data: MatchCompany2Company, token): + from databases import ( + Duties, + ) + + token_duties_id, token_company_id = token.get("duty_id"), token.get( + "company_id" + ) + list_match_company_id = [] + send_duties = Duties.filter_one( + Duties.uu_id == data.duty_uu_id, + ) + send_user_duties = Duties.filter_one( + Duties.duties_id == send_duties.id, + Duties.company_id == token_duties_id, + ) + if not send_user_duties: + raise Exception( + "Send Duty is not found in company. Please check duty uuid and try again." + ) + + for company_uu_id in list(data.match_company_uu_id): + company = Companies.filter_one( + Companies.uu_id == company_uu_id, + ) + bulk_company = RelationshipDutyCompany.filter_one( + RelationshipDutyCompany.owner_id == token_company_id, + RelationshipDutyCompany.relationship_type == "Bulk", + RelationshipDutyCompany.member_id == company.id, + ) + if not bulk_company: + raise Exception( + f"Bulk Company is not found in company. " + f"Please check company uuid {bulk_company.uu_id} and try again." + ) + list_match_company_id.append(bulk_company) + + for match_company_id in list_match_company_id: + Duties.init_a_company_default_duties( + company_id=match_company_id.id, + company_uu_id=str(match_company_id.uu_id), + ) + RelationshipDutyCompany.find_or_create( + owner_id=token_company_id, + duties_id=send_user_duties.id, + member_id=match_company_id.id, + parent_id=match_company_id.parent_id, + relationship_type="Organization", + show_only=False, + ) + + __table_args__ = ( + Index( + "_company_relationship_ndx_01", + duties_id, + owner_id, + member_id, + relationship_type, + unique=True, + ), + {"comment": "Company Relationship Information"}, + ) + + +class Companies(CrudCollection, SelectAction): + """ + Company class based on declarative_base and CrudCollection via session + formal_name = Government register name by offical + public_name = Public registered name by User + nick_name = Search by nickname, commercial_type = Tüzel veya birey + """ + + __tablename__ = "companies" + + __exclude__fields__ = ["is_blacklist", "is_commercial"] + __access_by__ = [] + __many__table__ = RelationshipDutyCompany + __language_model__ = CompaniesLanguageModel + # __explain__ = AbstractCompany() + + formal_name: Mapped[str] = mapped_column( + String, nullable=False, comment="Formal Name" + ) + company_type: Mapped[str] = mapped_column( + String, nullable=False, comment="Company Type" + ) + commercial_type: Mapped[str] = mapped_column( + String, nullable=False, comment="Commercial Type" + ) + tax_no: Mapped[str] = mapped_column( + String, index=True, unique=True, nullable=False, comment="Tax No" + ) + + public_name: Mapped[str] = mapped_column(String, comment="Public Name of a company") + company_tag: Mapped[str] = mapped_column(String, comment="Company Tag") + default_lang_type: Mapped[str] = mapped_column(String, server_default="TR") + default_money_type: Mapped[str] = mapped_column(String, server_default="TL") + is_commercial: Mapped[bool] = mapped_column(Boolean, server_default="False") + is_blacklist: Mapped[bool] = mapped_column(Boolean, server_default="False") + parent_id = mapped_column(Integer, nullable=True) + workplace_no: Mapped[str] = mapped_column(String, nullable=True) + + official_address_id: Mapped[int] = mapped_column( + ForeignKey("addresses.id"), nullable=True + ) + official_address_uu_id: Mapped[str] = mapped_column( + String, nullable=True, comment="Official Address UUID" + ) + top_responsible_company_id: Mapped[int] = mapped_column( + ForeignKey("companies.id"), nullable=True + ) + top_responsible_company_uu_id: Mapped[str] = mapped_column( + String, nullable=True, comment="Top Responsible Company UUID" + ) + + # buildings: Mapped[List["Build"]] = relationship( + # "Build", + # back_populates="companies", + # foreign_keys="Build.company_id", + # ) + + __table_args__ = ( + Index("_company_ndx_01", tax_no, unique=True), + Index("_company_ndx_02", formal_name, public_name), + {"comment": "Company Information"}, + ) + + @classmethod + def create_action(cls, data: InsertCompany, token: EmployeeTokenObject): + from databases import Addresses, Duties + + data_dict = data.model_dump() + if cls.filter_one(cls.tax_no == str(data.tax_no).strip(), system=True).data: + raise HTTPException( + status_code=400, + detail="Company already exists. Please ask supervisor to make company visible for your duty.", + ) + + official_address = Addresses.filter_one( + Addresses.uu_id == data.official_address_uu_id, + ).data + # if not official_address: + # raise HTTPException( + # status_code=400, + # detail="Official address is not found. Please check address uuid and try again.", + # ) + + bulk_duties = Duties.get_bulk_duties_of_a_company( + company_id=token.selected_company.company_id + ) + + if official_address: + data_dict["official_address_id"] = official_address.id + data_dict["official_address_uu_id"] = str(official_address.uu_id) + + data_dict["parent_id"] = token.selected_company.company_id + data_dict["top_responsible_company_id"] = token.selected_company.company_id + data_dict["top_responsible_company_uu_id"] = ( + token.selected_company.company_uu_id + ) + company_created = cls.find_or_create(**data_dict) + company_created.save_and_confirm() + company_relationship_created = RelationshipDutyCompany.find_or_create( + owner_id=token.selected_company.company_id, + duties_id=bulk_duties.id, + member_id=company_created.id, + parent_id=company_created.parent_id, + child_count=0, + relationship_type="Bulk", + show_only=False, + ) + company_relationship_created.save_and_confirm() + return company_created + + @classmethod + def update_action(cls, data: UpdateCompany, token): + from databases import ( + Addresses, + ) + + data_dict = data.excluded_dump() + duty_id = token.get("duty_id") + company_id = token.get("company_id") + if data.official_address_uu_id: + official_address = Addresses.filter_one( + Addresses.uu_id == data.official_address_uu_id, + *Addresses.valid_record_args(Addresses), + ).data + data_dict["official_address_id"] = official_address.id + del data_dict["official_address_uu_id"], data_dict["company_uu_id"] + company_to_update = cls.select_action( + duty_id_list=[duty_id], + filter_expr=[ + cls.uu_id == data.company_uu_id, + RelationshipDutyCompany.parent_id == company_id, + ], + ) + return company_to_update.update(**data_dict) + + # parent_id = mapped_column(ForeignKey("companies.id")) + # if data.parent_uu_id: + # company = Companies.find_one(uu_id=data.parent_uu_id) + # data_dict["parent_id"] = company.id + # def is_access_valid(self, endpoint_ext: str): + # try: + # if ( + # not arrow.get(self.stop_date) + # > arrow.utcnow() + # > arrow.get(self.start_date) + # ): + # message = f"Kullanıcı yetkileri süresi dolmuştur. {self.endpoint_name} için supervisor ile görüşünüz." + # SystemLogs.create_log( + # log_type="ERROR", + # log_code="ACCESS_EXPIRED", + # log_action=self.__tablename__, + # log_message=message, + # ) + # return False + # except Exception as e: + # SystemLogs.create_log( + # log_type="ERROR", + # log_code="ACCESS_EXPIRED", + # log_action=self.__tablename__, + # log_message=e, + # ) + # return False + # + # access_dict = { + # "LIST": self.access_read, + # "INSERT": self.access_write, + # "UPDATE": self.access_update, + # "DELETE": self.access_delete, + # "ACTIVE": self.access_update, + # "PRINT": self.report_print, + # "EXPORT": self.report_export, + # } + # return access_dict.get(endpoint_ext.upper(), False) + + # official_address: Mapped[List["Address"]] = relationship( + # "Address", + # back_populates="official_companies", + # foreign_keys=[official_address_id], + # ) + # + # emails: Mapped[List["UsersEmails"]] = relationship( + # "UsersEmails", back_populates="companies", foreign_keys="UsersEmails.company_id" + # ) + # phones: Mapped[List["UsersPhones"]] = relationship( + # "UsersPhones", back_populates="company", foreign_keys="UsersPhones.company_id" + # ) + # buildings: Mapped[List["Build"]] = relationship( + # "Build", + # back_populates="companies", + # foreign_keys="Build.company_id", + # ) + # response_buildings: Mapped[List["Build"]] = relationship( + # "Build", + # back_populates="response_companies", + # foreign_keys="Build.response_company_id", + # ) + # departments: Mapped[List["CompanyDepartments"]] = relationship( + # "CompanyDepartments", + # back_populates="company", + # foreign_keys="CompanyDepartments.company_id", + # ) + # budget_records: Mapped[List["CompanyBudgetRecords"]] = relationship( + # "CompanyBudgetRecords", + # back_populates="companies", + # foreign_keys="CompanyBudgetRecords.company_id", + # ) + # send_budget_records: Mapped[List["CompanyBudgetRecords"]] = relationship( + # "CompanyBudgetRecords", + # back_populates="send_companies", + # foreign_keys="CompanyBudgetRecords.send_company_id", + # ) + # decision_books: Mapped[List["BuildDecisionBook"]] = relationship( + # "BuildDecisionBook", + # back_populates="companies", + # foreign_keys="BuildDecisionBook.resp_company_id", + # ) + # decision_book_projects: Mapped[List["BuildDecisionBookProjects"]] = relationship( + # "BuildDecisionBookProjects", + # back_populates="companies", + # foreign_keys="BuildDecisionBookProjects.resp_company_id", + # ) + # decision_book_legal: Mapped["BuildDecisionBookLegal"] = relationship( + # "BuildDecisionBookLegal", + # back_populates="attorney_companies", + # foreign_keys="BuildDecisionBookLegal.resp_attorney_company", + # ) + # + # company_account_books: Mapped["AccountBooks"] = relationship( + # "AccountBooks", + # back_populates="company", + # foreign_keys="AccountBooks.company_id", + # ) + # branch_account_books: Mapped["AccountBooks"] = relationship( + # "AccountBooks", + # back_populates="branch", + # foreign_keys="AccountBooks.branch_id", + # ) + # account_codes: Mapped["AccountCodes"] = relationship( + # "AccountCodes", back_populates="company", foreign_keys="AccountCodes.company_id" + # ) + # search_iban_description: Mapped["BuildIbanDescription"] = relationship( + # "BuildIbanDescription", + # back_populates="company", + # foreign_keys="BuildIbanDescription.company_id", + # ) + # related_companies: Mapped[List["CompanyRelationship"]] = relationship( + # "CompanyRelationship", + # back_populates="related_company", + # foreign_keys="CompanyRelationship.related_company_id", + # ) + + +# +# class AbstractCompany: +# """ +# Abstract and explanation of Company class for end-user guide +# """ +# +# formal_name = Explanation( +# explanation="Devletin resmi kayıtlarında bulunan şirket ünvanıdır.", +# usage="Devletin resmi kayıtlarında bulunan şirket adı istendiğinde kullanılır.", +# alias="Resmi Ünvan", +# example=["X Şirketi LTD", "Y Şirketi A.Ş."], +# ) +# company_type = Explanation( +# explanation="Şirketin türüdür.", +# usage="Şirketin türü istendiğinde kullanılır.", +# alias="Şirket Türü", +# example=[ +# "Şahıs", +# "Limited", +# "Anonim", +# "Kolektif", +# "Komandit", +# "Kooperatif", +# "Serbest Meslek", +# "Adi Ortaklık", +# ], +# ) +# commercial_type = Explanation( +# explanation="Şirketin ticari türüdür.", +# usage="Şirketin ticari türü istendiğinde kullanılır.", +# alias="Ticari Tür", +# example=["Tüzel", "Birey"], +# ) +# tax_no = Explanation( +# explanation="Şirketin vergi numarasıdır.", +# usage="Şirketin vergi numarası istendiğinde kullanılır.", +# alias="Vergi No", +# example=["1234567890"], +# ) +# public_name = Explanation( +# explanation="Şirketin kamuoyunda bilinen adıdır.", +# usage="Şirketin kamuoyunda bilinen adı istendiğinde kullanılır.", +# alias="Piyasada Bilinen Adı", +# example=["X Şirketi", "Y Şirketi"], +# ) +# company_tag = Explanation( +# explanation="Şirketin takma adı veya etiketidir.", +# usage="Şirketin yöneticisin karar verdiği takma adı veya etiketi istendiğinde kullanılır.", +# alias="Şirket Etiketi veya Takma Adı", +# example=["X", "Y"], +# ) +# default_lang_type = Explanation( +# explanation="Şirketin varsayılan dil türüdür.", +# usage="Şirketin varsayılan dil türü istendiğinde kullanılır.", +# alias="Şirketin Dil Türü", +# example=["TR", "EN"], +# ) +# default_money_type = Explanation( +# explanation="Şirketin varsayılan para birimi türüdür.", +# usage="Şirketin varsayılan para birimi türü istendiğinde kullanılır.", +# alias="Şirketin Para Birimi Türü", +# example=["TL", "USD", "EUR"], +# ) +# is_commercial = Explanation( +# explanation="Şirketin ticari olup olmadığını belirtir.", +# usage="Şirketin ticari olup olmadığını applikasyonun anlaması için kullanılır.", +# condition=lambda commercial_type: True if commercial_type == "Şahıs" else False, +# alias="Şirket Ticari mi?", +# ) +# is_blacklist = Explanation( +# explanation="Şirketin kara listeye alınıp alınmadığını belirtir.", +# usage="Şirketin kara listeye alınıp alınmadığını applikasyonun anlaması için kullanılır.", +# alias="Kara Listeye alınsın mı?", +# example=[True, False], +# ) +# parent_id = Explanation( +# explanation="Şirketin sorumlu olduğu şirketin ID'sidir.", +# usage="Şirketin sorumlu olduğu şirketin ID'si istendiğinde kullanılır.", +# alias="Sorumlu Şirket", +# example=[ +# "Bir şirketin sorumlu şirketi hangisi olduğunu bulmak için kullanılır.", +# ], +# ) +# workplace_no = Explanation( +# explanation="Şirketin iş yeri numarasıdır.", +# usage="Şirketin iş yeri numarası istendiğinde kullanılır.", +# alias="İş Yeri No", +# example=["1234567890"], +# ) +# official_address_id = Explanation( +# explanation="Şirketin resmi adresidi.", +# usage="Şirketin resmi adresinin ne olduğunu bulmak için kullanılır.", +# alias="Resmi Adres", +# example=[ +# "Bu şirketin adresi nedir sorusuna cevap vermek için kullanılır.", +# ], +# ) +# top_responsible_company_id = Explanation( +# explanation="Şirketin en üst sorumlu şirketin ID'sidir.", +# usage="Şirketin en üst sorumlu şirketin hangisi olduğunu bulmak için kullanılır.", +# alias="Ana Yetkili Şirket", +# example=[ +# "Bölge veya ülke genelinde en üst sorumlu şirketin hangisi olduğunu belirtmek için kullanılır.", +# ], +# ) +# buildings = Explanation( +# explanation="Şirketin sahip olduğu binaların listesidir.", +# usage="Şirketin sahip olduğu binaların listesini bulmak için kullanılır.", +# alias="Sorumlu olduğu binalar Binalar", +# example=[ +# "Şirketin sahip olduğu binaların listesini bulmak için kullanılır.", +# ], +# ) +# +# def wag_create_company(self): +# """ +# Er kişiye wag_create_company fonksiyonu = fieldları manipule edebilir? +# 78 ile oluşturulan bir user için wag_create_company fonksiyonu = fieldları manipule edebilir? +# """ +# return { +# "commercial_type": self.commercial_type, +# "formal_name": self.formal_name, +# "public_name": self.public_name, +# "company_type": self.company_type, +# "tax_no": self.tax_no, +# "workplace_no": self.workplace_no, +# "company_tag": self.company_tag, +# "default_lang_type": self.default_lang_type, +# "default_money_type": self.default_money_type, +# "official_address_id": self.official_address_id, +# } +# +# def wag_update_company(self): +# return { +# "commercial_type": self.commercial_type, +# "formal_name": self.formal_name, +# "public_name": self.public_name, +# "company_type": self.company_type, +# "tax_no": self.tax_no, +# "workplace_no": self.workplace_no, +# "company_tag": self.company_tag, +# "default_lang_type": self.default_lang_type, +# "default_money_type": self.default_money_type, +# "official_address_id": self.official_address_id, +# } diff --git a/Schemas/company/department.py b/Schemas/company/department.py new file mode 100644 index 0000000..6c3e31d --- /dev/null +++ b/Schemas/company/department.py @@ -0,0 +1,232 @@ +from sqlalchemy import String, Integer, ForeignKey, Index, Boolean, Identity +from sqlalchemy.orm import mapped_column, Mapped + +from databases.sql_models.core_mixin import CrudCollection + + +class Departments(CrudCollection): + + __tablename__ = "departments" + __exclude__fields__ = [] + + parent_department_id = mapped_column(Integer, server_default="0") + department_code = mapped_column( + String(16), nullable=False, index=True, comment="Department Code" + ) + department_name: Mapped[str] = mapped_column( + String(128), nullable=False, comment="Department Name" + ) + department_description: Mapped[str] = mapped_column(String, server_default="") + + company_id: Mapped[int] = mapped_column(ForeignKey("companies.id"), nullable=False) + company_uu_id: Mapped[str] = mapped_column( + String, nullable=False, comment="Company UUID" + ) + + # @classmethod + # def create_action(cls, data: DepartmentsPydantic, token): + # data_dict = data.model_dump() + # data_dict["company_id"] = token.selected_company.company_id + # return cls.find_or_create(**data_dict) + + __table_args__ = {"comment": "Departments Information"} + + +class Duty(CrudCollection): + + __tablename__ = "duty" + __exclude__fields__ = [] + + duty_name: Mapped[str] = mapped_column( + String, unique=True, nullable=False, comment="Duty Name" + ) + duty_code: Mapped[str] = mapped_column(String, nullable=False, comment="Duty Code") + duty_description: Mapped[str] = mapped_column(String, comment="Duty Description") + + # @classmethod + # def create_action(cls, data: InsertCompanyDuty, token): + # # if not cls.__is_super__: + # # raise HTTPException( + # # status_code=401, detail="You are not authorized to create a duty." + # # ) + # data_dict = data.model_dump() + # + # return cls.find_or_create(**data_dict) + + __table_args__ = ({"comment": "Duty Information"},) + + +class Duties(CrudCollection): + + __tablename__ = "duties" + __exclude__fields__ = [] + + users_default_duty = mapped_column( + ForeignKey("duty.id"), nullable=True, comment="Default Duty for Users" + ) + company_id: Mapped[int] = mapped_column(Integer) + company_uu_id: Mapped[str] = mapped_column( + String, nullable=False, comment="Company UUID" + ) + duties_id: Mapped[int] = mapped_column(ForeignKey("duty.id"), nullable=False) + duties_uu_id: Mapped[str] = mapped_column( + String, nullable=False, comment="Duty UUID" + ) + department_id = mapped_column( + ForeignKey("departments.id"), nullable=False, comment="Department ID" + ) + department_uu_id: Mapped[str] = mapped_column( + String, nullable=False, comment="Department UUID" + ) + # priority_id: Mapped[int] = mapped_column(ForeignKey("priority.id"), nullable=True) + management_duty = mapped_column( + Boolean, server_default="0" + ) # is this a prime Company Duty ??? + + @classmethod + def init_a_company_default_duties(cls, company_id, company_uu_id): + __default_init__ = ["Execution Office", "IT Department"] + + active_row = dict( + is_confirmed=True, active=True, deleted=False, is_notification_send=True + ) + list_of_created = [] + + execution = Departments.find_or_create( + department_name="Execution Office", + department_code="EO001", + company_id=company_id, + company_uu_id=str(company_uu_id), + **active_row, + ) + list_of_created.append(execution) + it_dept = Departments.find_or_create( + department_name="IT Department", + department_code="ITD001", + company_id=company_id, + company_uu_id=str(company_uu_id), + **active_row, + ) + list_of_created.append(it_dept) + bm_duty = Duty.find_or_create( + duty_name="Business Manager", + duty_code="BM0001", + duty_description="Business Manager", + **active_row, + ) + list_of_created.append(bm_duty) + it_duty = Duty.find_or_create( + duty_name="IT Manager", + duty_code="IT0001", + duty_description="IT Manager", + **active_row, + ) + list_of_created.append(it_duty) + bulk_duty = Duty.find_or_create( + duty_name="BULK", + duty_code="BULK", + duty_description="BULK RECORDS OF THE COMPANY", + **active_row, + ) + list_of_created.append(bulk_duty) + occu_duty = Duty.find_or_create( + duty_name="OCCUPANT", + duty_code="OCCUPANT", + duty_description="OCCUPANT RECORDS OF THE COMPANY", + **active_row, + ) + list_of_created.append(occu_duty) + duties_created_bm = cls.find_or_create( + company_id=company_id, + company_uu_id=str(company_uu_id), + duties_id=bm_duty.id, + duties_uu_id=str(bm_duty.uu_id), + department_id=execution.id, + department_uu_id=str(execution.uu_id), + **active_row, + ) + list_of_created.append(duties_created_bm) + duties_created_it = cls.find_or_create( + company_id=company_id, + company_uu_id=str(company_uu_id), + duties_id=it_duty.id, + duties_uu_id=str(it_duty.uu_id), + department_id=it_dept.id, + department_uu_id=str(it_dept.uu_id), + **active_row, + ) + list_of_created.append(duties_created_it) + duties_created__ex = cls.find_or_create( + company_id=company_id, + company_uu_id=str(company_uu_id), + duties_id=bulk_duty.id, + duties_uu_id=str(bulk_duty.uu_id), + department_id=execution.id, + department_uu_id=str(execution.uu_id), + **active_row, + ) + list_of_created.append(duties_created__ex) + duties_created_at = cls.find_or_create( + company_id=company_id, + company_uu_id=str(company_uu_id), + duties_id=occu_duty.id, + duties_uu_id=str(occu_duty.uu_id), + department_id=execution.id, + department_uu_id=str(execution.uu_id), + **active_row, + ) + list_of_created.append(duties_created_at) + return list_of_created + + @classmethod + def get_bulk_duties_of_a_company(cls, company_id): + duties_id = Duty.filter_by_one(system=True, duty_code="BULK").data + if bulk_duties := Duties.filter_by_one( + duties_id=getattr(duties_id, "id", None), + company_id=company_id, + **Duties.valid_record_dict, + ).data: + return bulk_duties + raise Exception("Bulk Duty not found. Please contact with supervisor.") + + # @classmethod + # def create_action(cls, data: InsertCompanyDuty): + # data_dict = data.model_dump() + # if department := Departments.find_one(uu_id=data.department_uu_id): + # data_dict["department_id"] = department.id + # del data_dict["department_uu_id"] + # return cls.find_or_create(**data_dict) + + __table_args__ = ( + Index("duty_ndx_00", company_id, duties_id, department_id, unique=True), + {"comment": "Duty & Company & Department Information"}, + ) + + # department: Mapped[List["CompanyDepartments"]] = relationship( + # "CompanyDepartments", back_populates="duties", foreign_keys=[department_id] + # ) + # employees: Mapped[List["CompanyEmployees"]] = relationship( + # "CompanyEmployees", + # back_populates="duty", + # foreign_keys="CompanyEmployees.duty_id", + # ) + # duty_app: Mapped["CompanyDutyApp"] = relationship( + # "CompanyDutyApp", back_populates="duties", foreign_keys="CompanyDutyApp.company_duty_id" + # ) + + # def get_language_of_duty(self, lang): + # if erp_text := ErpText.find_one(lang=lang, text_code=self.duty_code): + # return erp_text.text_name, erp_text.text_description + # return None, None + + # company: Mapped["Companies"] = relationship( + # "Company", back_populates="departments", foreign_keys=[company_id] + # ) + # duties: Mapped[List["CompanyDuty"]] = relationship( + # "CompanyDuty", + # back_populates="department", + # foreign_keys="CompanyDuty.department_id", + # ) + # app_item: Mapped["AppItems"] = relationship( + # "AppItems", back_populates="department", foreign_keys="AppItems.department_id" + # ) diff --git a/Schemas/company/employee.py b/Schemas/company/employee.py new file mode 100644 index 0000000..8411ddf --- /dev/null +++ b/Schemas/company/employee.py @@ -0,0 +1,153 @@ +from sqlalchemy import ( + String, + ForeignKey, + Index, + Numeric, +) +from sqlalchemy.orm import mapped_column, Mapped + +from databases.language_models.company.employee import ( + StaffLanguageModel, + EmployeesLanguageModel, + EmployeeHistoryLanguageModel, + EmployeesSalariesLanguageModel, +) +from databases.sql_models.core_mixin import CrudCollection + +from api_validations.validations_request import InsertCompanyEmployees + + +class Staff(CrudCollection): + + __tablename__ = "staff" + __exclude__fields__ = [] + __language_model__ = StaffLanguageModel + + staff_description: Mapped[str] = mapped_column( + String, server_default="", comment="Staff Description" + ) + staff_name: Mapped[str] = mapped_column( + String, nullable=False, comment="Staff Name" + ) + staff_code: Mapped[str] = mapped_column( + String, nullable=False, comment="Staff Code" + ) + + duties_id: Mapped[int] = mapped_column(ForeignKey("duties.id"), nullable=False) + duties_uu_id: Mapped[str] = mapped_column( + String, nullable=False, comment="Duty UUID" + ) + + # people: Mapped["People"] = relationship( + # "People", back_populates="employees", foreign_keys=[people_id], uselist=True + # ) + # duty: Mapped["CompanyDuty"] = relationship( + # "CompanyDuty", back_populates="employees", foreign_keys=[duty_id] + # ) + + @classmethod + def create_action(cls, data: InsertCompanyEmployees): + from databases import Duties + + data_dict = data.model_dump() + if duty := Duties.find_one(uu_id=data.duty_uu_id): + data_dict["duty_id"] = duty.id + # if person := People.find_one(uu_id=data.person_uu_id): + # data_dict["people_id"] = person.id + if data.start_date: + data_dict["expiry_starts"] = data.start_date + if data.stop_date: + data_dict["expiry_ends"] = data.stop_date + # del data_dict["duty_uu_id"], data_dict["person_uu_id"] + del data_dict["start_date"], data_dict["stop_date"], data_dict["duty_uu_id"] + return cls.find_or_create(**data_dict) + + __table_args__ = ({"comment": "Staff Information"},) + + +class Employees(CrudCollection): + + __tablename__ = "employees" + __exclude__fields__ = [] + __language_model__ = EmployeesLanguageModel + + staff_id: Mapped[int] = mapped_column(ForeignKey("staff.id")) + staff_uu_id: Mapped[str] = mapped_column( + String, nullable=False, comment="Staff UUID" + ) + people_id: Mapped[int] = mapped_column(ForeignKey("people.id"), nullable=True) + people_uu_id: Mapped[str] = mapped_column( + String, nullable=True, comment="People UUID" + ) + + __table_args__ = ( + Index("employees_ndx_00", people_id, staff_id, unique=True), + {"comment": "Employee Person Information"}, + ) + + +class EmployeeHistory(CrudCollection): + + __tablename__ = "employee_history" + __exclude__fields__ = [] + __language_model__ = EmployeeHistoryLanguageModel + + staff_id: Mapped[int] = mapped_column( + ForeignKey("staff.id"), nullable=False, comment="Staff ID" + ) + staff_uu_id: Mapped[str] = mapped_column( + String, nullable=False, comment="Staff UUID" + ) + people_id: Mapped[int] = mapped_column( + ForeignKey("people.id"), nullable=False, comment="People ID" + ) + people_uu_id: Mapped[str] = mapped_column( + String, nullable=False, comment="People UUID" + ) + + __table_args__ = ( + Index("_employee_history_ndx_00", people_id, staff_id), + {"comment": "Employee History Information"}, + ) + + +class EmployeesSalaries(CrudCollection): + + __tablename__ = "employee_salaries" + __exclude__fields__ = [] + __language_model__ = EmployeesSalariesLanguageModel + + gross_salary: Mapped[float] = mapped_column( + Numeric(20, 6), nullable=False, comment="Gross Salary" + ) + net_salary: Mapped[float] = mapped_column( + Numeric(20, 6), nullable=False, comment="Net Salary" + ) + + people_id: Mapped[int] = mapped_column(ForeignKey("people.id"), nullable=False) + people_uu_id: Mapped[str] = mapped_column( + String, nullable=False, comment="People UUID" + ) + + # people: Mapped["People"] = relationship( + # "People", back_populates="employee_salaries", foreign_keys=[people_id] + # ) + + __table_args__ = ( + Index("_employee_salaries_ndx_00", people_id, "expiry_starts"), + {"comment": "Employee Salaries Information"}, + ) + + +# class Events2Employees(CrudCollection): +# +# __tablename__ = "events2employees" +# __exclude__fields__ = [] +# +# event_id = mapped_column(ForeignKey("events.id"), nullable=False) +# employees_id = mapped_column(ForeignKey("employees.id"), nullable=False) +# +# __table_args__ = ( +# Index("_events2employees_ndx_00", event_id, employees_id), +# {"comment": "Events2Employees Information"}, +# ) diff --git a/Schemas/event/event.py b/Schemas/event/event.py new file mode 100644 index 0000000..ea4b7a1 --- /dev/null +++ b/Schemas/event/event.py @@ -0,0 +1,358 @@ +from databases.sql_models.core_mixin import CrudCollection +from databases.language_models.event.event import ( + EventsLanguageModel, + ModulesLanguageModel, + ServicesLanguageModel, + Service2EventsLanguageModel, + Event2OccupantExtraLanguageModel, + Event2EmployeeExtraLanguageModel, + Event2EmployeeLanguageModel, + Event2OccupantLanguageModel, + ModulePriceLanguageModel, +) + +from sqlalchemy import ( + String, + ForeignKey, + Numeric, + SmallInteger, + Boolean, + Integer, + Index, +) +from sqlalchemy.orm import mapped_column, Mapped + + +class Events(CrudCollection): + """ + Events class based on declarative_base and BaseMixin via session + If Events2Occupants and Events2Employees are not found for user request, response 401 Unauthorized + """ + + __tablename__ = "events" + __exclude__fields__ = [] + __language_model__ = EventsLanguageModel + + event_type: Mapped[str] = mapped_column( + String, nullable=False, comment="Event Type" + ) + function_code: Mapped[str] = mapped_column( + String, nullable=False, comment="function code" + ) + function_class: Mapped[str] = mapped_column( + String, nullable=False, comment="class name" + ) + + # name: Mapped[str] = mapped_column(String, nullable=True) # form or page title + description: Mapped[str] = mapped_column( + String, server_default="" + ) # form or page description + property_description: Mapped[str] = mapped_column(String, server_default="") + + marketing_layer = mapped_column(SmallInteger, server_default="3") + cost: Mapped[float] = mapped_column(Numeric(20, 2), server_default="0.00") + unit_price: Mapped[float] = mapped_column(Numeric(20, 2), server_default="0.00") + + endpoint_id: Mapped[int] = mapped_column( + ForeignKey("endpoint_restriction.id"), nullable=True + ) + endpoint_uu_id: Mapped[str] = mapped_column( + String, nullable=True, comment="Endpoint UUID" + ) + + __table_args__ = ({"comment": "Events Information"},) + + +class Modules(CrudCollection): + """ + Modules class based on declarative_base and BaseMixin via session + """ + + __tablename__ = "modules" + __exclude__fields__ = [] + __language_model__ = ModulesLanguageModel + + module_name: Mapped[str] = mapped_column( + String, nullable=False, comment="Module Name" + ) + module_description: Mapped[str] = mapped_column(String, server_default="") + module_code: Mapped[str] = mapped_column( + String, nullable=False, comment="Module Code" + ) + module_layer = mapped_column(Integer, nullable=False, comment="Module Layer") + is_default_module = mapped_column(Boolean, server_default="0") + + def retrieve_services(self): + services = Services.filter_all(Services.module_id == self.id).data + if not services: + self.raise_http_exception( + status_code="HTTP_404_NOT_FOUND", + error_case="RECORD_NOT_FOUND", + message=f"No services found for this module : {str(self.uu_id)}", + data={ + "module_uu_id": str(self.uu_id), + }, + ) + return services + + __table_args__ = ({"comment": "Modules Information"},) + + +class Services(CrudCollection): + """ + Services class based on declarative_base and BaseMixin via session + """ + + __tablename__ = "services" + __exclude__fields__ = [] + __language_model__ = ServicesLanguageModel + + module_id: Mapped[int] = mapped_column(ForeignKey("modules.id"), nullable=False) + module_uu_id: Mapped[str] = mapped_column( + String, nullable=False, comment="Module UUID" + ) + service_name: Mapped[str] = mapped_column( + String, nullable=False, comment="Service Name" + ) + service_description: Mapped[str] = mapped_column(String, server_default="") + service_code: Mapped[str] = mapped_column( + String, nullable=True, comment="Service Code" + ) + related_responsibility: Mapped[str] = mapped_column(String, server_default="") + + @classmethod + def retrieve_service_via_occupant_code(cls, occupant_code): + from databases import OccupantTypes + + occupant_type = OccupantTypes.filter_by_one( + system=True, + occupant_code=occupant_code, + ).data + if not occupant_type: + cls.raise_http_exception( + status_code="HTTP_404_NOT_FOUND", + error_case="RECORD_NOT_FOUND", + message=f"No occupant type found for this code : {occupant_code}", + data={ + "occupant_code": occupant_code, + }, + ) + return cls.filter_one( + cls.related_responsibility == occupant_type.occupant_code + ).data + + __table_args__ = ({"comment": "Services Information"},) + + +class Service2Events(CrudCollection): + """ + Service2Actions class based on declarative_base and BaseMixin via session + """ + + __tablename__ = "services2events" + __exclude__fields__ = [] + __language_model__ = Service2EventsLanguageModel + + service_id: Mapped[int] = mapped_column(ForeignKey("services.id"), nullable=False) + service_uu_id = mapped_column(String, nullable=False, comment="Service UUID") + event_id: Mapped[int] = mapped_column(ForeignKey("events.id"), nullable=False) + event_uu_id = mapped_column(String, nullable=False, comment="Event UUID") + + __table_args__ = ({"comment": "Service2Events Information"},) + + +class Event2OccupantExtra(CrudCollection): + + __tablename__ = "event2occupant_extra" + __exclude__fields__ = [] + __language_model__ = Event2OccupantExtraLanguageModel + + build_living_space_id: Mapped[int] = mapped_column( + ForeignKey("build_living_space.id"), nullable=False + ) + build_living_space_uu_id: Mapped[str] = mapped_column( + String, nullable=False, comment="Build Living Space UUID" + ) + event_id: Mapped[int] = mapped_column(ForeignKey("events.id"), nullable=False) + event_uu_id: Mapped[str] = mapped_column( + String, nullable=False, comment="Event UUID" + ) + + __table_args__ = ( + Index( + "event2occupant_extra_bind_event_to_occupant", + build_living_space_id, + event_id, + unique=True, + ), + {"comment": "Occupant2Event Information"}, + ) + + +class Event2EmployeeExtra(CrudCollection): + """ + Employee2Event class based on declarative_base and BaseMixin via session + """ + + __tablename__ = "event2employee_extra" + __exclude__fields__ = [] + __language_model__ = Event2EmployeeExtraLanguageModel + + employee_id: Mapped[int] = mapped_column(ForeignKey("employees.id"), nullable=False) + employee_uu_id: Mapped[str] = mapped_column( + String, nullable=False, comment="Employee UUID" + ) + + event_id: Mapped[int] = mapped_column(ForeignKey("events.id"), nullable=False) + event_uu_id: Mapped[str] = mapped_column( + String, nullable=False, comment="Event UUID" + ) + + __table_args__ = ( + Index( + "event2employee_extra_employee_to_event", + employee_id, + event_id, + unique=True, + ), + {"comment": "Employee to Event Information"}, + ) + + +class Event2Employee(CrudCollection): + """ + Employee2Event class based on declarative_base and BaseMixin via session + """ + + __tablename__ = "event2employee" + __exclude__fields__ = [] + __language_model__ = Event2EmployeeLanguageModel + + employee_id: Mapped[int] = mapped_column(ForeignKey("employees.id"), nullable=False) + employee_uu_id: Mapped[str] = mapped_column( + String, nullable=False, comment="Employee UUID" + ) + event_service_id: Mapped[int] = mapped_column( + ForeignKey("services.id"), nullable=False + ) + event_service_uu_id: Mapped[str] = mapped_column( + String, nullable=False, comment="Event Cluster UUID" + ) + + __table_args__ = ( + Index( + "event2employee_employee_to_event", + employee_id, + event_service_id, + unique=True, + ), + {"comment": "Employee to Event Information"}, + ) + + @classmethod + def get_event_id_by_employee_id(cls, employee_id) -> list: + occupant_events = cls.filter_all( + cls.employee_id == employee_id, + ).data + active_events = Service2Events.filter_all( + Service2Events.service_id.in_( + [event.event_service_id for event in occupant_events] + ), + system=True, + ).data + active_events_id = [event.event_id for event in active_events] + if extra_events := Event2EmployeeExtra.filter_all( + Event2EmployeeExtra.employee_id == employee_id + ).data: + active_events_id.extend([event.event_id for event in extra_events]) + return active_events_id + + +class Event2Occupant(CrudCollection): + """ + Occupant2Event class based on declarative_base and BaseMixin via session + """ + + __tablename__ = "event2occupant" + __exclude__fields__ = [] + __language_model__ = Event2OccupantLanguageModel + + build_living_space_id: Mapped[str] = mapped_column( + ForeignKey("build_living_space.id"), nullable=False + ) + build_living_space_uu_id: Mapped[str] = mapped_column( + String, nullable=False, comment="Build Living Space UUID" + ) + event_service_id: Mapped[int] = mapped_column( + ForeignKey("services.id"), nullable=False + ) + event_service_uu_id: Mapped[str] = mapped_column( + String, nullable=False, comment="Event Cluster UUID" + ) + # event_id: Mapped[int] = mapped_column(ForeignKey("events.id"), nullable=False) + # event_uu_id = mapped_column(String, nullable=False, comment="Event UUID") + + __table_args__ = ( + Index( + "event2occupant_bind_event_to_occupant", + build_living_space_id, + event_service_id, + unique=True, + ), + {"comment": "Occupant2Event Information"}, + ) + + @classmethod + def get_event_id_by_build_living_space_id(cls, build_living_space_id) -> list: + occupant_events = cls.filter_all( + cls.build_living_space_id == build_living_space_id, + ).data + active_events = Service2Events.filter_all( + Service2Events.service_id.in_( + [event.event_service_id for event in occupant_events] + ), + system=True, + ).data + active_events_id = [event.event_id for event in active_events] + if extra_events := Event2OccupantExtra.filter_all( + Event2OccupantExtra.build_living_space_id == build_living_space_id + ).data: + active_events_id.extend([event.event_id for event in extra_events]) + return active_events_id + + +class ModulePrice(CrudCollection): + """ + ModulePrice class based on declarative_base and BaseMixin via session + """ + + __tablename__ = "module_price" + __exclude__fields__ = [] + __language_model__ = ModulePriceLanguageModel + + campaign_code: Mapped[str] = mapped_column( + String, nullable=False, comment="Campaign Code" + ) + module_id: Mapped[int] = mapped_column(ForeignKey("modules.id"), nullable=False) + module_uu_id: Mapped[str] = mapped_column( + String, nullable=False, comment="Module UUID" + ) + service_id: Mapped[int] = mapped_column(ForeignKey("services.id"), nullable=False) + service_uu_id: Mapped[str] = mapped_column( + String, nullable=False, comment="Service UUID" + ) + event_id: Mapped[int] = mapped_column(ForeignKey("events.id"), nullable=False) + event_uu_id: Mapped[str] = mapped_column( + String, nullable=False, comment="Event UUID" + ) + is_counted_percentage: Mapped[float] = mapped_column( + Numeric(6, 2), server_default="0.00" + ) # %22 + discounted_price: Mapped[float] = mapped_column( + Numeric(20, 2), server_default="0.00" + ) # Normal: 78.00 TL + calculated_price: Mapped[float] = mapped_column( + Numeric(20, 2), server_default="0.00" + ) # sana düz 75.00 TL yapar + + __table_args__ = ({"comment": "ModulePrice Information"},) diff --git a/Schemas/identity/identity.py b/Schemas/identity/identity.py new file mode 100644 index 0000000..49399be --- /dev/null +++ b/Schemas/identity/identity.py @@ -0,0 +1,1059 @@ +from datetime import timedelta + +from fastapi import HTTPException +from sqlalchemy import ( + String, + Integer, + Boolean, + ForeignKey, + Index, + TIMESTAMP, + func, + Text, + BigInteger, + Numeric, + or_, +) +from sqlalchemy.orm import mapped_column, relationship, Mapped + +from api_library.date_time_actions.date_functions import system_arrow +from api_configs import Auth, ApiStatic, RelationAccess +from databases.sql_models.core_mixin import CrudCollection +from databases.extensions import SelectAction, SelectActionWithEmployee +from databases.extensions.auth import UserLoginModule +from api_validations.validations_request import InsertUsers, InsertPerson +from databases.language_models.identity.identity import ( + UsersTokensLanguageModel, + UsersLanguageModel, + PeopleLanguageModel, + RelationshipDutyPeopleLanguageModel, + RelationshipEmployee2PostCodeLanguageModel, + AddressPostcodeLanguageModel, + AddressesLanguageModel, + AddressGeographicLocationsLanguageModel, + AddressCountryLanguageModel, + AddressStateLanguageModel, + AddressCityLanguageModel, + AddressDistrictLanguageModel, + AddressLocalityLanguageModel, + AddressNeighborhoodLanguageModel, + AddressStreetLanguageModel, + OccupantTypesLanguageModel, + ContractsLanguageModel, +) + + +class UsersTokens(CrudCollection): + + __tablename__ = "users_tokens" + __exclude__fields__ = [] + __language_model__ = UsersTokensLanguageModel + + user_id: Mapped[int] = mapped_column(ForeignKey("users.id"), nullable=False) + + token_type: Mapped[str] = mapped_column(String(16), server_default="RememberMe") + token: Mapped[str] = mapped_column(String, server_default="") + domain: Mapped[str] = mapped_column(String, server_default="") + expires_at: Mapped[TIMESTAMP] = mapped_column( + TIMESTAMP(timezone=True), + default=str(system_arrow.shift(date=system_arrow.now(), days=3)), + ) + + # users = relationship("Users", back_populates="tokens", foreign_keys=[user_id]) + + +class Users(CrudCollection, UserLoginModule, SelectAction): + """ + Application User frame to connect to API with assigned token-based HTTP connection + """ + + __tablename__ = "users" + __exclude__fields__ = [ + "hash_password", + "password_token", + "expiry_begins", + "related_company", + ] + __language_model__ = UsersLanguageModel + + user_tag: Mapped[str] = mapped_column( + String(64), server_default="", comment="Unique tag for the user", index=True + ) + email: Mapped[str] = mapped_column( + String(128), server_default="", comment="Email address of the user", index=True + ) + phone_number: Mapped[str] = mapped_column( + String, server_default="", comment="Phone number of the user", index=True + ) + via: Mapped[str] = mapped_column( + String, + server_default="111", + comment="Email 1/ Phone 2/ User Tag 3 All 111 Only 100", + ) + + avatar: Mapped[str] = mapped_column( + String, server_default="", comment="Avatar URL for the user" + ) + hash_password: Mapped[str] = mapped_column( + String(256), server_default="", comment="Hashed password for security" + ) + password_token: Mapped[str] = mapped_column( + String(256), server_default="", comment="Token for password reset" + ) + remember_me: Mapped[bool] = mapped_column( + Boolean, server_default="0", comment="Flag to remember user login" + ) + + password_expires_day: Mapped[int] = mapped_column( + Integer, + server_default=str(Auth.PASSWORD_EXPIRE_DAY.days), + comment="Password expires in days", + ) + password_expiry_begins: Mapped[TIMESTAMP] = mapped_column( + TIMESTAMP(timezone=True), + server_default=func.now(), + comment="Timestamp when password expiry begins", + ) + related_company: Mapped[str] = mapped_column(String, comment="Related Company UUID") + + person_id: Mapped[int] = mapped_column( + ForeignKey("people.id"), nullable=False, comment="Foreign key to person table" + ) + person_uu_id: Mapped[str] = mapped_column( + String, server_default="", comment="Person UUID", index=True + ) + local_timezone = mapped_column( + String, server_default="GMT+3", comment="Local timezone of user" + ) + person = relationship("People", back_populates="user", foreign_keys=[person_id]) + + @property + def is_occupant(self): + return not str(self.email).split("@")[1] == Auth.ACCESS_EMAIL_EXT + + @property + def password_expiry_ends(self): + """Calculates the expiry end date based on expiry begins and expires day""" + return self.password_expiry_begins + timedelta( + days=int( + "".join( + [ + _ + for _ in str(self.password_expires_day).split(",")[0] + if _.isdigit() + ] + ) + ) + ) + + @property + def is_super_user(self): + """Checks if the user is a superuser based on priority code""" + return getattr(self.priority, "priority_code", 0) == 78 + + @property + def is_user(self): + """Checks if the user is a regular user based on priority code""" + return getattr(self.priority, "priority_code", 0) == 0 + + @classmethod + 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 ( + not any(i in str(create_user.email) for i in ["@", "."]) + and not len(str(create_user.phone_number)) >= 10 + ): + raise HTTPException( + status_code=400, + detail="Please enter at least one valid email or phone number.", + ) + if not create_user.avatar: + create_user.avatar = ApiStatic.PLACEHOLDER + create_dict = create_user.model_dump() + 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(found_user=created_user) + return created_user + + @classmethod + def credentials(cls): + person_object = People.filter_by_one(system=True, id=cls.person_id).data + if person_object: + return { + "person_id": person_object.id, + "person_uu_id": str(person_object.uu_id), + } + return { + "person_id": None, + "person_uu_id": None, + } + + def get_employee_and_duty_details(self): + from databases import Employees, Duties + + found_person = People.filter_one( + People.id == self.person_id, + ) + found_employees = Employees.filter_by_active( + people_id=found_person.id, is_confirmed=True + ) + found_duties = Duties.filter_all( + Duties.is_confirmed == True, + Duties.id.in_( + list(found_employee.duty_id for found_employee in found_employees.data) + ), + ) + if not found_employees.count: + raise HTTPException( + status_code=401, + detail={ + "message": "Person has no confirmed duty. No employee match please register " + "your super admin", + "completed": False, + }, + ) + return { + "duty_list": [ + { + "duty_id": duty.id, + "duty_uu_id": duty.uu_id.__str__(), + "duty_code": duty.duty_code, + "duty_name": duty.duty_name, + "duty_description": duty.duty_description, + } + for duty in found_duties.data + ], + } + + def get_main_domain_and_other_domains(self, get_main_domain: bool = True): + from databases import MongoQueryIdentity + + query_engine = MongoQueryIdentity(company_uuid=self.related_company) + domain_via_user = query_engine.get_domain_via_user(user_uu_id=str(self.uu_id)) + if not domain_via_user: + raise HTTPException( + status_code=401, + detail="Domain not found. Please contact the admin.", + ) + domain_via_user = domain_via_user[0] + if get_main_domain: + return domain_via_user.get("main_domain", None) + return domain_via_user.get("other_domains_list", None) + + +class RelationshipDutyPeople(CrudCollection): + + __tablename__ = "relationship_duty_people" + __exclude__fields__ = [] + __access_by__ = RelationAccess.SuperAccessList + __language_model__ = RelationshipDutyPeopleLanguageModel + + company_id: Mapped[int] = mapped_column( + ForeignKey("companies.id"), nullable=False + ) # 1, 2, 3 + duties_id: Mapped[int] = mapped_column( + ForeignKey("duties.id"), nullable=False + ) # duty -> (n)person Evyos LTD + member_id: Mapped[int] = mapped_column( + ForeignKey("people.id"), nullable=False + ) # 2, 3, 4 + + relationship_type: Mapped[str] = mapped_column( + String, nullable=True, server_default="Employee" + ) # Commercial + show_only: Mapped[bool] = mapped_column(Boolean, server_default="0") + + # related_company: Mapped[List["Company"]] = relationship( + # "Company", + # back_populates="related_companies", + # foreign_keys=[related_company_id], + # ) + + __table_args__ = ( + Index( + "person_relationship_ndx_01", + company_id, + duties_id, + member_id, + relationship_type, + unique=True, + ), + {"comment": "Person Relationship Information"}, + ) + + +class People(CrudCollection, SelectAction): + """ + People that are related to users in the application + """ + + __tablename__ = "people" + __exclude__fields__ = [] + __many__table__ = RelationshipDutyPeople + __encrypt_list__ = [ + "father_name", + "mother_name", + "country_code", + "national_identity_id", + "birth_place", + "birth_date", + "tax_no", + ] + __language_model__ = PeopleLanguageModel + + firstname: Mapped[str] = mapped_column( + String, nullable=False, comment="First name of the person" + ) + surname: Mapped[str] = mapped_column( + String(24), nullable=False, comment="Surname of the person" + ) + middle_name: Mapped[str] = mapped_column( + String, server_default="", comment="Middle name of the person" + ) + sex_code: Mapped[str] = mapped_column( + String(1), nullable=False, comment="Sex code of the person (e.g., M/F)" + ) + person_ref: Mapped[str] = mapped_column( + String, server_default="", comment="Reference ID for the person" + ) + person_tag: Mapped[str] = mapped_column( + String, server_default="", comment="Unique tag for the person" + ) + + # ENCRYPT DATA + father_name: Mapped[str] = mapped_column( + String, server_default="", comment="Father's name of the person" + ) + mother_name: Mapped[str] = mapped_column( + String, server_default="", comment="Mother's name of the person" + ) + country_code: Mapped[str] = mapped_column( + String(4), server_default="TR", comment="Country code of the person" + ) + national_identity_id: Mapped[str] = mapped_column( + String, server_default="", comment="National identity ID of the person" + ) + birth_place: Mapped[str] = mapped_column( + String, server_default="", comment="Birth place of the person" + ) + birth_date: Mapped[TIMESTAMP] = mapped_column( + TIMESTAMP(timezone=True), + server_default="1900-01-01", + comment="Birth date of the person", + ) + tax_no: Mapped[str] = mapped_column( + String, server_default="", comment="Tax number of the person" + ) + # ENCRYPT DATA + user = relationship( + "Users", back_populates="person", foreign_keys="Users.person_id" + ) + + __table_args__ = ( + Index( + "person_ndx_001", + national_identity_id, + unique=True, + ), + {"comment": "Person Information"}, + ) + + @property + def full_name(self): + if self.middle_name: + return f"{self.firstname} {self.middle_name} {self.surname}" + return f"{self.firstname} {self.surname}" + + @classmethod + def create_action(cls, data: InsertPerson, token): + from databases import Duties + + token_duties_id, token_company_id = ( + token.selected_company.duty_id, + token.selected_company.company_id, + ) + bulk_duty = Duties.get_bulk_duties_of_a_company(company_id=token_company_id) + + if str(data.country_code) == "TR": + if not len(data.national_identity_id) == 11: + raise HTTPException( + status_code=400, + detail="Please enter a valid national identity number.", + ) + if data.tax_no and not len(str(data.tax_no)) == 10: + raise HTTPException( + status_code=400, + detail="Please enter a valid tax number.", + ) + + create_dict = data.model_dump() + create_dict["firstname"] = str(create_dict["firstname"]).capitalize() + create_dict["middle_name"] = str(create_dict["middle_name"]).capitalize() + create_dict["surname"] = str(create_dict["surname"]).upper() + create_dict["birth_place"] = str(create_dict["birth_place"]).upper() + created_people = cls.find_or_create(**create_dict) + created_people.update(is_confirmed=True) + duty_people = RelationshipDutyPeople.find_or_create( + company_id=token.selected_company.company_id, + duties_id=bulk_duty.id, + member_id=created_people.id, + ) + duty_people.update(is_confirmed=True) + return created_people + + +class RelationshipEmployee2PostCode(CrudCollection): + """ + Build2EmployeeRelationship class based on declarative_base and BaseMixin via session + """ + + __tablename__ = "relationship_employee2postcode" + __exclude__fields__ = [] + __include__fields__ = [] + __language_model__ = RelationshipEmployee2PostCodeLanguageModel + + 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) + member_id: Mapped[int] = mapped_column( + ForeignKey("address_postcode.id"), nullable=False + ) + + relationship_type: Mapped[str] = mapped_column( + String, nullable=True, server_default="Employee" + ) # Commercial + show_only: Mapped[bool] = mapped_column(Boolean, server_default="0") + + __table_args__ = ({"comment": "Build2Employee Relationship Information"},) + + +class AddressPostcode(CrudCollection, SelectActionWithEmployee): + """ + Postcode class based on declarative_base and BaseMixin via session + """ + + __tablename__ = "address_postcode" + __exclude__fields__ = [] + __access_by__ = [] + __many__table__ = RelationshipEmployee2PostCode + __language_model__ = AddressPostcodeLanguageModel + + 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" + ) + + __table_args__ = ({"comment": "Postcode Information"},) + + +class Addresses(CrudCollection): + """ + Address class based on declarative_base and BaseMixin via session + """ + + __tablename__ = "addresses" + __exclude__fields__ = [] + __language_model__ = AddressesLanguageModel + + 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" + ) + + latitude: Mapped[float] = mapped_column(Numeric(20, 12), server_default="0") + longitude: Mapped[float] = mapped_column(Numeric(20, 12), server_default="0") + + 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" + ) + + @classmethod + 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, + ).data + post_code_id_list = [post_code.member_id for post_code in post_code_list] + if not post_code_id_list: + raise HTTPException( + 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 + filter_cls = cls.filter_all(*filter_expr or []) + cls.pre_query = None + return filter_cls.data + + # buildings: Mapped["Build"] = relationship( + # "Build", back_populates="addresses", foreign_keys="Build.address_id" + # ) + # site: Mapped["BuildSites"] = relationship( + # "BuildSites", back_populates="addresses", foreign_keys="BuildSites.address_id" + # ) + # official_companies: Mapped["Companies"] = relationship( + # "Company", + # back_populates="official_address", + # foreign_keys="Company.official_address_id", + # ) + + # @classmethod + # def create_action(cls, request, create_address: InsertAddress): + # from services.redis.auth_actions.token import parse_token_object_to_dict + # + # token_dict = parse_token_object_to_dict(request=request) + # data_dict = create_address.model_dump() + # post_code = AddressPostcode.find_one(uu_id=create_address.post_code_uu_id) + # if not post_code: + # raise HTTPException( + # status_code=404, + # detail="Post code not found.", + # ) + # if Employee2AddressRelationship.post_code_id.find_one( + # employee_id=token_dict.selected_company.employee_id, + # post_code_id=post_code.id, + # ): + # data_dict["post_code_id"] = post_code.id + # del data_dict["post_code_uu_id"] + # return cls.find_or_create(**create_address.model_dump()) + # raise HTTPException( + # status_code=401, + # detail=f"User is not qualified to create address at this post code {post_code.postcode}", + # ) + + # __table_args__ = ( + # Index("_address_ndx_00", country_code, b_state, city, district), + # {"comment": "Address Information"}, + # ) + + +class AddressGeographicLocations(CrudCollection): + """ + Country class based on declarative_base and BaseMixin via session + """ + + __tablename__ = "address_geographic_locations" + __exclude__fields__ = [] + __language_model__ = AddressGeographicLocationsLanguageModel + + 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" + ) + geo_longitude: Mapped[float] = mapped_column( + Numeric(20, 6), server_default="0", comment="Geographic Location Latitude" + ) + geo_altitude: Mapped[float] = mapped_column( + Numeric(20, 6), server_default="0", comment="Geographic Location Longitude" + ) + geo_description: Mapped[str] = mapped_column( + Text, nullable=False, comment="Geographic Location Description" + ) + geo_area_size: Mapped[float] = mapped_column( + Numeric(20, 2), + nullable=True, + server_default="0", + comment="Geographic Location Area Size", + ) + geo_population: Mapped[int] = mapped_column( + BigInteger, nullable=True, comment="Geographic Location Population" + ) + # geo_geom_point = mapped_column(Geometry('POINT', srid=4326), nullable=True, comment="Geographic Location Points") + # geo_geom_polygon = mapped_column(Geometry('POLYGON', srid=4326), nullable=True, + # comment="Geographic Location Vector geographic information (polygon)") + # geo_centroid = mapped_column( GEOMETRY(POINT, 4326), nullable=True, + # comment="Geographic Location center of gravity of the region(points)") + + __table_args__ = ( + Index("_address_geographic_locations_ndx_00", geo_table, geo_id), + Index("_address_geographic_locations_ndx_01", geo_latitude, geo_longitude), + {"comment": "Geographic Location Information"}, + ) + + +class AddressCountry(CrudCollection): + """ + Country class based on declarative_base and BaseMixin via session + """ + + __tablename__ = "address_country" + __exclude__fields__ = [] + __language_model__ = AddressCountryLanguageModel + + 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" + ) + + __table_args__ = ( + Index("_address_country_ndx_00", money_code), + Index("_address_country_ndx_01", country_code, unique=True), + {"comment": "Country Information"}, + ) + + +class AddressState(CrudCollection): + """ + State class based on declarative_base and BaseMixin via session + """ + + __tablename__ = "address_state" + __exclude__fields__ = [] + __language_model__ = AddressStateLanguageModel + + 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" + ) + + __table_args__ = ( + Index( + "_address_state_ndx_01", + country_id, + state_code, + unique=True, + ), + {"comment": "State Information"}, + ) + + +class AddressCity(CrudCollection): + """ + City class based on declarative_base and BaseMixin via session + """ + + __tablename__ = "address_city" + __exclude__fields__ = [] + __language_model__ = AddressCityLanguageModel + + 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" + ) + 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" + ) + + __table_args__ = ( + Index( + "_address_city_ndx_01", + state_id, + city_code, + unique=True, + ), + {"comment": "City Information"}, + ) + + +class AddressDistrict(CrudCollection): + """ + District class based on declarative_base and BaseMixin via session + """ + + __tablename__ = "address_district" + __exclude__fields__ = [] + __language_model__ = AddressDistrictLanguageModel + + 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" + ) + + 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" + ) + + __table_args__ = ( + Index( + "_address_district_ndx_01", + city_id, + district_code, + unique=True, + ), + {"comment": "District Information"}, + ) + + +class AddressLocality(CrudCollection): + """ + Locality class based on declarative_base and BaseMixin via session + """ + + __tablename__ = "address_locality" + __exclude__fields__ = [] + __language_model__ = AddressLocalityLanguageModel + + 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" + ) + address_show: Mapped[bool] = mapped_column(Boolean, server_default="1") + address_geographic_id: Mapped[int] = mapped_column( + BigInteger, nullable=True, comment="Address Geographic Id" + ) + + 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" + ) + + __table_args__ = ( + Index( + "_address_locality_ndx_01", + district_id, + locality_code, + unique=True, + ), + {"comment": "Locality Information"}, + ) + + +class AddressNeighborhood(CrudCollection): + """ + Neighborhood class based on declarative_base and BaseMixin via session + """ + + __tablename__ = "address_neighborhood" + __exclude__fields__ = [] + __language_model__ = AddressNeighborhoodLanguageModel + + neighborhood_code: Mapped[str] = mapped_column( + String(16), nullable=False, comment="Neighborhood Code" + ) + neighborhood_name: Mapped[str] = mapped_column( + 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" + ) + address_show: Mapped[bool] = mapped_column(Boolean, server_default="1") + address_geographic_id: Mapped[int] = mapped_column( + BigInteger, nullable=True, comment="Address Geographic Id" + ) + + 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" + ) + 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" + ) + + __table_args__ = ( + Index( + "_address_neighborhood_ndx_01", + locality_id, + neighborhood_code, + unique=True, + ), + {"comment": "Neighborhood Information"}, + ) + + +class AddressStreet(CrudCollection): + """ + Street class based on declarative_base and BaseMixin via session + """ + + __tablename__ = "address_street" + __exclude__fields__ = [] + __language_model__ = AddressStreetLanguageModel + + 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" + ) + + address_geographic_id: Mapped[int] = mapped_column( + BigInteger, nullable=True, comment="Address Geographic Id" + ) + neighborhood_id: Mapped[int] = mapped_column( + ForeignKey("address_neighborhood.id"), nullable=False, comment="Neighborhood ID" + ) + neighborhood_uu_id: Mapped[str] = mapped_column( + String, server_default="", comment="Neighborhood UUID" + ) + + __table_args__ = ( + Index("_address_street_ndx_01", neighborhood_id, street_code, unique=True), + {"comment": "Street Information"}, + ) + + @classmethod + def search_address_text(cls, search_text, token_dict=None): + field_dict = { + "AddressStreet.uu_id": cls.uu_id, + "AddressCountry.uu_id": AddressCountry.uu_id, + "AddressState.uu_id": AddressState.uu_id, + "AddressCity.uu_id": AddressCity.uu_id, + "AddressDistrict.uu_id": AddressDistrict.uu_id, + "AddressLocality.uu_id": AddressLocality.uu_id, + "AddressNeighborhood.uu_id": AddressNeighborhood.uu_id, + "AddressCountry.country_name": AddressCountry.country_name, + "AddressState.state_name": AddressState.state_name, + "AddressCity.city_name": AddressCity.city_name, + "AddressDistrict.district_name": AddressDistrict.district_name, + "AddressLocality.locality_name": AddressLocality.locality_name, + "AddressNeighborhood.neighborhood_name": AddressNeighborhood.neighborhood_name, + "AddressStreet.street_name": cls.street_name, + } + joined_data = ( + cls.session.query(*list(field_dict.values())) + .select_from(cls) + .join(AddressNeighborhood, AddressNeighborhood.id == cls.neighborhood_id) + .join( + AddressLocality, AddressLocality.id == AddressNeighborhood.locality_id + ) + .join(AddressDistrict, AddressDistrict.id == AddressLocality.district_id) + .join(AddressCity, AddressCity.id == AddressDistrict.city_id) + .join(AddressState, AddressState.id == AddressCity.state_id) + .join(AddressCountry, AddressCountry.id == AddressState.country_id) + .filter( + or_( + AddressNeighborhood.neighborhood_name.ilike( + f"%{str(search_text).upper()}%" + ), + AddressLocality.locality_name.ilike( + f"%{str(search_text).upper()}%" + ), + AddressDistrict.district_name.ilike( + f"%{str(search_text).upper()}%" + ), + # AddressCity.city_name.ilike(f"%{str(search_text).upper()}%"), + # AddressState.state_name.ilike(f"%{str(search_text).upper()}%"), + # AddressCountry.country_name.ilike(f"%{str(search_text).upper()}%"), + cls.street_name.ilike(f"%{str(search_text).upper()}%"), + ), + ) + ) + # select([mytable.c.id]).where( + # func.to_tsvector('english', mytable.c.title) \ + # .match('somestring', postgresql_regconfig='english') + # ) + joined_statement = joined_data + joined_data = joined_data.first() + if not joined_data: + raise HTTPException( + status_code=404, + detail="No address found with the given search text.", + ) + return dict( + query=joined_statement, + schema=list(field_dict.keys()), + ) + + +class OccupantTypes(CrudCollection): + """ + Occupant Types class based on declarative_base and BaseMixin via session + """ + + __tablename__ = "occupant_types" + __exclude__fields__ = [] + __language_model__ = OccupantTypesLanguageModel + + 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="") + occupant_category_type: Mapped[str] = mapped_column(String, server_default="") + occupant_is_unique: Mapped[bool] = mapped_column(Boolean, server_default="0") + + __table_args__ = ({"comment": "Occupant Types Information"},) + + @classmethod + def get_manager_occupant_type(cls): + if occupant_types := cls.filter_all( + cls.occupant_is_unique == True, cls.occupant_category_type == "MT" + ).data: + return [occupant.uu_id.__str__() for occupant in occupant_types] + raise HTTPException( + status_code=404, + detail="No manager type found.", + ) + + +class Contracts(CrudCollection): + """ + Contract class based on declarative_base and BaseMixin via session + """ + + __tablename__ = "contracts" + __exclude__fields__ = [] + __language_model__ = ContractsLanguageModel + + contract_type: Mapped[str] = mapped_column( + String(5), + nullable=False, + comment="The code for personnel is P and the code for companies is C.", + ) + contract_title: Mapped[str] = mapped_column(String(255)) + contract_details: Mapped[str] = mapped_column(Text) + contract_terms: Mapped[str] = mapped_column(Text) + + contract_code: Mapped[str] = mapped_column( + String(100), + nullable=False, + comment="contract_code is the unique code given by the system.", + ) + contract_date: Mapped[TIMESTAMP] = mapped_column( + TIMESTAMP(timezone=True), + server_default="2099-12-31 23:59:59", + comment="contract date is the date the contract is made. " + "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" + ) + + 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): + # from api_library.date_time_actions.date_functions import system_arrow + + # todo When create record contract_code == below string + related_date, counter = Contracts.client_arrow.now(), 1 + return ( + f"{related_date.date().year}{str(cls.contract_type)}{str(counter).zfill(6)}" + ) + + __table_args__ = ( + Index("_contract_ndx_01", contract_code, unique=True), + {"comment": "Contract Information"}, + ) diff --git a/Schemas/others/enums.py b/Schemas/others/enums.py new file mode 100644 index 0000000..472e750 --- /dev/null +++ b/Schemas/others/enums.py @@ -0,0 +1,106 @@ +from fastapi.exceptions import HTTPException + +from sqlalchemy import ( + UUID, + String, + text, +) +from sqlalchemy.orm import ( + Mapped, + mapped_column, +) +from databases.sql_models.core_mixin import CrudCollection + + +class ApiEnumDropdown(CrudCollection): + __tablename__ = "api_enum_dropdown" + __exclude__fields__ = ["enum_class"] + __language_model__ = None + + id: Mapped[int] = mapped_column(primary_key=True) + uu_id: Mapped[str] = mapped_column( + UUID, server_default=text("gen_random_uuid()"), index=True, unique=True + ) + enum_class: Mapped[str] = mapped_column( + String, nullable=False, comment="Enum Constant Name" + ) + key: Mapped[str] = mapped_column(String, nullable=False, comment="Enum Key") + value: Mapped[str] = mapped_column(String, nullable=False, comment="Enum Value") + description: Mapped[str] = mapped_column(String, nullable=True) + + __table_args__ = ({"comment": "Enum objets that are linked to tables"},) + + @classmethod + def get_by_uuid(cls, uuid: str): + return cls.filter_by_one(system=True, uu_id=str(uuid)).data + + @classmethod + 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, + ).data: + return search + elif search_debit: + if search := cls.filter_one( + 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 + + @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, + ).data: + return [due.uu_id.__str__() for due in due_list] + raise HTTPException( + status_code=404, + detail="No dues types found", + ) + + @classmethod + 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, + ).data: + return search + elif search_management: + if search := cls.filter_one( + 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 + + def get_enum_dict(self): + return { + "uu_id": str(self.uu_id), + "enum_class": self.enum_class, + "key": self.key, + "value": self.value, + "description": self.description, + } + + @classmethod + 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, + "uu_id", + None, + ) + ) + + +ApiEnumDropdown.set_session(ApiEnumDropdown.__session__) diff --git a/Schemas/rules/rules.py b/Schemas/rules/rules.py new file mode 100644 index 0000000..f8e91e2 --- /dev/null +++ b/Schemas/rules/rules.py @@ -0,0 +1,31 @@ +from sqlalchemy import String +from sqlalchemy.orm import mapped_column, Mapped + +from databases.language_models.rules.rules import EndpointRestrictionLanguageModel +from databases.sql_models.core_mixin import CrudCollection + + +class EndpointRestriction(CrudCollection): + """ + Initialize Endpoint Restriction with default values + """ + + __tablename__ = "endpoint_restriction" + __exclude__fields__ = [] + __language_model__ = EndpointRestrictionLanguageModel + + endpoint_function: Mapped[str] = mapped_column( + String, server_default="", comment="Function name of the API endpoint" + ) + endpoint_name: Mapped[str] = mapped_column( + String, server_default="", comment="Name of the API endpoint" + ) + endpoint_method: Mapped[str] = mapped_column( + String, server_default="", comment="HTTP method used by the endpoint" + ) + endpoint_desc: Mapped[str] = mapped_column( + String, server_default="", comment="Description of the endpoint" + ) + endpoint_code: Mapped[str] = mapped_column( + String, server_default="", unique=True, comment="Unique code for the endpoint" + ) diff --git a/Services/PostgresDb/Models/response.py b/Services/PostgresDb/Models/response.py index a1a5fd0..00dbf68 100644 --- a/Services/PostgresDb/Models/response.py +++ b/Services/PostgresDb/Models/response.py @@ -14,13 +14,13 @@ T = TypeVar("T") class PostgresResponse(Generic[T]): """ Wrapper for PostgreSQL/SQLAlchemy query results. - + Attributes: query: SQLAlchemy query object first: Whether to return first result only data: Query results (lazy loaded) count: Total count of results - + Properties: all: All results as list first_item: First result only @@ -63,7 +63,11 @@ class PostgresResponse(Generic[T]): @property def all(self) -> List[T]: """Get all results as list.""" - return self.data if isinstance(self.data, list) else [self.data] if self.data else [] + return ( + self.data + if isinstance(self.data, list) + else [self.data] if self.data else [] + ) @property def first_item(self) -> Optional[T]: diff --git a/Services/PostgresDb/__init__.py b/Services/PostgresDb/__init__.py index 390e444..912af25 100644 --- a/Services/PostgresDb/__init__.py +++ b/Services/PostgresDb/__init__.py @@ -3,4 +3,4 @@ from Services.PostgresDb.Models.mixins import CrudCollection, BaseCollection __all__ = [ "CrudCollection", "BaseCollection", -] \ No newline at end of file +]