Initial 2
This commit is contained in:
@ -1,6 +1,16 @@
|
||||
from datetime import datetime
|
||||
|
||||
from televend_core.databases.base_filter import BaseFilter
|
||||
from televend_core.databases.common.filters.filters import EQ, IN, filterfield
|
||||
from televend_core.databases.common.filters.filters import (
|
||||
EQ,
|
||||
GT,
|
||||
IN,
|
||||
IS_NOT_NULL,
|
||||
LT,
|
||||
filterfield,
|
||||
)
|
||||
from televend_core.databases.televend_repositories.cashbag_conform.model import CashBagConform
|
||||
from televend_core.databases.televend_repositories.machine.model import Machine
|
||||
|
||||
|
||||
class CashBagConformFilter(BaseFilter):
|
||||
@ -9,6 +19,18 @@ class CashBagConformFilter(BaseFilter):
|
||||
alive: bool | None = filterfield(operator=EQ, default=True)
|
||||
ids: list[int] | None = filterfield(field="id", operator=IN)
|
||||
machine_ids: list[int] | None = filterfield(field="machine_id", operator=IN)
|
||||
cashflow_collections_ids: list[int] | None = filterfield(
|
||||
field="cashflow_collections_id", operator=IN
|
||||
company_id: int | None = filterfield(
|
||||
field="owner_id",
|
||||
operator=EQ,
|
||||
joins=[Machine],
|
||||
filter_on_model_cls=Machine,
|
||||
)
|
||||
cashflow_collections_ids: list[int] | None = filterfield(
|
||||
field="cashflow_collection_id", operator=IN
|
||||
)
|
||||
is_assigned_to_collection: bool | None = filterfield(
|
||||
field="cashflow_collection_id", operator=IS_NOT_NULL
|
||||
)
|
||||
is_counted: bool | None = filterfield(field="count_timestamp", operator=IS_NOT_NULL)
|
||||
count_timestamp_gt: datetime | None = filterfield(field="count_timestamp", operator=GT)
|
||||
count_timestamp_lt: datetime | None = filterfield(field="count_timestamp", operator=LT)
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
from sqlalchemy.orm import Query
|
||||
|
||||
from televend_core.databases.base_load_options import LoadOptions
|
||||
from televend_core.databases.common.load_options import joinload
|
||||
from televend_core.databases.televend_repositories.cashbag_conform.model import CashBagConform
|
||||
from televend_core.databases.televend_repositories.custom_user.model import CustomUser
|
||||
|
||||
|
||||
class CashBagConformLoadOptions(LoadOptions):
|
||||
@ -10,3 +13,16 @@ class CashBagConformLoadOptions(LoadOptions):
|
||||
load_machine: bool = joinload(relations=["machine"])
|
||||
load_cashbag: bool = joinload(relations=["cashbag"])
|
||||
load_denominations: bool = joinload(relations=["denominations"])
|
||||
|
||||
load_count_user_auth_user: bool = False
|
||||
|
||||
def _apply_custom_joins(self, query: Query) -> Query:
|
||||
if self.load_count_user_auth_user:
|
||||
query = self._add_joins_to_options(
|
||||
query=query,
|
||||
fields=[
|
||||
CashBagConform.count_user,
|
||||
CustomUser.auth_user,
|
||||
],
|
||||
)
|
||||
return query
|
||||
|
||||
26
example/cashbag_conform/mapper.py
Normal file
26
example/cashbag_conform/mapper.py
Normal file
@ -0,0 +1,26 @@
|
||||
mapper_registry.map_imperatively(
|
||||
class_=CashBagConform,
|
||||
local_table=CASHBAG_CONFORM_TABLE,
|
||||
properties={
|
||||
"cashflow_collection": relationship(
|
||||
CashFlowCollection, lazy=relationship_loading_strategy.value
|
||||
),
|
||||
"cashbag": relationship(CashBag, lazy=relationship_loading_strategy.value),
|
||||
"machine": relationship(Machine, lazy=relationship_loading_strategy.value),
|
||||
"count_user": relationship(
|
||||
CustomUser,
|
||||
lazy=relationship_loading_strategy.value,
|
||||
foreign_keys=CASHBAG_CONFORM_TABLE.columns.count_user_id,
|
||||
),
|
||||
"collect_user": relationship(
|
||||
CustomUser,
|
||||
lazy=relationship_loading_strategy.value,
|
||||
foreign_keys=CASHBAG_CONFORM_TABLE.columns.collect_user_id,
|
||||
),
|
||||
"denominations": relationship(
|
||||
CashBagConformDenomination,
|
||||
back_populates="cashbag_conform",
|
||||
lazy=relationship_loading_strategy.value,
|
||||
),
|
||||
},
|
||||
)
|
||||
Reference in New Issue
Block a user