save and confirmed added

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

View File

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